PageSourceSearch

https://jhasolutions.com/assets/Maintenance-By4Vwr6j.js

js jhasolutions.com collected 2026-09-24 14:45:51 UTC 34,603 bytes, 1 lines download raw bytes

1import{r as j,j as e,u as ye,b as De,e as le}from"./query-vendor-Dp9tfhuh.js";import{F as ce,D as Te,x as Fe}from"./DashboardLayout-v_SFEx5M.js";import{P as Oe}from"./PageHeader-DAD15sYQ.js";import{d as Z,s as k,u as Ie,D as q,p as ee,q as te,r as se,L as w,B as v,w as We,h as Pe,a as de,c as H,T as Re,j as G}from"./index-CgOeqv80.js";import{I as Y}from"./input-go5takyh.js";import{T as ve}from"./textarea-BSB7eVDL.js";import{S as T,a as F,b as O,c as I,d as x}from"./select-Bqpq_Ta3.js";import{u as Ne}from"./useMaintenanceRequests-DqDKMQug.js";import{u as Ue}from"./useProperties-EVF9Wa0N.js";import{M as Le,u as $e,T as Ee}from"./useTenantData-BGYaOMsh.js";import{u as Be}from"./useWhatsAppIntegration-CFsyJ7KO.js";import{B as E}from"./badge-CarGzGVG.js";import{V as me}from"./video-DaS8rS9K.js";import{I as ze}from"./image-CayqqQKD.js";import{D as Ve}from"./download-B3iahoQg.js";import{W as B}from"./wrench-CDdvezGQ.js";import{C as z}from"./calendar-D4RFJDPY.js";import{f as R}from"./format-Ch7dQtBq.js";import{T as Ke,a as Qe,b as pe,c as ue}from"./tabs-CaoVN6UB.js";import{S as He}from"./scroll-area-DpCy8yLM.js";import{C as J}from"./clock-BmPJ466V.js";import{U as Ge}from"./user-check-XkucE5f8.js";import{D as X}from"./dollar-sign-D0iC4HrG.js";import{T as Ye}from"./trending-up-CRE5UWZg.js";import{M as Je}from"./message-square-B81woyC-.js";import{S as Xe}from"./send-Blf9Z7mq.js";import{M as Ze}from"./MobileFAB-BuVHAANZ.js";import{O as qe,a as et,b as tt,c as Q,e as xe,f as he,d as $}from"./OperationsWorkspace-DwthIjgh.js";import{u as st}from"./use-mobile-CojsY12Z.js";import{u as at}from"./useRouteAction-CySCP0-5.js";import{p as rt}from"./parseISO-k3Q1d3Py.js";import{i as it}from"./isToday-C3mvRkZe.js";import{P as ge}from"./plus-CYnN_kFu.js";import{C as nt}from"./clipboard-check-Cvc1fMv5.js";import{f as ot}from"./formatDistanceToNow-DExfhm_y.js";import"./ui-vendor-DW4RoVmg.js";import"./react-vendor-DfslLuwi.js";import"./separator-DP1KYTpB.js";import"./sheet-bqYui_d3.js";import"./skeleton-U7PtyM3w.js";import"./tooltip-CSLOX5Ak.js";import"./Logo-Dty4QCqO.js";import"./calendar-days-Cbs598pa.js";import"./building-2-BMIYvzwG.js";import"./users-9XO_ctWv.js";import"./map-pin-B63H-upO.js";import"./wifi-off-BfVaxzCl.js";import"./file-text-CuOiBfSM.js";import"./credit-card-B-2xvAjl.js";import"./panel-top-BGv8mfXo.js";import"./mail-CObWevXE.js";import"./log-out-SS0g6Uak.js";import"./bell-D0vTOuek.js";import"./check-check-2zE5w8gN.js";import"./en-US-5rFTtd83.js";import"./LanguageSwitcher-DHMsopEY.js";import"./dropdown-menu-BeZf8kFV.js";import"./chevron-right-BdUdHP_I.js";import"./check-v4vwqlB-.js";import"./circle-pSWMGBM_.js";import"./languages-DOZFgZ9Q.js";import"./message-circle-BYe5rrWz.js";import"./activity-CfnIewRD.js";import"./arrow-down-CIVFAk8G.js";import"./arrow-left-BmX2tYO6.js";import"./arrow-right-left-DF8EQ874.js";import"./arrow-right-ksEPM703.js";import"./banknote-CdW1Jv9F.js";import"./bed-B88pYHvh.js";import"./list-ordered-hB6RbGtG.js";import"./book-open-check-DYZCLGLv.js";import"./book-open-D0Y1dKqG.js";import"./brain-BohJitgU.js";import"./building-DasY5zOg.js";import"./calculator-ByooPTmb.js";import"./car-D3b4R55M.js";import"./landmark-BwZdzl4J.js";import"./chart-no-axes-column-increasing-C6Bh1bTG.js";import"./chart-pie-7jztI-xg.js";import"./chevron-down-Bm2Y15mk.js";import"./chevron-left-DCDYd6CA.js";import"./chevron-up-DVBQQKr7.js";import"./circle-check-big-CQmmVCDK.js";import"./circle-check-CLkepror.js";import"./message-square-text-W-2xUYbe.js";import"./circle-help-Cpt-rFJF.js";import"./circle-x-CMEjdGNX.js";import"./clipboard-list-FvLR_NG8.js";import"./clipboard-viWVwQwk.js";import"./copy-BEDU18te.js";import"./database-kv95WpLa.js";import"./zoom-out-zrJfLdu9.js";import"./external-link-BIGsQXrz.js";import"./twitter-BaxQU1X8.js";import"./file-chart-column-increasing-DEN9Rsed.js";import"./file-check-cM7E4NaC.js";import"./file-spreadsheet-ZK-q7Zgc.js";import"./filter-Bs-PYMIY.js";import"./folder-open-DFmVGiUq.js";import"./tree-pine-CouWAS-6.js";import"./globe-C_UDh3Yp.js";import"./hammer-691LkvTd.js";import"./heart-Dv9Odr8c.js";import"./hotel-C1w3GOsr.js";import"./house-5R4LHGOP.js";import"./image-plus-xT5L-tET.js";import"./infinity-wq20aEtI.js";import"./key-round-Dh3U7Shh.js";import"./pen-tool-_n2hBO7N.js";import"./keyboard-CSqz3mRU.js";import"./layers-D0VRol72.js";import"./lightbulb-DlRuWc33.js";import"./list-checks-coQAK2sr.js";import"./list-BJoWfKXY.js";import"./lock-B0M9hAnN.js";import"./map-pinned-B-fJbXg-.js";import"./map-C8rxfYCS.js";import"./maximize-2-CZGGiq67.js";import"./maximize-DHDDLx00.js";import"./menu-DuKtMQlr.js";import"./minus-04ztrfH_.js";import"./mouse-pointer-click-Bc_ivnf4.js";import"./mouse-CUCnDlYq.js";import"./navigation-mR6QetLo.js";import"./pause-DWfQPC5O.js";import"./pencil-d1bR18nI.js";import"./ruler-BoWqmUga.js";import"./phone-I9m-09C5.js";import"./play-CVPqrcf1.js";import"./printer-DjW2gpx9.js";import"./refresh-ccw-BR8hKK-Q.js";
1import"./rocket-DxjHbFsp.js";import"./rotate-ccw-CE2HFYnH.js";import"./rotate-cw-n6J_8Piu.js";import"./route-Df-61sSI.js";import"./save-DF6x0jpO.js";import"./scale-CZXGlUhc.js";import"./search-Dx_o7OfG.js";import"./share-2-sKHj2vjO.js";import"./square-plus-Dp1sCmj5.js";import"./skip-forward-eFm9X_4U.js";import"./smartphone-CBjqwShe.js";import"./square-check-big-DF0dFzei.js";import"./square-pen-Bg7uj701.js";import"./square-MsVDU0g-.js";import"./star-DlIZz9Im.js";import"./trash-2-DAqLpVlV.js";import"./trending-down-COltpy2W.js";import"./upload-55xlfOPi.js";import"./user-DV5oCLCs.js";import"./volume-2-DTT7l7C1.js";import"./volume-x-BBMkTIRp.js";import"./wallet-_cnDvlQk.js";import"./workflow-Bfwpj-zP.js";import"./zap-BKGpOGd1.js";import"./useIsRTL-D_a81cVb.js";import"./useOrganization-msM7McOc.js";import"./chart-vendor-BoynbIzZ.js";import"./index-BdQq_4o_.js";import"./whatsappBrowser-Bk8kXzkW.js";import"./isSameDay-DKb4pGQS.js";const lt=()=>{const{user:r}=Z(),{session:a,sendWhatsAppMessage:t}=Be();return{sendMaintenanceAlert:async(c,u,d,n,m)=>{try{return await t.mutateAsync({to:c,message:n,tenantId:u,maintenanceRequestId:d,propertyId:m}),!0}catch(f){return console.error("Failed to send WhatsApp maintenance alert:",f),!1}},sendRentReminder:async(c,u,d,n,m)=>{try{return await t.mutateAsync({to:c,message:n,tenantId:u,leaseId:d,propertyId:m}),!0}catch(f){return console.error("Failed to send WhatsApp rent reminder:",f),!1}},sendTenantMessage:async(c,u,d,n,m,f)=>{try{return await t.mutateAsync({to:c,message:d,tenantId:u,propertyId:n,leaseId:m,maintenanceRequestId:f}),!0}catch(h){return console.error("Failed to send WhatsApp tenant message:",h),!1}},getTenantPhone:async c=>{try{const{data:u,error:d}=await k.from("profiles").select("phone").eq("id",c).single();if(d)throw d;return(u==null?void 0:u.phone)||null}catch(u){return console.error("Failed to fetch tenant phone:",u),null}},isWhatsAppEnabled:(a==null?void 0:a.connection_status)==="connected",preferences:{maintenanceAlerts:!0,rentReminders:!0,tenantMessages:!0}}};function ct({open:r,onOpenChange:a,request:t}){const{t:g}=Ie(),{createRequest:i,updateRequest:o}=Ne(),{sendMaintenanceAlert:l,getTenantPhone:c}=lt(),{properties:u}=Ue(),{user:d}=Z(),[n,m]=j.useState({property_id:(t==null?void 0:t.property_id)||"",title:(t==null?void 0:t.title)||"",description:(t==null?void 0:t.description)||"",category:(t==null?void 0:t.category)||"plumbing",priority:(t==null?void 0:t.priority)||"medium",status:(t==null?void 0:t.status)||"open"});j.useEffect(()=>{t&&m({property_id:t.property_id,title:t.title,description:t.description,category:t.category||"plumbing",priority:t.priority,status:t.status})},[t]);const f=async h=>{if(h.preventDefault(),t){const C=t.status;if(await o.mutateAsync({id:t.id,...n}),C!==n.status&&t.tenant_id){const _=await c(t.tenant_id);if(_){const N=`Maintenance Request Update: Your maintenance request "${n.title}" has been updated to status: ${n.status}`;await l(_,t.tenant_id,t.id,N,n.property_id)}}}else await i.mutateAsync({request:{...n,tenant_id:d.id,unit_id:null,assigned_to:null,estimated_cost:null,actual_cost:null,completed_at:null}});a(!1)};return e.jsx(q,{open:r,onOpenChange:a,children:e.jsxs(ee,{className:"max-w-2xl",children:[e.jsx(te,{children:e.jsx(se,{children:t?"Edit Request":"New Maintenance Request"})}),e.jsxs("form",{onSubmit:f,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"property_id",children:"Property"}),e.jsxs(T,{value:n.property_id,onValueChange:h=>m({...n,property_id:h}),required:!0,children:[e.jsx(F,{children:e.jsx(O,{placeholder:g("common.selectProperty")})}),e.jsx(I,{children:u.map(h=>e.jsx(x,{value:h.id,children:h.name},h.id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"title",children:"Title"}),e.jsx(Y,{id:"title",value:n.title,onChange:h=>m({...n,title:h.target.value}),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"description",children:"Description"}),e.jsx(ve,{id:"description",value:n.description,onChange:h=>m({...n,description:h.target.value}),rows:4,required:!0})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"category",children:"Category"}),e.jsxs(T,{value:n.category||"",onValueChange:h=>m({...n,category:h}),children:[e.jsx(F,{children:e.jsx(O,{})}),e.jsxs(I,{children:[e.jsx(x,{value:"plumbing",children:"Plumbing"}),e.jsx(x,{value:"electrical",children:"Electrical"}),e.jsx(x,{value:"hvac",children:"HVAC"}),e.jsx(x,{value:"appliance",children:"Appliance"}),e.jsx(x,{value:"structural",children:"Structural"}),e.jsx(x,{value:"other",children:"Other"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"priority",children:"Priority"}),e.jsxs(T,{value:n.priority,onValueChange:h=>m({...n,priority:h}),children:[e.jsx(F,{children:e.jsx(O,{})}),e.jsxs(I,{children:[e.jsx(x,{value:"low",children:"Low"}),e.jsx(x,{value:"medium",children:"Medium"}),e.jsx(x,{value:"high",children:"High"}),e.jsx(x,{value:"urgent",children:"Urgent"})]})]})]}),t&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"status",children:"Status"}),e.jsxs(T,{value:n.status,onValueChange:h=>m({...n,status:h}),children:[e.jsx(F,{children:e.jsx(O,{})}),e.jsxs(I,{children:[e.jsx(x,{value:"open",children:"Open"}),e.jsx(x,{value:"in_progress",children:"In Progress"}),e.jsx(x,{value:"completed",children:"Completed"}),e.jsx(x,{value:"cancelled",children:"Cancelled"})]})]})]})]}),!t&&n.description&&n.category&&n.property_id&&e.jsx(Le,{description:n.description,category:n.category,propertyId:n.property_id}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(v,{type:"button",variant:"outline",onClick:()=>a(!1),children:"Cancel"}
1),e.jsx(v,{type:"submit",children:t?"Update":"Submit Request"})]})]})]})})}const dt=r=>ye({queryKey:["maintenance-attachments",r],queryFn:async()=>{if(!r)return[];const{data:a,error:t}=await k.from("maintenance_attachments").select("*").eq("request_id",r).order("uploaded_at",{ascending:!0});if(t)throw t;return a||[]},enabled:!!r}),we=({requestId:r})=>{const{data:a,isLoading:t}=dt(r);if(t)return e.jsx("div",{className:"flex justify-center p-4",children:e.jsx(We,{size:"md"})});if(!a||a.length===0)return e.jsx("div",{className:"text-center p-4 text-muted-foreground",children:"No attachments"});const g=i=>i<1024?i+" B":i<1024*1024?(i/1024).toFixed(1)+" KB":(i/(1024*1024)).toFixed(1)+" MB";return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-sm font-medium",children:["Attachments (",a.length,")"]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-3",children:a.map(i=>{const o=i.file_type.startsWith("image/"),l=i.file_type.startsWith("video/");return e.jsxs(Pe,{className:"overflow-hidden group relative hover:shadow-md transition-all",children:[e.jsx("a",{href:i.file_url,target:"_blank",rel:"noopener noreferrer",className:"block",children:e.jsxs("div",{className:"aspect-square relative bg-muted",children:[o?e.jsx("img",{src:i.file_url,alt:"Attachment",className:"w-full h-full object-cover transition-transform group-hover:scale-105",loading:"lazy"}):l?e.jsx("div",{className:"w-full h-full flex items-center justify-center bg-gradient-to-br from-primary/10 to-primary/5",children:e.jsx(me,{className:"w-12 h-12 text-primary"})}):e.jsx("div",{className:"w-full h-full flex items-center justify-center bg-gradient-to-br from-muted to-muted/50",children:e.jsx(ce,{className:"w-12 h-12 text-muted-foreground"})}),e.jsxs("div",{className:"absolute inset-0 bg-gradient-to-t from-black/80 via-black/30 to-transparent opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center",children:[o&&e.jsx(ze,{className:"w-8 h-8 text-white drop-shadow-lg"}),l&&e.jsx(me,{className:"w-8 h-8 text-white drop-shadow-lg"}),!o&&!l&&e.jsx(ce,{className:"w-8 h-8 text-white drop-shadow-lg"})]})]})}),e.jsxs("div",{className:"p-2 space-y-1 bg-card",children:[e.jsx("p",{className:"text-xs text-muted-foreground truncate font-medium",children:g(i.file_size)}),e.jsx(v,{variant:"ghost",size:"sm",className:"w-full h-7 text-xs hover:bg-primary/10 hover:text-primary",asChild:!0,children:e.jsxs("a",{href:i.file_url,download:!0,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(Ve,{className:"w-3 h-3 mr-1"}),"Download"]})})]})]},i.id)})})]})},mt=({open:r,onOpenChange:a,request:t})=>{if(!t)return null;const g={urgent:"bg-destructive/10 text-destructive border-destructive/20",high:"bg-destructive/10 text-destructive border-destructive/20",medium:"bg-secondary/10 text-secondary border-secondary/20",low:"bg-muted-foreground/10 text-muted-foreground border-muted-foreground/20"},i={open:"bg-destructive/10 text-destructive",in_progress:"bg-secondary/10 text-secondary",completed:"bg-accent/10 text-accent",cancelled:"bg-muted-foreground/10 text-muted-foreground"};return e.jsx(q,{open:r,onOpenChange:a,children:e.jsxs(ee,{className:"max-w-3xl max-h-[90vh] overflow-y-auto",children:[e.jsx(te,{children:e.jsx("div",{className:"space-y-3",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-3 sm:gap-4",children:[e.jsx(se,{className:"text-lg sm:text-xl pr-2",children:t.title}),e.jsxs("div",{className:"flex gap-2 flex-shrink-0 flex-wrap",children:[e.jsx(E,{variant:"outline",className:g[t.priority],children:t.priority.toUpperCase()}),e.jsx(E,{className:i[t.status],children:t.status.replace("_"," ").toUpperCase()})]})]})})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-2",children:"Description"}),e.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-wrap",children:t.description})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-2 text-sm p-3 rounded-lg bg-muted/50",children:[e.jsx(B,{className:"w-4 h-4 text-muted-foreground mt-0.5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium block",children:"Category"}),e.jsx("span",{className:"text-muted-foreground capitalize",children:t.category||"General"})]})]}),e.jsxs("div",{className:"flex items-start gap-2 text-sm p-3 rounded-lg bg-muted/50",children:[e.jsx(z,{className:"w-4 h-4 text-muted-foreground mt-0.5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium block",children:"Created"}),e.jsx("span",{className:"text-muted-foreground",children:R(new Date(t.created_at),"MMM d, yyyy h:mm a")})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[t.completed_at&&e.jsxs("div",{className:"flex items-start gap-2 text-sm p-3 rounded-lg bg-muted/50",children:[e.jsx(z,{className:"w-4 h-4 text-muted-foreground mt-0.5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium block",children:"Completed"}),e.jsx("span",{className:"text-muted-foreground",children:R(new Date(t.completed_at),"MMM d, yyyy h:mm a")})]})]}),t.estimated_cost&&e.jsxs("div",{className:"flex items-start gap-2 text-sm p-3 rounded-lg bg-muted/50",children:[e.jsx("span",{className:"font-medium block",children:"Estimated Cost"}),e.jsxs("span",{className:"text-muted-foreground",children:["$",t.estimated_cost.toFixed(2)]})]}),t.actual_cost&&e.jsxs("div",{className:"flex items-start gap-2 text-sm p-3 rounded-lg bg-muted/50",children:[e.jsx("span",{className:"font-medium block",children:"Actual Cost"}),e.jsxs("span",{className:"text-muted-foreground",children:["$",t.actual_cost.toFixed(2)]})]})]})]})]}),e.jsx("div",{className:"border-t pt-4",children:e.jsx(we,{requestId:t.id})}),e.jsx("div",{className:"flex gap-2 justify-end border-t pt-4",children:e.jsx(v,{variant:"outline",onClick:()=>a(!1),children:"Close"})})]})]})})},pt=r=>{const a=De(),{data:t,isLoading:g}=ye({queryKey:["maintenance-activities",r],queryFn:async()=>
1{if(!r)return[];const{data:l,error:c}=await k.from("maintenance_activities").select("*").eq("request_id",r).order("created_at",{ascending:!0});if(c)throw c;return l||[]},enabled:!!r}),i=le({mutationFn:async({requestId:l,content:c})=>{const{data:{user:u}}=await k.auth.getUser();if(!u)throw new Error("Not authenticated");const{error:d}=await k.from("maintenance_activities").insert({request_id:l,user_id:u.id,activity_type:"comment",content:c});if(d)throw d},onSuccess:(l,c)=>{a.invalidateQueries({queryKey:["maintenance-activities",c.requestId]}),de.success("Comment added")},onError:l=>{de.error(`Failed to add comment: ${l.message}`)}}),o=le({mutationFn:async({requestId:l,activityType:c,content:u,metadata:d})=>{const{data:{user:n}}=await k.auth.getUser();if(!n)throw new Error("Not authenticated");const{error:m}=await k.from("maintenance_activities").insert({request_id:l,user_id:n.id,activity_type:c,content:u,metadata:d});if(m)throw m},onSuccess:(l,c)=>{a.invalidateQueries({queryKey:["maintenance-activities",c.requestId]})}});return{activities:t||[],isLoading:g,addComment:i.mutate,isAddingComment:i.isPending,logActivity:o.mutate}},ut=({status:r,priority:a})=>{const t={open:"bg-destructive/10 text-destructive border-destructive/20",in_progress:"bg-primary/10 text-primary border-primary/20",completed:"bg-accent/10 text-accent border-accent/20",cancelled:"bg-muted-foreground/10 text-muted-foreground border-muted-foreground/20"},g={urgent:"bg-destructive text-destructive-foreground",high:"bg-destructive/80 text-destructive-foreground",medium:"bg-primary text-primary-foreground",low:"bg-muted text-muted-foreground"};return e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsx(E,{variant:"outline",className:H("text-xs",t[r]),children:r.replace("_"," ").toUpperCase()}),e.jsx(E,{className:H("text-xs",g[a]),children:a.toUpperCase()})]})},xt=({activities:r,isLoading:a})=>{const t=o=>{switch(o){case"comment":return e.jsx(Je,{className:"w-4 h-4"});case"status_change":return e.jsx(Ye,{className:"w-4 h-4"});case"cost_update":return e.jsx(X,{className:"w-4 h-4"});case"assignment":return e.jsx(Ge,{className:"w-4 h-4"});default:return e.jsx(J,{className:"w-4 h-4"})}},g=o=>{switch(o){case"comment":return"bg-primary/10 text-primary border-primary/20";case"status_change":return"bg-accent/10 text-accent border-accent/20";case"cost_update":return"bg-secondary/10 text-secondary border-secondary/20";case"assignment":return"bg-muted text-muted-foreground border-muted-foreground/20";default:return"bg-muted text-muted-foreground border-muted-foreground/20"}},i=o=>{var l,c,u,d;if(o.content)return o.content;switch(o.activity_type){case"status_change":return`Status changed to ${((l=o.metadata)==null?void 0:l.new_status)||"unknown"}`;case"cost_update":return`Cost updated: ${((c=o.metadata)==null?void 0:c.field)||"cost"} set to $${((u=o.metadata)==null?void 0:u.value)||0}`;case"assignment":return`Assigned to ${((d=o.metadata)==null?void 0:d.assignee)||"someone"}`;default:return"Activity logged"}};return a?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx("div",{className:"animate-pulse text-sm text-muted-foreground",children:"Loading activity..."})}):r.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(J,{className:"w-8 h-8 text-muted-foreground/50 mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No activity yet"})]}):e.jsx(He,{className:"h-[300px] pr-4",children:e.jsx("div",{className:"space-y-4",children:r.map((o,l)=>e.jsxs("div",{className:"flex gap-3 group",children:[e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:H("flex items-center justify-center w-8 h-8 rounded-full border-2 transition-all",g(o.activity_type),"group-hover:scale-110"),children:t(o.activity_type)}),l<r.length-1&&e.jsx("div",{className:"w-0.5 h-full min-h-[40px] bg-border mt-2"})]}),e.jsx("div",{className:"flex-1 pb-4",children:e.jsxs("div",{className:"bg-muted/30 rounded-lg p-3 transition-all group-hover:bg-muted/50",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2 mb-1",children:[e.jsx("p",{className:"text-sm font-medium capitalize",children:o.activity_type.replace("_"," ")}),e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:R(new Date(o.created_at),"MMM d, h:mm a")})]}),e.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-wrap",children:i(o)})]})})]},o.id))})})},ht=({onSubmit:r,isSubmitting:a})=>{const[t,g]=j.useState(""),i=()=>{t.trim()&&(r(t),g(""))},o=l=>{l.key==="Enter"&&(l.metaKey||l.ctrlKey)&&i()};return e.jsxs("div",{className:"space-y-2",children:[e.jsx(ve,{placeholder:"Add a comment... (Cmd/Ctrl + Enter to send)",value:t,onChange:l=>g(l.target.value),onKeyDown:o,className:"min-h-[80px] resize-none",disabled:a}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(v,{onClick:i,disabled:!t.trim()||a,size:"sm",className:"gap-2",children:[e.jsx(Xe,{className:"w-4 h-4"}),a?"Sending...":"Send Comment"]})})]})}
1,gt=({open:r,onOpenChange:a,request:t,onUpdate:g,isUpdating:i})=>{var M,P;const[o,l]=j.useState((t==null?void 0:t.status)||"open"),[c,u]=j.useState((t==null?void 0:t.priority)||"medium"),[d,n]=j.useState(((M=t==null?void 0:t.estimated_cost)==null?void 0:M.toString())||""),[m,f]=j.useState(((P=t==null?void 0:t.actual_cost)==null?void 0:P.toString())||""),[h,C]=j.useState(""),{activities:_,isLoading:N,addComment:V,isAddingComment:K,logActivity:W}=pt((t==null?void 0:t.id)||null);if(j.useEffect(()=>{var y,b;t&&(l(t.status),u(t.priority),n(((y=t.estimated_cost)==null?void 0:y.toString())||""),f(((b=t.actual_cost)==null?void 0:b.toString())||""))},[t]),!t)return null;const S=()=>{var b,U;const y={status:o,priority:c,estimated_cost:d?parseFloat(d):null,actual_cost:m?parseFloat(m):null};o==="completed"&&!t.completed_at&&(y.completed_at=new Date().toISOString()),o!==t.status&&W({requestId:t.id,activityType:"status_change",metadata:{old_status:t.status,new_status:o}}),d&&d!==((b=t.estimated_cost)==null?void 0:b.toString())&&W({requestId:t.id,activityType:"cost_update",metadata:{field:"estimated_cost",value:d}}),m&&m!==((U=t.actual_cost)==null?void 0:U.toString())&&W({requestId:t.id,activityType:"cost_update",metadata:{field:"actual_cost",value:m}}),g(t.id,y)},A=y=>{V({requestId:t.id,content:y})};return e.jsx(q,{open:r,onOpenChange:a,children:e.jsxs(ee,{className:"max-w-3xl max-h-[90vh] overflow-y-auto",children:[e.jsx(te,{children:e.jsx("div",{className:"space-y-3",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-3",children:[e.jsx(se,{className:"text-lg sm:text-xl pr-2",children:t.title}),e.jsx(ut,{status:t.status,priority:t.priority})]})})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4 p-4 bg-muted/30 rounded-lg",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-2",children:"Description"}),e.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-wrap",children:t.description})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm p-2 rounded bg-background/50",children:[e.jsx(z,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium block text-xs",children:"Created"}),e.jsx("span",{className:"text-muted-foreground",children:R(new Date(t.created_at),"MMM d, yyyy h:mm a")})]})]}),t.completed_at&&e.jsxs("div",{className:"flex items-center gap-2 text-sm p-2 rounded bg-background/50",children:[e.jsx(z,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium block text-xs",children:"Completed"}),e.jsx("span",{className:"text-muted-foreground",children:R(new Date(t.completed_at),"MMM d, yyyy h:mm a")})]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Management"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"status",children:"Status"}),e.jsxs(T,{value:o,onValueChange:l,children:[e.jsx(F,{id:"status",children:e.jsx(O,{})}),e.jsxs(I,{children:[e.jsx(x,{value:"open",children:"Open"}),e.jsx(x,{value:"in_progress",children:"In Progress"}),e.jsx(x,{value:"completed",children:"Completed"}),e.jsx(x,{value:"cancelled",children:"Cancelled"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"priority",children:"Priority"}),e.jsxs(T,{value:c,onValueChange:u,children:[e.jsx(F,{id:"priority",children:e.jsx(O,{})}),e.jsxs(I,{children:[e.jsx(x,{value:"urgent",children:"Urgent"}),e.jsx(x,{value:"high",children:"High"}),e.jsx(x,{value:"medium",children:"Medium"}),e.jsx(x,{value:"low",children:"Low"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"estimated-cost",children:"Estimated Cost"}),e.jsxs("div",{className:"relative",children:[e.jsx(X,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(Y,{id:"estimated-cost",type:"number",step:"0.01",placeholder:"0.00",value:d,onChange:y=>n(y.target.value),className:"pl-8"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"actual-cost",children:"Actual Cost"}),e.jsxs("div",{className:"relative",children:[e.jsx(X,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(Y,{id:"actual-cost",type:"number",step:"0.01",placeholder:"0.00",value:m,onChange:y=>f(y.target.value),className:"pl-8"})]})]})]})]}),e.jsx("div",{className:"border-t pt-4",children:e.jsxs(Ke,{defaultValue:"attachments",className:"w-full",children:[e.jsxs(Qe,{className:"flex w-full md:grid md:grid-cols-2",children:[e.jsx(pe,{value:"attachments",children:"Attachments"}),e.jsx(pe,{value:"activity",children:"Activity & Comments"})]}),e.jsx(ue,{value:"attachments",className:"mt-4",children:e.jsx(we,{requestId:t.id})}),e.jsxs(ue,{value:"activity",className:"mt-4 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold mb-3",children:"Add Comment"}),e.jsx(ht,{onSubmit:A,isSubmitting:K})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold mb-3",children:"Activity Timeline"}),e.jsx(xt,{activities:_,isLoading:N})]})]})]})}),e.jsxs("div",{className:"flex gap-2 justify-end border-t pt-4",children:[e.jsx(v,{variant:"outline",onClick:()=>a(!1),disabled:i,children:"Cancel"}),e.jsx(v,{onClick:S,disabled:i,children:i?"Updating...":"Update Request"})]})]})]})})};function fe(r){const a=(r==null?void 0:r.toLowerCase())||"maintenance";return a.includes("clean")?"cleaning":a.includes("turnover")?"turnover":a.includes("inspect")?"inspection":a.includes("restock")?"restock":"maintenance"}function ft(r){switch(r){case"completed":return"success";case"in_progress":return"info";case"cancelled":return"default";default:return"warning"}}function je(r){switch(r){case"urgent":case"high":return"danger";case"medium":return"warning";default:return"default"}}function jt(r){switch(r){case"cleaning":case"turnover":return G;case"inspection":return Fe;default:return B}}const jr=()=>{var ie,ne,oe;const[r,a]=j.useState(!1),[t,g]=j.useState(""),[i,o]=j.useState("all"),[l,c]=j.useState(null),[u,d]=j.useState(!1),[n,m]=j.useState(!1),{requests:f,isLoading:h,updateRequest:C}=Ne(),{userRole:_}=Z(),{data:N}=$e(),V=st(),K=_==="tenant",W=_!=="tenant",S=j.useMemo(()=>f.map(s=>{const p=fe(s.category),L=rt(s.created_at);return{request:s,workType:p,isCleanerWork:p==="cleaning"||p==="turnover",isTodayWork:it(L)||s.status==="open"||s.status==="in_progress"}}),[f]),A=j.useMemo(()=>{const s=t.trim().toLowerCase();return S.filter(({request:p,workType:L,isCleanerWork:D,isTodayWork:ke})=>{const Se=[p.title,p.description,p.category,p.priority,p.status].filter(
1Boolean).join(" ").toLowerCase(),Ae=s.length===0||Se.includes(s),Me=i==="all"||i==="today"&&ke||i==="open"&&(p.status==="open"||p.status==="in_progress")||i==="cleaning"&&D||i==="urgent"&&(p.priority==="urgent"||p.priority==="high")||i==="completed"&&p.status==="completed";return Ae&&Me}).map(({request:p})=>p)},[i,S,t]),M=f.filter(s=>s.status==="open").length,P=f.filter(s=>s.status==="in_progress").length,y=S.filter(s=>s.isCleanerWork&&s.request.status!=="completed").length,b=f.filter(s=>s.priority==="urgent"||s.priority==="high").length,U=f.filter(s=>s.status==="completed").length,ae=S.filter(s=>s.isCleanerWork&&s.request.status!=="completed").map(s=>s.request).slice(0,5),re=s=>{c(s),W?m(!0):d(!0)},be=(s,p)=>{C.mutate({id:s,...p},{onSuccess:()=>m(!1)})},Ce=s=>{C.mutate({id:s.id,status:"in_progress"})},_e=s=>{C.mutate({id:s.id,status:"completed",completed_at:new Date().toISOString()})};return at("new",()=>a(!0)),e.jsxs(Te,{className:"pb-24 md:pb-6",children:[e.jsx(Oe,{title:"Work Orders",subtitle:"Maintenance, cleaning, inspections, turnovers, and staff work in one queue",icon:e.jsx(B,{className:"h-5 w-5"}),actions:!V&&e.jsxs(v,{onClick:()=>a(!0),children:[e.jsx(ge,{className:"h-4 w-4"}),e.jsx("span",{className:"ml-2",children:"New Work Order"})]})}),e.jsx(qe,{metrics:[{label:"Open",value:M,detail:"Waiting to be started",icon:Re,tone:M>0?"warning":"default"}
1,{label:"In progress",value:P,detail:"Assigned or currently active",icon:J,tone:"info"},{label:"Cleaning queue",value:y,detail:"Cleaning and turnover work",icon:G,tone:y>0?"success":"default"},{label:"Urgent",value:b,detail:`${U} completed total`,icon:nt,tone:b>0?"danger":"default"}]}),e.jsx(et,{searchValue:t,onSearchChange:g,searchPlaceholder:"Search work orders, category, priority, or notes",children:[["all","All"],["today","Today"],["open",`Open ${M+P}`],["cleaning",`Cleaning ${y}`],["urgent",`Urgent ${b}`],["completed","Completed"]].map(([s,p])=>e.jsx(tt,{active:i===s,onClick:()=>o(s),children:p},s))}),e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,1fr)_400px]",children:[e.jsx(Q,{title:"Work Queue",subtitle:`${A.length} work order${A.length===1?"":"s"} shown`,children:h?e.jsx("div",{className:"space-y-3",children:[1,2,3,4].map(s=>e.jsx("div",{className:"h-28 animate-pulse rounded-lg bg-muted"},s))}):A.length===0?e.jsx(xe,{icon:B,title:"No work orders in this view",description:"Create a work order or adjust the filters to find maintenance and cleaning tasks.",action:e.jsx(v,{variant:"outline",onClick:()=>a(!0),children:"New Work Order"})}):e.jsx("div",{className:"space-y-3",children:A.map(s=>{const p=fe(s.category),L=jt(p);return e.jsx(he,{onClick:()=>re(s),children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-md border bg-muted",children:e.jsx(L,{className:"h-5 w-5 text-muted-foreground"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"font-medium",children:s.title}),e.jsx($,{tone:ft(s.status),children:s.status.replace("_"," ")}),e.jsx($,{tone:je(s.priority),children:s.priority}),e.jsx($,{tone:p==="cleaning"||p==="turnover"?"success":"default",children:p})]}),e.jsx("p",{className:"mt-1 line-clamp-2 text-sm text-muted-foreground",children:s.description}),e.jsxs("p",{className:"mt-2 text-xs text-muted-foreground",children:["Created ",ot(new Date(s.created_at),{addSuffix:!0}),s.estimated_cost!=null&&` - Est. $${Number(s.estimated_cost).toLocaleString()}`]})]}),e.jsxs("div",{className:"flex shrink-0 flex-col gap-2",children:[s.status==="open"&&e.jsx(v,{size:"sm",variant:"secondary",onClick:D=>{D.stopPropagation(),Ce(s)},children:"Start"}),s.status==="in_progress"&&e.jsx(v,{size:"sm",onClick:D=>{D.stopPropagation(),_e(s)},children:"Done"})]})]})},s.id)})})}),e.jsxs("div",{className:"space-y-6",children:[e.jsx(Q,{title:"Cleaner Board",subtitle:"Fast view for cleaning and turnovers",children:ae.length===0?e.jsx(xe,{icon:G,title:"No cleaner work waiting",description:"Cleaning and turnover jobs will appear here as soon as they are created."}):e.jsx("div",{className:"space-y-3",children:ae.map(s=>e.jsx(he,{onClick:()=>re(s),children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-medium",children:s.title}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:s.description})]}),e.jsx($,{tone:je(s.priority),children:s.priority})]})},s.id))})}),e.jsx(Q,{title:"Standard Checklist",subtitle:"Simple flow for cleaners and maintenance staff",children:e.jsx("div",{className:"space-y-3 text-sm",children:["Open the work order and confirm property/unit details.","Upload before photos when the job starts.","Complete repair, cleaning, inspection, or turnover checklist.","Upload after photos and mark Done for manager review."].map((s,p)=>e.jsxs("div",{className:"flex gap-3 rounded-lg border p-3",children:[e.jsx("div",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full border bg-muted text-xs font-medium",children:p+1}),e.jsx("p",{children:s})]},s))})})]})]}),e.jsx(Ze,{icon:e.jsx(ge,{className:"h-6 w-6"}),label:"New Work Order",onClick:()=>a(!0)}),K?e.jsx(Ee,{open:r,onOpenChange:a,unitId:(ie=N==null?void 0:N.lease)==null?void 0:ie.unit_id,propertyId:(oe=(ne=N==null?void 0:N.lease)==null?void 0:ne.unit)==null?void 0:oe.property_id}):e.jsx(ct,{open:r,onOpenChange:a}),e.jsx(mt,{open:u,onOpenChange:d,request:l}),e.jsx(gt,{open:n,onOpenChange:m,request:l,onUpdate:be,isUpdating:C.isPending})]})};export{jr 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.