PageSourceSearch

https://care.soberpedia.ai/assets/OrdersRoute-DwPAjPKE.js

js soberpedia.ai collected 2026-10-05 15:09:09 UTC 13,594 bytes, 1 lines download raw bytes

1import{r as i,j as e}from"./react-vendor-CU6Sz31W.js";import{au as F,ay as B,ax as V,E as O,i as c,aA as U,I as M,aD as H,a0 as E,ez as N,eA as G,eB as P,c7 as J,c8 as X,c9 as K,ca as Q,cb as D,U as W,dX as Y,be as T}from"./index-DEXJEDAi.js";import{A as Z}from"./AccessDenied-Ba4b0-Uz.js";import{u as ee}from"./usePracticeRoute-BanfQY79.js";import{R as te}from"./RoutePageHeader-9W0v4VlT.js";import{a as _}from"./DataTableCard-BluwWKn_.js";import{P as ae}from"./patient-name-link-BAfQKbEs.js";import{u as re}from"./useOpenPatientProfile-CASNKG5E.js";import{P as q}from"./PracticeFormDialog-RdnfXKaS.js";import{P as se}from"./PracticeLabResults-D8MPDUph.js";import"./firebase-w6DYUbFN.js";import"./payment-icons-Daq1K3F1.js";import"./shield-alert-DjOj07_r.js";import"./RoutePageHeaderContent-FkxdZGox.js";import"./index-BSuGcRaZ.js";import"./table-CxPdvV_9.js";import"./arrow-up-D6DFVL4j.js";import"./arrow-down-BjUlbB4f.js";import"./pill-filter-CtZSNPVl.js";import"./date-picker-filter-Qp1kqu9t.js";import"./calendar-RV2oTCrW.js";import"./addWeeks-1hrFjz19.js";import"./clear-filters-button-DmPemFGr.js";import"./ExportCsvAction-BJr9eiP6.js";import"./modal-option-cards-Dksohkou.js";import"./text-highlight-BFqqfcjs.js";import"./use-unsaved-changes-B6nL5Xdd.js";import"./modal-form-CqN5DZuv.js";import"./api-DkVW0jWd.js";async function w(n,l="",{body:m,after:p,signal:h}={}){if(!n||!F.currentUser)throw new Error("Sign in to your Practice to view orders.");const t=new URL(`${B.replace(/\/$/,"")}/practice/orders${l}`);t.searchParams.set("practiceId",n),p&&t.searchParams.set("after",p);const f=await fetch(t,{method:m?"POST":"GET",signal:h,headers:{Authorization:`Bearer ${await F.currentUser.getIdToken()}`,"Content-Type":"application/json"},...m?{body:JSON.stringify(m)}:{}}),x=await f.json();if(!f.ok||!x.success)throw new Error(x.error||"Unable to load orders. Try again.");return x}function ne({practiceId:n,onClose:l,onChanged:m}){const[p,h]=i.useState([]),[t,f]=i.useState(!0),[x,C]=i.useState(""),[j,v]=i.useState(null),[o,g]=i.useState(0);i.useEffect(()=>{const a=new AbortController;return f(!0),C(""),w(n,"/payment-attempts",{signal:a.signal}).then(u=>{a.signal.aborted||h(u.payments)}).catch(u=>{a.signal.aborted||C(u.message)}).finally(()=>{a.signal.aborted||f(!1)}),()=>a.abort()},[n,o]);const S=a=>a.status==="paid"||a.useSavedCard||["nmi","simpay","slidepay","authorize","square"].includes(a.mode),R=[{id:"product",header:"Purchase",renderCell:a=>a.productName},{id:"amount",header:"Amount",renderCell:a=>`$${(a.amount/100).toFixed(2)}`},{id:"processor",header:"Processor",renderCell:a=>a.mode},{id:"status",header:"State",renderCell:a=>a.captureStatus||a.status},{id:"action",header:"Action",renderCell:a=>S(a)?e.jsx(c,{variant:"outline",size:"sm",onClick:()=>v(a),children:a.status==="paid"?"Finish order":"Verify payment"}):e.jsx("span",{className:"text-sm text-muted-foreground",children:"Patient can resume hosted checkout"})}];return e.jsxs(e.Fragment,{children:[e.jsx(V,{open:!0,onOpenChange:a=>{!a&&!j&&l()},title:"Payment recovery",description:"Review the latest 100 checkout attempts. Verification looks up an existing processor payment and never charges a card.",size:"lg",mobileStickyFooter:!0,footer:e.jsxs(e.Fragment,{children:[e.jsx(c,{variant:"outline",onClick:l,children:"Close"}),e.jsx(c,{variant:"outline",onClick:()=>g(a=>a+1),children:"Refresh"})]}),children:x?e.jsx(O,{reason:"error",title:"Unable to load payment attempts",description:x}):e.jsx(_,{columns:R,rows:p,loading:t,tableLabel:"Payment attempts",emptyMessage:"No unfinished payments."})}),j&&e.jsx(q,{title:j.status==="paid"?"Finish received payment":"Verify existing payment",description:"The processor must confirm the exact booking reference, merchant, currency, amount, and captured status before this order can finish.",initial:{paymentId:""},saveLabel:"Verify and finish order",onClose:()=>v(null),onSave:async a=>{await w(n,`/payment-attempts/${encodeURIComponent(j.id)}/reconcile`,{body:j.status==="paid"?{}:a}),g(u=>u+1),m()},children:(a,u)=>j.status==="paid"?e.jsx("p",{className:"text-sm",children:"Payment is already verified. This retries the order records without contacting the processor."}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(U,{htmlFor:"practice-reconcile-payment",children:"Processor transaction ID"}),e.jsx(M,{id:"practice-reconcile-payment",required:!0,value:a.paymentId,onChange:s=>u("paymentId",s.target.value)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Find this reference in your merchant dashboard. An unrelated payment cannot be linked."})]})})]})}const k=n=>String(n||"pending").replaceAll("_"," ").replace(/^./,l=>l.toUpperCase()),I=n=>
1new Intl.NumberFormat("en-US",{style:"currency",currency:n.currency||"USD"}).format((n.amount||0)/100);function oe({practiceId:n,orderId:l,patient:m,onClose:p,onChanged:h}){var R,a,u;const[t,f]=i.useState(null),[x,C]=i.useState(""),[j,v]=i.useState(0),[o,g]=i.useState(null);i.useEffect(()=>{const s=new AbortController;return f(null),C(""),w(n,`/${encodeURIComponent(l)}`,{signal:s.signal}).then(d=>{s.signal.aborted||f(d.order)}).catch(d=>{s.signal.aborted||C(d.message)}),()=>s.abort()},[n,l,j]);const S=(t==null?void 0:t.canManage)&&!["on_hold","completed","cancelled","canceled","refunded","voided","shipped","delivered","pending_lab_review","pending_result_review"].includes(t.status);return e.jsxs(e.Fragment,{children:[e.jsx(V,{open:!0,onOpenChange:s=>{!s&&!o&&p()},title:"Order details",description:"Review the order, payment, and processing status.",size:"lg",mobileStickyFooter:!0,footer:e.jsxs(e.Fragment,{children:[e.jsx(c,{variant:"outline",onClick:p,children:"Close"}),(t==null?void 0:t.canRefreshRefund)&&e.jsx(c,{variant:"outline",onClick:async()=>{try{const s=await w(n,`/${encodeURIComponent(l)}/refund-status`,{body:{}});f(s.order),h()}catch(s){C(s.message)}},children:"Check refund"}),(t==null?void 0:t.canRefund)&&e.jsx(c,{variant:"outline",onClick:()=>g("refund"),children:"Refund payment"}),(t==null?void 0:t.canManage)&&e.jsx(c,{variant:"outline",onClick:()=>g("label"),children:"Set label"}),S&&e.jsx(c,{onClick:()=>g("hold"),children:"Place on hold"}),(t==null?void 0:t.canManage)&&t.status==="on_hold"&&e.jsx(c,{onClick:()=>g("release"),children:"Release hold"})]}),children:x?e.jsx(O,{reason:"error",title:"Unable to load order",description:x,action:e.jsx(c,{onClick:()=>v(s=>s+1),children:"Try again"})}):t?e.jsxs(e.Fragment,{children:[e.jsx(N,{title:"Summary",children:e.jsxs(G,{children:[!m&&e.jsx(P,{label:"Patient",children:t.patientName}),e.jsx(P,{label:"Status",children:m&&t.status==="on_hold"?"Processing":k(t.status)}),t.operationalLabel&&e.jsx(P,{label:"Team label",children:t.operationalLabel.name}),e.jsx(P,{label:"Payment",children:k(t.paymentStatus)}),t.refundStatus&&e.jsx(P,{label:"Refund",children:k(t.refundStatus)}),e.jsx(P,{label:"Total",numeric:!0,children:I(t)}),e.jsx(P,{label:"Created",children:t.createdAt?new Date(t.createdAt).toLocaleDateString():"Not recorded"})]})}),e.jsx(N,{title:"Items",children:t.items.length?e.jsx("ul",{className:"space-y-2",children:t.items.map((s,d)=>e.jsxs("li",{className:"flex justify-between gap-4 text-sm",children:[e.jsxs("span",{children:[s.name," × ",s.quantity]}),e.jsx("span",{className:"shrink-0 tabular-nums",children:I({...s,currency:t.currency})})]},`${s.productId}-${d}`))}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No item details were recorded for this order."})}),(t.careOrderId||t.labOrderId||((R=t.labOrderIds)==null?void 0:R.length)>0||t.canPayTreatment)&&e.jsx(N,{title:"Care steps",children:e.jsxs("div",{className:"flex flex-wrap gap-4",children:[t.careOrderId&&e.jsx("a",{className:"text-sm underline",href:`/orders?order=${encodeURIComponent(t.careOrderId)}`,children:"View treatment review"}),t.labOrderId&&e.jsx("a",{className:"text-sm underline",href:`/orders?order=${encodeURIComponent(t.labOrderId)}`,children:"View lab order"}),(a=t.labOrderIds)==null?void 0:a.map((s,d)=>e.jsxs("a",{className:"text-sm underline",href:`/orders?order=${encodeURIComponent(s)}`,children:["View included lab ",d+1]},s)),t.canPayTreatment&&e.jsx("a",{className:"text-sm underline",href:`/products?checkout=${encodeURIComponent(t.productId)}&careOrder=${encodeURIComponent(t.id)}`,children:"Pay for approved treatment"})]})}),t.type==="lab"&&t.externalLabOrderId&&e.jsx(N,{title:"Lab results",children:e.jsx(se,{practiceId:n,orderId:l})}),t.holdReason&&e.jsx(N,{title:"Hold reason",children:e.jsx("p",{className:"whitespace-pre-wrap break-words text-sm",children:t.holdReason})})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsx(E,{className:"h-16 w-full"}),e.jsx(E,{className:"h-24 w-full"})]})}),o&&e.jsx(q,{title:o==="refund"?"Refund payment":o==="label"?"Set order label":o==="hold"?"Place order on hold":"Release order hold",de
1scription:o==="refund"?`Refund the full ${I(t)} to the original payment method. This stops clinical processing but does not cancel a calendar appointment or subscription.`:o==="label"?"Labels organize your team’s work without changing payment or clinical status.":o==="hold"?"Pause this order and its linked orders. Payments are not refunded.":"Resume the previous processing stage. Payment and clinical requirements still apply.",initial:{reason:"",labelId:((u=t.operationalLabel)==null?void 0:u.id)||"none"},saveLabel:o==="refund"?"Refund payment":o==="label"?"Save label":o==="hold"?"Place on hold":"Release hold",onClose:()=>g(null),onSave:async s=>{const d=await w(n,`/${encodeURIComponent(l)}/${o==="refund"?"refund":"actions"}`,{body:{...o!=="refund"?{action:o}:{},expectedRevision:t.revision,...o==="label"?{labelId:s.labelId==="none"?null:s.labelId}:["hold","refund"].includes(o)?{reason:s.reason}:{}}});f(d.order),h()},children:(s,d)=>o==="label"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(U,{htmlFor:"practice-order-label",optional:!0,children:"Team label"}),e.jsxs(J,{value:s.labelId,onValueChange:y=>d("labelId",y),children:[e.jsx(X,{id:"practice-order-label",children:e.jsx(K,{})}),e.jsxs(Q,{children:[e.jsx(D,{value:"none",children:"No label"}),t.availableLabels.map(y=>e.jsx(D,{value:y.id,children:y.name},y.id))]})]})]}):["hold","refund"].includes(o)?e.jsxs("div",{className:"space-y-2",children:[e.jsx(U,{htmlFor:"practice-order-hold-reason",optional:o!=="refund",children:"Reason"}),e.jsx(W,{id:"practice-order-hold-reason",required:o==="refund",value:s.reason,maxLength:1e3,onChange:y=>d("reason",y.target.value)})]}):e.jsx("p",{className:"text-sm",children:"Linked orders paused with this order will also resume. Orders placed on hold separately stay paused."})})]})}function le({practiceId:n,patient:l=!1,admin:m=!1}){const[p,h]=i.useState(!1),[t,f]=H(),x=t.get("order"),{openPatientProfile:C,buildPatientProfileHref:j}=re(),[v,o]=i.useState({orders:[],nextCursor:null}),[g,S]=i.useState([""]),[R,a]=i.useState(0),[u,s]=i.useState(!0),[d,y]=i.useState(""),$=g.at(-1);i.useEffect(()=>{const r=new AbortController;return s(!0),y(""),w(n,"",{after:$,signal:r.signal}).then(b=>{r.signal.aborted||o(b)}).catch(b=>{r.signal.aborted||y(b.message)}).finally(()=>{r.signal.aborted||s(!1)}),()=>r.abort()},[n,$,R]);const A=r=>f(b=>{const L=new URLSearchParams(b);return r?L.set("order",r):L.delete("order"),L}),z=[...l?[]:[{id:"patient",header:"Patient",renderCell:r=>e.jsx(ae,{patientId:r.patientId,name:r.patientName,href:j(r.patientId),onOpen:C})}],{id:"items",header:"Order",renderCell:r=>r.items.map(b=>b.name).join(", ")||k(r.type)},{id:"status",header:"Status",renderCell:r=>{var b;return l&&r.status==="on_hold"?"Processing":[k(r.status),(b=r.operationalLabel)==null?void 0:b.name].filter(Boolean).join(" · ")}},{id:"payment",header:"Payment",renderCell:r=>k(r.paymentStatus)},{id:"amount",header:"Total",renderCell:I},{id:"actions",header:"Actions",renderCell:r=>e.jsx(c,{variant:"outline",size:"sm",onClick:()=>A(r.id),children:"View order"})}];return e.jsxs("div",{className:"app-page-shell space-y-6",children:[e.jsx(te,{title:"Orders",description:"Track purchases, payment, and care progress."}),e.jsxs("div",{className:"flex justify-end gap-3",children:[m&&e.jsx(c,{variant:"outline",onClick:()=>h(!0),children:"Recover payment"}),e.jsx(c,{variant:"outline",disabled:u,onClick:()=>a(r=>r+1),children:"Refresh orders"})]}),d?e.jsx(O,{reason:"error",title:"Unable to load orders",description:d,action:e.jsx(c,{onClick:()=>a(r=>r+1),children:"Try again"})}):e.jsx(_,{columns:z,rows:v.orders,loading:u,tableLabel:"Practice orders",emptyMessage:e.jsx(O,{reason:"empty",title:"No orders yet",description:"Purchases and requested care will appear here."})}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(c,{variant:"outline",disabled:u||g.length<2,onClick:()=>S(r=>r.slice(0,-1)),children:"Previous page"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Page ",g.length]}),e.jsx(c,{variant:"outline",disabled:u||!!d||!v.nextCursor,onClick:()=>S(r=>[...r,v.nextCursor]),children:"Next page"})]}),p&&e.jsx(ne,{practiceId:n,onClose:()=>h(!1),onChanged:()=>a(r=>r+1)}),x&&e.jsx(oe,{practiceId:n,orderId:x,patient:l,onClose:()=>A(null),onChanged:()=>a(r=>r+1)},x)]})}function Ee(){const{loading:n,role:l,practiceId:m,userType:p,userDoc:h}=ee();return n?e.jsx(Y,{title:"Orders",description:"Track purchases, payment, and care progress.",message:"Loading orders…"}):!m||!l&&!T(p,"Patient")?e.jsx(Z,{subject:"orders"}):e.jsx(le,{practiceId:m,patient:T(p,"Patient"),admin:T(p,"Practice Admin")},`${m}-${h==null?void 0:h.id}-${p}`)}export{Ee 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.