PageSourceSearch

https://harbor-os.com/assets/VendorEventCheckIn-wgfeFqfi.js

js harbor-os.com collected 2026-09-24 14:46:06 UTC 9,614 bytes, 1 lines download raw bytes

1import{r as i,g as _,i as K,j as e,bi as T,G as p,bC as ee,J as V,bF as te,bf as L,h4 as se,K as ae,hf as ne,bX as ie,h6 as re}from"./vendor-BeA4siBz.js";import{u as de,C as b,d as k,B as h,g as u,a as M,b as Q,I as ce,f as G,q as N}from"./index-C2NQ_9nj.js";import{A as le,a as oe,b as ue,c as me,d as he,e as xe,f as fe,g as H}from"./alert-dialog-BQRMS-US.js";function ge(){var O;const{toast:R}=de(),[B,z]=i.useState(null),[C,D]=i.useState(""),[J,w]=i.useState(!1),[P,q]=i.useState(null),[m,S]=i.useState(null),[s,A]=i.useState(null),F=i.useRef(null),j=i.useRef(null),x=i.useRef(null),v=i.useRef(null),{data:U=[],isLoading:W}=_({queryKey:["/api/vendor/events"]}),g=U.filter(t=>t.eventMode),l=B??((O=g[0])==null?void 0:O.id)??null,o=g.find(t=>t.id===l)??null,{data:I=[],isLoading:Y}=_({queryKey:["/api/vendor/events",l,"attendees"],queryFn:async()=>{const t=await fetch(`/api/vendor/events/${l}/attendees`,{credentials:"include"});if(!t.ok)throw new Error("Failed to load attendees");return t.json()},enabled:l!=null}),f=K({mutationFn:async t=>(await G("POST","/api/vendor/events/check-in",{code:t})).json(),onSuccess:t=>{var n;const a=((n=t==null?void 0:t.attendee)==null?void 0:n.name)||null;t.alreadyCheckedIn?S({ok:!0,message:"Already checked in",name:a}):S({ok:!0,message:"Checked in!",name:a}),N.invalidateQueries({queryKey:["/api/vendor/events"]}),N.invalidateQueries({queryKey:["/api/vendor/events",l,"attendees"]})},onError:t=>{var c;let a="Check-in failed";const n=String((t==null?void 0:t.message)||""),r=n.indexOf("{");if(r>=0)try{a=((c=JSON.parse(n.slice(r)))==null?void 0:c.message)||a}catch{}S({ok:!1,message:a})}}),d=K({mutationFn:async({attendeeId:t,refund:a})=>(await G("POST",`/api/vendor/events/attendees/${t}/cancel`,{refund:a})).json(),onSuccess:t=>{A(null),R({title:t.refunded?"Ticket refunded":"Cancelled",description:t.refunded?`$${Number(t.refundAmount??0).toFixed(2)} was refunded to the buyer and the seat was freed.`:"The spot was freed."}),N.invalidateQueries({queryKey:["/api/vendor/events"]}),N.invalidateQueries({queryKey:["/api/vendor/events",l,"attendees"]})},onError:t=>{var c;let a="Could not cancel";const n=String((t==null?void 0:t.message)||""),r=n.indexOf("{");if(r>=0)try{a=((c=JSON.parse(n.slice(r)))==null?void 0:c.message)||a}catch{}R({title:"Cancel failed",description:a,variant:"destructive"})}}),X=t=>{const a=t.trim();if(!a)return;const n=Date.now();v.current&&v.current.code===a&&n-v.current.at<4e3||(v.current={code:a,at:n},f.mutate(a))},$=()=>{var t;x.current&&cancelAnimationFrame(x.current),x.current=null,(t=j.current)==null||t.getTracks().forEach(a=>a.stop()),j.current=null,w(!1)},Z=async()=>{q(null);try{const t=await navigator.mediaDevices.getUserMedia({video:{facingMode:"environment"},audio:!1});j.current=t,w(!0),requestAnimationFrame(()=>{const a=F.current;if(!a)return;a.srcObject=t,a.setAttribute("playsinline","true"),a.play().catch(()=>{});const n=document.createElement("canvas"),r=n.getContext("2d",{willReadFrequently:!0}),c=()=>{if(j.current){if(a.readyState===a.HAVE_ENOUGH_DATA&&r){n.width=a.videoWidth,n.height=a.videoHeight,r.drawImage(a,0,0,n.width,n.height);const E=r.getImageData(0,0,n.width,n.height),y=re(E.data,E.width,E.height,{inversionAttempts:"dontInvert"});y!=null&&y.data&&X(y.data)}x.current=requestAnimationFrame(c)}};x.current=requestAnimationFrame(c)})}catch{q("Camera unavailable — allow camera access or type the code below."),w(!1)}};return i.useEffect(()=>()=>$(),[]),e.jsxs("div",{className:"max-w-3xl mx-auto px-4 py-6 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{className:"w-6 h-6 text-teal-600"}),e.jsx("h1",{className:"text-2xl font-bold",children:"Event Check-In"})]}),W?e.jsx(b,{children:e.jsx(k,{className:"p-6 flex justify-center",children:e.jsx(p,{className:"w-6 h-6 animate-spin"})})}):g.length===0?e.jsx(b,{children:e.jsx(k,{className:"p-6 text-center text-slate-500",children:`No events with RSVPs or ticketing yet. Set an event listing's Attendance to "Free RSVP" or "Paid tickets" in the listing editor.`})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:g.map(t=>
1e.jsx(h,{size:"sm",variant:t.id===l?"default":"outline",onClick:()=>z(t.id),"data-testid":`button-event-${t.id}`,children:t.name},t.id))}),o&&e.jsxs("div",{className:"flex flex-wrap gap-2 text-sm",children:[e.jsxs(u,{variant:"secondary",children:[e.jsx(ee,{className:"w-3 h-3 mr-1"}),o.attending," attending",o.capacity!=null?` / ${o.capacity}`:""]}),e.jsxs(u,{className:"bg-emerald-600",children:[e.jsx(V,{className:"w-3 h-3 mr-1"}),o.checkedIn," checked in"]}),o.startsAt&&e.jsxs(u,{variant:"outline",children:[e.jsx(te,{className:"w-3 h-3 mr-1"}),new Date(o.startsAt).toLocaleString(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})]})]}),e.jsxs(b,{children:[e.jsx(M,{className:"pb-3",children:e.jsxs(Q,{className:"text-base flex items-center gap-2",children:[e.jsx(L,{className:"w-4 h-4"}),"Scan tickets"]})}),e.jsxs(k,{className:"space-y-3",children:[J?e.jsxs("div",{className:"space-y-2",children:[e.jsx("video",{ref:F,className:"w-full rounded-lg bg-black aspect-video object-cover",muted:!0,"data-testid":"video-qr-scanner"}),e.jsxs(h,{variant:"outline",className:"w-full",onClick:$,"data-testid":"button-stop-camera",children:[e.jsx(se,{className:"w-4 h-4 mr-2"}),"Stop camera"]})]}):e.jsxs(h,{className:"w-full",onClick:Z,"data-testid":"button-start-camera",children:[e.jsx(L,{className:"w-4 h-4 mr-2"}),"Start camera scanner"]}),P&&e.jsx("p",{className:"text-sm text-amber-600",children:P}),e.jsxs("form",{className:"flex gap-2",onSubmit:t=>{t.preventDefault(),X(C),D("")},children:[e.jsx(ce,{placeholder:"Or type a code (e.g. EVT-XXXXX-XXXXX)",value:C,onChange:t=>D(t.target.value),"data-testid":"input-manual-code"}),e.jsx(h,{type:"submit",disabled:f.isPending||!C.trim(),"data-testid":"button-manual-checkin",children:f.isPending?e.jsx(p,{className:"w-4 h-4 animate-spin"}):"Check in"})]}),m&&e.jsxs("div",{className:`rounded-lg p-3 flex items-center gap-2 ${m.ok?"bg-emerald-50 text-emerald-800 border border-emerald-200":"bg-red-50 text-red-700 border border-red-200"}`,"data-testid":"checkin-result",children:[m.ok?e.jsx(V,{className:"w-5 h-5 shrink-0"}):e.jsx(ae,{className:"w-5 h-5 shrink-0"}),e.jsxs("span",{className:"text-sm font-medium",children:[m.message,m.name?` — ${m.name}`:""]})]})]})]}),e.jsxs(b,{children:[e.jsx(M,{className:"pb-3",children:e.jsxs(Q,{className:"text-base flex items-center gap-2",children:[e.jsx(ne,{className:"w-4 h-4"}),"Attendees"]})}),e.jsx(k,{children:Y?e.jsx("div",{className:"flex justify-center py-6",children:e.jsx(p,{className:"w-5 h-5 animate-spin"})}):I.length===0?e.jsx("p",{className:"text-sm text-slate-500 py-4 text-center",children:"No RSVPs or tickets yet."}):e.jsx("div",{className:"divide-y",children:I.map(t=>e.jsxs("div",{className:"py-2 flex items-center gap-3","data-testid":`attendee-row-${t.id}`,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:t.name||t.email||"Guest"}),e.jsxs("p",{className:"text-xs text-slate-500 font-mono",children:[t.ticket_code,t.quantity>1?` · ${t.quantity} people`:""]})]}),e.jsx(u,{variant:t.kind==="rsvp"?"outline":"secondary",children:t.kind==="rsvp"?"RSVP":"Ticket"}),t.refund_status==="refunded"&&e.jsx(u,{variant:"outline",className:"text-amber-700 border-amber-300",children:"Refunded"}),t.status==="checked_in"?e.jsx(u,{className:"bg-emerald-600",children:"In"}):t.status==="cancelled"?e.jsx(u,{variant:"destructive",children:"Cancelled"}):e.jsx(h,{size:"sm",variant:"outline",disabled:f.isPending,onClick:()=>f.mutate(t.ticket_code),"data-testid":`button-checkin-${t.id}`,children:"Check in"}),t.status!=="cancelled"&&e.jsx(h,{size:"icon",variant:"ghost",className:"h-8 w-8 text-red-600 hover:text-red-700",disabled:d.isPending,onClick:()=>A(t),title:"Cancel this spot","data-testid":`button-cancel-${t.id}`,children:e.jsx(ie,{className:"w-4 h-4"})})]},t.id))})})]})]}),e.jsx(le,{open:!!s,onOpenChange:t=>{t||A(null)},children:e.jsxs(oe,{children:[e.jsxs(ue,{children:[e.jsxs(me,{children:["Cancel ",(s==null?void 0:s.kind)==="ticket"?"this ticket":"this RSVP","?"]}),e.jsx(he,{children:(s==null?void 0:s.kind)==="ticket"&&(s!=null&&s.order_id)?e.jsxs(e.Fragment,{children:["This ticket for ",e.jsx("strong",{children:(s==null?void 0:s.name)||(s==null?void 0:s.email)||"Guest"})," was paid for through checkout. You can cancel it and refund the buyer's money in one step, or just cancel the seat and settle the money separately."]}):e.jsxs(e.Fragment,{children:["This will cancel the spot for ",e.jsx("strong",{children:(s==null?void 0:s.name)||(s==null?void 0:s.email)||"Guest"}
1)," and free the capacity. This can't be undone."]})})]}),e.jsxs(xe,{className:"flex-col gap-2 sm:flex-row",children:[e.jsx(fe,{disabled:d.isPending,children:"Keep it"}),e.jsxs(H,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:d.isPending,onClick:t=>{t.preventDefault(),s&&d.mutate({attendeeId:s.id,refund:!1})},"data-testid":"button-confirm-cancel",children:[d.isPending&&e.jsx(p,{className:"mr-2 h-4 w-4 animate-spin"}),"Cancel only"]}),(s==null?void 0:s.kind)==="ticket"&&(s==null?void 0:s.order_id)&&(s==null?void 0:s.refund_status)!=="refunded"&&e.jsxs(H,{disabled:d.isPending,onClick:t=>{t.preventDefault(),s&&d.mutate({attendeeId:s.id,refund:!0})},"data-testid":"button-confirm-cancel-refund",children:[d.isPending&&e.jsx(p,{className:"mr-2 h-4 w-4 animate-spin"}),"Cancel & refund"]})]})]})})]})}export{ge as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.