PageSourceSearch

https://www.viewings.ai/assets/HomeReportAdmin-DSz8gbIA.js

js viewings.ai collected 2026-10-05 15:10:54 UTC 13,675 bytes, 1 lines download raw bytes

1import{a5 as de,r as d,l as V,j as e,d as m,g as x,W as ce,R as oe,v as k,w as D,x as P,y as M,z as l,B as n,ag as me,ah as xe,b as v,ai as he,aj as ue,ak as c,L as K,ae as pe,ad as je,D as U,p as Q,q as $,t as z,al as ge,a6 as ye,an as W,K as X,s as j,h,C as Ne,H as ve}from"./index-C9f1sBdt.js";import{u as fe}from"./useMutation-86Rdoy3K.js";import{A as Ce}from"./AppLayout-B9ktyuxE.js";import{T as we,a as _e,b as f,c as o,d as be,e as i}from"./table-BD-VuCIZ.js";import{M as Se}from"./mail-CdvjVzMY.js";import{P as ke}from"./phone-BPiJeKdR.js";import{C as De}from"./circle-x-DvDOQkFE.js";import{C as Pe}from"./circle-alert-CTrZhs3O.js";import{C as Me}from"./clock-DTXlmEsB.js";import{F as Te}from"./file-text-Dp-dKqbl.js";import{f as T}from"./format-DwvaiAgB.js";import"./globe-CEKYjKWl.js";import"./receipt-BHarpD0Q.js";import"./message-circle-9TywF5f6.js";import"./plus-qClqWP7l.js";import"./useTrialStatus-Bq2bIA6_.js";function We(){const J=de(),[g,Y]=d.useState(""),[C,Z]=d.useState("all"),[w,q]=d.useState("all"),[t,A]=d.useState(null),[ee,y]=d.useState(!1),[se,_]=d.useState(!1),[u,L]=d.use
1State(""),[I,F]=d.useState(null),[H,R]=d.useState(null),{data:p=[],isLoading:ae}=V({queryKey:["home-report-requests"],queryFn:async()=>{const{data:s,error:a}=await j.from("home_report_requests").select("*").order("created_at",{ascending:!1});if(a)throw a;return s}}),{data:E=[]}=V({queryKey:["surveyors"],queryFn:async()=>{const{data:s,error:a}=await j.from("contractors").select("*").eq("is_active",!0).order("name");if(a)throw a;return s}}),b=fe({mutationFn:async({id:s,updates:a})=>{const{error:r}=await j.from("home_report_requests").update(a).eq("id",s);if(r)throw r},onSuccess:()=>{J.invalidateQueries({queryKey:["home-report-requests"]}),h.success("Request updated successfully")},onError:s=>{h.error(s.message||"Failed to update request")}}),te=()=>{if(!t||!u)return;const s=E.find(a=>a.id===u);b.mutate({id:t.id,updates:{assigned_surveyor_id:u,assigned_surveyor_name:(s==null?void 0:s.name)||null,status:"assigned"}}),y(!1),L("")},S=(s,a)=>{const r={status:a};a==="completed"&&(r.completed_at=new Date().toISOString()),b.mutate({id:s,updates:r})},re=s=>{b.mutate({id:s,updates:{paid_at:new Date().toISOString()}})},ne=async s=>{F(s.id);try{const{data:a,error:r}=await j.functions.invoke("create-home-report-payment",{body:{requestId:s.id,reportType:s.report_type,customerEmail:s.customer_email,customerName:s.customer_name}});if(r)throw r;a!=null&&a.url&&(await navigator.clipboard.writeText(a.url),h.success("Payment link copied to clipboard!"),window.open(a.url,"_blank"))}catch(a){console.error("Error generating payment link:",a),h.error(a.message||"Failed to generate payment link")}finally{F(null)}},le=async s=>{R(s.id);try{const{data:a,error:r}=await j.functions.invoke("send-home-report-payment-link",{body:{requestId:s.id,reportType:s.report_type,customerEmail:s.customer_email,customerName:s.customer_name,propertyAddress:s.property_address}});if(r)throw r;h.success(`Payment link sent to ${s.customer_email}`)}catch(a){console.error("Error sending payment link:",a),h.error(a.message||"Failed to send payment link")}finally{R(null)}},O=s=>{switch(s){case"pending":return e.jsxs(n,{variant:"outline",className:"bg-yellow-50 text-yellow-700 border-yellow-200",children:[e.jsx(Me,{className:"h-3 w-3 mr-1"})," Pending"]});case"assigned":return e.jsxs(n,{variant:"outline",className:"bg-blue-50 text-blue-700 border-blue-200",children:[e.jsx(X,{className:"h-3 w-3 mr-1"})," Assigned"]});case"in_progress":return e.jsxs(n,{variant:"outline",className:"bg-purple-50 text-purple-700 border-purple-200",children:[e.jsx(Pe,{className:"h-3 w-3 mr-1"})," In Progress"]});case"completed":return e.jsxs(n,{variant:"outline",className:"bg-green-50 text-green-700 border-green-200",children:[e.jsx(Ne,{className:"h-3 w-3 mr-1"})," Completed"]});case"cancelled":return e.jsxs(n,{variant:"outline",className:"bg-red-50 text-red-700 border-red-200",children:[e.jsx(De,{className:"h-3 w-3 mr-1"})," Cancelled"]});default:return e.jsx(n,{variant:"outline",children:s})}},B=s=>s==="home_inspection"?e.jsxs(n,{variant:"secondary",className:"gap-1",children:[e.jsx(ve,{className:"h-3 w-3"})," Home Inspection"]}):e.jsxs(n,{variant:"secondary",className:"gap-1",children:[e.jsx(Te,{className:"h-3 w-3"})," Accommodation Letter"]}),G=p.filter(s=>{const a=s.customer_name.toLowerCase().includes(g.toLowerCase())||s.property_address.toLowerCase().includes(g.toLowerCase())||s.customer_email.toLowerCase().includes(g.toLowerCase()),r=C==="all"||s.status===C,ie=w==="all"||s.report_type===w;return a&&r&&ie}),N={total:p.length,pending:p.filter(s=>s.status==="pending").length,assigned:p.filter(s=>s.status==="assigned"||s.status==="in_progress").length,completed:p.filter(s=>s.status==="completed").length};return e.jsxs(Ce,{children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Home Report Requests"}),e.jsx("p",{className:"text-muted-foreground",children:"Manage property inspection and accommodation letter requests"})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsx(m,{children:e.jsxs(x,{className:"pt-4",children:[e.jsx("div",{className:"text-2xl font-bold",children:N.total}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Total Requests"})]})}),e.jsx(m,{children:e.jsxs(x,{className:"pt-4",children:[e.jsx("div",{className:"text-2xl font-bold text-yellow-600",children:N.pending}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Pending"})]})}),e.jsx(m,{children:e.jsxs(x,{className:"pt-4",children:[e.jsx("div",{className:"text-2xl font-bold text-blue-600",children:N.assigned}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"In Progress"})]})}),e.jsx(m,{children:e.jsxs(x,{className:"pt-4",children:[e.jsx("div",{className:"text-2xl font-bold text-green-600",children:N.completed}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Completed"})]})})]}),e.jsx(m,{children:e.jsx(x,{className:"pt-4",children:e.jsxs("div",{className:"flex flex-col md:flex-row gap-4",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ce,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(oe,{placeholder:"Search by name, email, or address...",value:g,onChange:s=>Y(s.target.value),className:"pl-9"})]}),e.jsxs(k,{value:C,onValueChange:Z,children:[e.jsx(D,{className:"w-full md:w-40",children:e.jsx(P,{placeholder:"Status"})}),e.jsxs(M,{children:[e.jsx(l,{value:"all",children:"All Status"}),e.jsx(l,{value:"pending",children:"Pending"}),e.jsx(l,{value:"assigned",children:"Assigned"}),e.jsx(l,{value:"in_progress",children:"In Progress"}),e.jsx(l,{value:"completed",children:"Completed"}),e.jsx(l,{value:"cancelled",children:"Cancelled"})]})]}),e.jsxs(k,{value:w,onValueChange:q,children:[e.jsx(D,{className:"w-full md:w-48",children:e.jsx(P,{placeholder:"Type"})}),e.jsxs(M,{children:[e.jsx(l,{value:"all",children:"All Types"}),e.jsx(l,{value:"home_inspection",children:"Home Inspection"}),e.jsx(l,{value:"accommodation_letter",children:"Accommodation Letter"})]})]})]})})}),e.jsx(m,{children:e.jsx(x,{className:"pt-4",children:e.jsxs(we,{children:[e.jsx(_e,{children:e.jsxs(f,{children:[e.jsx(o,{children:"Customer"}),e.jsx(o,{children:"Type"}),e.jsx(o,{children:"Property"}),e.jsx(o,{children:"Status"}),e.jsx(o,{children:"Assigned To"}),e.jsx(o,{children:"Price"}),e.jsx(o,{children:"Date"}),e.jsx(o,{className:"text-right",children:"Actions"})]})}),e.jsx(be,{children:ae?e.jsx(f,{children:e.jsx(i,{colSpan:8,className:"text-center py-8 text-muted-foreground",children:"Loading requests..."})}):G.length===0?e.jsx(f,{children:e.jsx(i,{colSpan:8,className:"text-center py-8 text-muted-foreground",children:"No requests found"})}):G.map(s=>e.jsxs(f,{children:[e.jsx(i,{children:e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:s.customer_name}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s.customer_email})]})}),e.jsx(i,{children:B(s.report_type)}),e.jsxs(i,{children:[e.jsx("div",{className:"max-w-[200px] truncate",title:s.property_address,children:s.property_address}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s.postcode})]}),e.jsx(i,{children:O(s.status)}),e.jsx(i,{children:s.assigned_surveyor_name||e.jsx("span",{className:"text-muted-foreground",children:"Unassigned"})}),e.jsxs(i,{children:[e.jsxs("div",{className:"font-medium",children:["£",s.price]}),s.paid_at?e.jsx(n,{variant:"outline",className:"text-xs bg-green-50 text-green-700",children:"Paid"}):e.jsx(n,{variant:"outline",className:"text-xs bg-red-50 text-red-700",children:"Unpaid"})]}),e.jsx(i,{className:"text-sm text-muted-foreground",children:T(new Date(s.created_at),"dd MMM yyyy")}),e.jsx(i,{className:"text-right",children:e.jsxs(me,{children:[e.jsx(xe,{asChild:!0,children:e.jsx(v,{variant:"ghost",size:"sm",children:e.jsx(he,{className:"h-4 w-4"})})}),e.jsxs(ue,{align:"end",children:[e.jsx(c,{onClick:()=>{A(s),_(!0)},children:"View Details"}),e.jsx(c,{onClick:()=>{A(s),y(!0)},children:"Assign Surveyor"}),!s.paid_at&&e.jsxs(e.Fragment,{children:[e.jsx(c,{onClick:()=>ne(s),disabled:I===s.id,children:I===s.id?e.jsxs(e.Fragment,{children:[e.jsx(K,{className:"h-4 w-4 mr-2 animate-spin"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(pe,{className:"h-4 w-4 mr-2"}),"Generate Payment Link"]})}),e.jsx(c,{onClick:()=>le(s),disabled:H===s.id,children:H===s.id?e.jsxs(e.Fragment,{children:[e.jsx(K,{className:"h-4 w-4 mr-2 animate-spin"}),"Sending..."]}):e.jsxs(e.Fragment,{children:[e.jsx(je,{className:"h-4 w-4 mr-2"}),"Send Payment Link"]})}),e.jsx(c,{onClick:()=>re(s.id),children:"Mark as Paid"})]}),e.jsx(c,{onClick:()=>S(s.id,"in_progress"),children:"Mark In Progress"}),e.jsx(c,{onClick:()=>S(s.id,"completed"),children:"Mark Complete"}),e.jsx(c,{onClick:()=>S(s.id,"cancelled"),className:"text-destructive",children:"Cancel Request"})]})]})})]},s.id))})]})})})]}),e.jsx(U,{open:ee,onOpenChange:y,children:e.jsxs(Q,{children:[e.jsxs($,{children:[e.jsx(z,{children:"Assign Surveyor"}),e.jsx(ge,{children:"Select a surveyor to assign to this request."})]}),e.jsx("div",{className:"space-y-4 py-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(ye,{children:"Select Surveyor"}),e.jsxs(k,{value:u,onValueChange:L,children:[e.jsx(D,{children:e.jsx(P,{placeholder:"Choose a surveyor..."})}),e.jsx(M,{children:E.map(s=>e.jsx(l,{value:s.id,children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:s.name}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s.specialty})]})},s.id))})]})]})}),e.jsxs(W,{children:[e.jsx(v,{variant:"outline",onClick:()=>y(!1),children:"Cancel"}),e.jsx(v,{onClick:te,disabled:!u,children:"Assign Surveyor"})]})]})}),e.jsx(U,{open:se,onOpenChange:_,children:e.jsxs(Q,{className:"max-w-2xl",children:[e.jsx($,{children:e.jsx(z,{children:"Request Details"})}),t&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[B(t.report_type),O(t.status),t.paid_at?e.jsx(n,{variant:"outline",className:"bg-green-50 text-green-700",children:"Paid"}):e.jsx(n,{variant:"outline",className:"bg-red-50 text-red-700",children:"Unpaid"})]}),e.jsxs("div",{className:"grid md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"font-semibold",children:"Customer Details"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(X,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:t.customer_name})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Se,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("a",{href:`mailto:${t.customer_email}`,className:"text-primary hover:underline",children:t.customer_email})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ke,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("a",{href:`tel:${t.customer_phone}`,className:"text-primary hover:underline",children:t.customer_phone})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"font-semibold",children:"Property Details"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"Address"}),e.jsx("div",{children:t.property_address})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"Postcode"}),e.jsx("div",{children:t.postcode})]})]})]})]}),e.jsxs("div",{className:"grid md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"font-semibold",children:"Assignment"}),e.jsx("div",{children:t.assigned_surveyor_name||e.jsx("span",{className:"text-muted-foreground",children:"Not yet assigned"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"font-semibold",children:"Price"}),e.jsxs("div",{className:"text-xl font-bold",children:["£",t.price]})]})]}),t.notes&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"font-semibold",children:"Notes"}),e.jsx("div",{className:"text-muted-foreground bg-muted/50 p-3 rounded-lg",children:t.notes})]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:["Created: ",T(new Date(t.created_at),"dd MMMM yyyy HH:mm"),t.completed_at&&e.jsxs("span",{children:[" | Completed: ",T(new Date(t.completed_at),"dd MMMM yyyy HH:mm")]})]})]}),e.jsx(W,{children:e.jsx(v,{variant:"outline",onClick:()=>_(!1),children:"Close"})})]})})]})}export{We 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.