PageSourceSearch

https://www.xpark.ai/assets/AdminCancellations-CDgduc2I.js

js xpark.ai collected 2026-10-05 14:02:36 UTC 8,987 bytes, 1 lines download raw bytes

1import{r as l,A as L,j as e,B as E,I as G,f as P,L as H,m as X,d as T,g as C}from"./index-FWKSGZPO.js";import{C as F,a as M,c as O,b as z}from"./card-DTQVPU97.js";import{B as U}from"./badge-Cpd-8HxK.js";import{S as j,a as f,b as g,c as N,d as a}from"./select-CNpOZwnZ.js";import{R as Q}from"./refresh-ccw-B3ZBuFOd.js";import{M as Y}from"./message-circle-D33wQSco.js";import"./index-BdQq_4o_.js";const u=r=>new Intl.NumberFormat("pt-BR",{style:"currency",currency:"BRL"}).format(r||0),B={refunded:{label:"Estornado",cls:"bg-green-500/10 text-green-700 border-green-500/30"},no_refund:{label:"Sem reembolso",cls:"bg-muted text-muted-foreground border-border"},failed:{label:"Falhou no MP",cls:"bg-red-500/10 text-red-700 border-red-500/30"}};function J(r){const o=new Date;return r==="7"?new Date(o.getTime()-7*864e5).toISOString():r==="30"?new Date(o.getTime()-30*864e5).toISOString():r==="90"?new Date(o.getTime()-90*864e5).toISOString():r==="month"?new Date(o.getFullYear(),o.getMonth(),1).toISOString():null}function re(){const[r,o]=l.useState([]),[S,w]=l.useState(!0),[b,V]=l.useState("30"),[x,I]=l.useState("all"),[h,q]=l.useState("all"),[p,D]=l.useState("all"),[_,A]=l.useState(""),[R,k]=l.useState(null);async function y(){w(!0);let s=T.from("cancellation_requests").select("*").order("created_at",{ascending:!1}).limit(500);const t=J(b);t&&(s=s.gte("created_at",t)),x!=="all"&&(s=s.eq("airport_code",x)),h!=="all"&&(s=s.eq("initiated_by",h)),p!=="all"&&(s=s.eq("outcome",p));const{data:i,error:n}=await s;if(w(!1),n)return C.error(n.message);o(i??[])}l.useEffect(()=>{y()},[b,x,h,p]);const c=l.useMemo(()=>{const s=_.trim().toLowerCase();return s?r.filter(t=>L(t.booking_id,t.airport_code??"XX").toLowerCase().includes(s)||(t.customer_email_snapshot??"").toLowerCase().includes(s)||(t.customer_name_snapshot??"").toLowerCase().includes(s)||(t.customer_phone_snapshot??"").toLowerCase().includes(s)):r},[r,_]),m=l.useMemo(()=>{const s=c.reduce((n,d)=>n+Number(d.refund_amount||0),0),t=c.reduce((n,d)=>n+Math.max(Number(d.total_paid||0)-Number(d.refund_amount||0),0),0),i=c.reduce((n,d)=>({...n,[d.outcome]:(n[d.outcome]??0)+1}),{});return{totalRefunded:s,totalRetained:t,counts:i,total:c.length}},[c]);async function $(s){k(s);const{data:t,error:i}=await T.functions.invoke("mp-refund-payment",{body:{bookingId:s,reason:"retry-from-admin"}});if(k(null),i||t!=null&&t.error){const n=(t==null?void 0:t.error)??"";C.error(n||"Reprocessamento falhou.");return}C.success("Reprocessado com sucesso."),y()}return e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold",children:"Cancelamentos"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Histórico de solicitações. Cliente cancela na hora respeitando a política 90/40/0. Este painel é para acompanhamento e reprocessamento de falhas."})]}),e.jsxs(E,{variant:"outline",size:"sm",onClick:y,disabled:S,children:[e.jsx(Q,{className:"mr-2 h-4 w-4"})," Atualizar"]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-4",children:[e.jsx(v,{label:"Solicitações no período",value:String(m.total)}),e.jsx(v,{label:"Total estornado",value:u(m.totalRefunded)}),e.jsx(v,{label:"Total retido",value:u(m.totalRetained)}),e.jsx(v,{label:"Estornadas / Sem reembolso / Falhas",value:`${m.counts.refunded??0} · ${m.counts.no_refund??0} · ${m.counts.failed??0}`})]}),e.jsxs(F,{children:[e.jsx(M,{className:"pb-2",children:e.jsxs("div",{className:"grid gap-2 sm:grid-cols-5",children:[e.jsxs(j,{value:b,onValueChange:V,children:[e.jsx(f,{children:e.jsx(g,{placeholder:"Período"})}),e.jsxs(N,{children:[e.jsx(a,{value:"7",children:"Últimos 7 dias"}),e.jsx(a,{value:"30",children:"Últimos 30 dias"}),e.jsx(a,{value:"90",children:"Últimos 90 dias"}),e.jsx(a,{value:"month",children:"Este mês"}),e.jsx(a,{value:"all",children:"Todos"})]})]}),e.jsxs(j,{value:x,onValueChange:I,children:[e.jsx(f,{children:e.jsx(g,{placeholder:"Aeroporto"})}),e.jsxs(N,{children:[e.jsx(a,{value:"all",children:"Todos os aeroportos"}),e.jsx(a,{value:"GRU",children:"GRU"}),e.jsx(a,{value:"VCP",children:"VCP"}),e.jsx(a,{value:"CNF",children:"CNF"}),e.jsx(a,{value:"CGH",children:"CGH"})]})]}),e.jsxs(j,{value:h,onValueChange:q,children:[e.jsx(f,{children:e.jsx(g,{placeholder:"Origem"})}),e.jsxs(N,{children:[e.jsx(a,{value:"all",children:"Qualquer origem"}),e.jsx(a,{value:"customer",children:"Cliente"}),e.jsx(a,{value:"admin",children:"Admin"})]})]}),e.jsxs(j,{value:p,onValueChange:D,children:[e.jsx(f,{children:e.jsx(g,{placeholder:"Resultado"})}),e.jsxs(N,{children:[e.jsx(a,{value:"all",children:"Qualquer resultado"}),e.jsx(a,{value:"refunded",children:"Estornado"}),e.jsx(a,{value:"no_refund",children:"Sem reembolso"}),e.jsx(a,{value:"failed",children:"Falhou"})]})]}),e.jsx(G,{placeholder:"Buscar por código, e-mail ou nome",value:_,onCh
1ange:s=>A(s.target.value)})]})}),e.jsx(O,{className:"p-0",children:S?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(P,{className:"h-5 w-5 animate-spin"})}):c.length===0?e.jsx("div",{className:"py-10 text-center text-sm text-muted-foreground",children:"Nenhuma solicitação no período selecionado."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/40 text-left text-xs uppercase text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2",children:"Solicitada em"}),e.jsx("th",{className:"px-3 py-2",children:"Reserva"}),e.jsx("th",{className:"px-3 py-2",children:"Cliente"}),e.jsx("th",{className:"px-3 py-2",children:"Política"}),e.jsx("th",{className:"px-3 py-2 text-right",children:"Valores"}),e.jsx("th",{className:"px-3 py-2",children:"Resultado"}),e.jsx("th",{className:"px-3 py-2"})]})}),e.jsx("tbody",{children:c.map(s=>{const t=L(s.booking_id,s.airport_code??"XX"),i=(s.customer_phone_snapshot??"").replace(/\D/g,"");return e.jsxs("tr",{className:"border-t align-top",children:[e.jsxs("td",{className:"px-3 py-2 whitespace-nowrap",children:[new Date(s.created_at).toLocaleString("pt-BR"),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:s.initiated_by==="admin"?"Feito por admin":"Pelo cliente"})]}),e.jsxs("td",{className:"px-3 py-2 font-mono text-xs",children:[e.jsx("div",{children:t}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:s.airport_code??"—"}),e.jsxs(H,{to:`/confirmacao?bookingId=${s.booking_id}`,className:"text-[11px] text-primary hover:underline inline-flex items-center gap-1",children:[e.jsx(X,{className:"h-3 w-3"})," Ver reserva"]})]}),e.jsxs("td",{className:"px-3 py-2",children:[e.jsx("div",{className:"font-medium",children:s.customer_name_snapshot??"—"}),s.customer_email_snapshot&&e.jsx("div",{className:"text-xs text-muted-foreground",children:s.customer_email_snapshot}),i&&e.jsxs("a",{href:`https://wa.me/${i}`,target:"_blank",rel:"noreferrer",className:"text-[11px] text-primary hover:underline inline-flex items-center gap-1",children:[e.jsx(Y,{className:"h-3 w-3"})," ",s.customer_phone_snapshot]}),s.reason&&e.jsxs("div",{className:"mt-1 text-[11px] text-muted-foreground italic",children:['"',s.reason,'"']})]}),e.jsxs("td",{className:"px-3 py-2",children:[e.jsxs("div",{className:"font-medium",children:[Number(s.policy_percent),"%"]}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:s.policy_label??"—"}),s.hours_until_start!==null&&e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:[Number(s.hours_until_start).toFixed(1),"h antes"]})]}),e.jsxs("td",{className:"px-3 py-2 text-right whitespace-nowrap",children:[e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Pago: ",u(Number(s.total_paid))]}),Number(s.insurance_retained)>0&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Seguro retido: ",u(Number(s.insurance_retained))]}),e.jsxs("div",{className:"font-semibold",children:["Estornado: ",u(Number(s.refund_amount))]})]}),e.jsxs("td",{className:"px-3 py-2",children:[e.jsx(U,{variant:"outline",className:B[s.outcome].cls,children:B[s.outcome].label}),s.mp_refund_id&&e.jsxs("div",{className:"mt-1 text-[10px] font-mono text-muted-foreground",children:["MP ",s.mp_refund_id]}),s.error_message&&e.jsx("div",{className:"mt-1 text-[10px] text-red-700",children:s.error_message})]}),e.jsx("td",{className:"px-3 py-2",children:s.outcome==="failed"&&e.jsxs(E,{size:"sm",variant:"outline",className:"h-7 px-2 text-xs",disabled:R===s.booking_id,onClick:()=>$(s.booking_id),children:[R===s.booking_id&&e.jsx(P,{className:"mr-1 h-3 w-3 animate-spin"}),"Reprocessar"]})})]},s.id)})})]})})})]})]})}function v({label:r,value:o}){return e.jsxs(F,{children:[e.jsx(M,{className:"pb-1",children:e.jsx(z,{className:"text-xs font-medium text-muted-foreground",children:r})}),e.jsx(O,{className:"pt-0 text-lg font-semibold",children:o})]})}export{re 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.