1import{c as V,ay as w,az as B,aD as K,b8 as G,al as S,aU as E,bn as _e,bo as we,j as e,bi as Ae,bj as De,bk as Ce,bl as Se,bm as Re,aM as v,I as y,bp as ke,G as Ee,J as Pe,K as Fe,N as Me,O as q,bq as Oe,B as _,a5 as k,br as Te,bs as C,bt as Le,bu as Q,bv as Ie,r as i,bw as qe,n as U,bx as $e,h as ze,by as Ve,l as Be,bz as Ke,bA as Ge,bB as Qe,bC as H,bD as Ue,bE as He,s as j,bF as J,S as Je,ar as W,F as We,bG as $,t as Ye,a6 as Xe,U as Ze,ah as es,bh as ss,a4 as as,ao as ts}from"./index-DmmRUugt.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const rs=V("LogIn",[["path",{d:"M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4",key:"u53s6r"}],["polyline",{points:"10 17 15 12 10 7",key:"1ail0h"}],["line",{x1:"15",x2:"3",y1:"12",y2:"12",key:"v6grx8"}]]);/** 7 * @license lucide-react v0.462.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const ns=V("UserPlus",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]]),ls=()=>{const{membership:s}=w();return B({queryKey:["team-all-companies"],queryFn:async()=>{const{data:a,error:t}=await E.rpc("haulops_admin_list_all_members");if(t)throw t;const r=a;if(!r.success)throw new Error(r.error||"Failed to load companies");return r.companies||[]},enabled:(s==null?void 0:s.role)==="admin"})},os=()=>{const{membership:s}=w();return B({queryKey:["team-members",s==null?void 0:s.effective_company],queryFn:async()=>{const{data:a,error:t}=await E.rpc("haulops_list_team_members");if(t)throw t;const r=a;if(!r.success)throw new Error(r.error||"Failed to load team");return r.members||[]},enabled:!!s&&s.role!=="admin"})},is=()=>{const s=K();return G({mutationFn:async a=>{const{data:t,error:r}=await E.rpc("haulops_add_team_member",{p_first_name:a.first_name,p_last_name:a.last_name,p_email:a.email,p_cell_number:a.cell_number,p_role:a.role,p_company_name:a.company_name||null});if(r)throw r;const l=t;if(!l.success)throw new Error(l.error||"Failed to add member");return l},onSuccess:()=>{S.success("Team member added"),s.invalidateQueries({queryKey:["team-members"]}),s.invalidateQueries({queryKey:["team-all-companies"]})},onError:a=>{S.error(a.message||"Failed to add member")}})},Y=()=>{const s=K();return G({mutationFn:async a=>{const{data:t,error:r}=await E.rpc("haulops_remove_team_member",{p_member_id:a});if(r)throw r;const l=t;if(!l.success)throw new Error(l.error||"Failed to remove member");return l},onSuccess:()=>{S.success("Team member removed"),s.invalidateQueries({queryKey:["team-members"]}),s.invalidateQueries({queryKey:["team-all-companies"]})},onError:a=>{S.error(a.message||"Failed to remove member")}})},cs=/^[\d\s\-()]+$/,ds=Te({first_name:C().min(1,"First name is required").max(50),last_name:C().min(1,"Last name is required").max(50),email:C().email("Invalid email address").max(255),cell_number:C().min(10,"Phone number is required").max(20).regex(cs,"Invalid phone format"),role:Le(["client","staff"]),company_name:C().optional()}),X=({open:s,onOpenChange:a})=>{const{membership:t}=w(),r=is(),l=(t==null?void 0:t.role)==="admin",{register:m,handleSubmit:c,reset:d,control:x,formState:{errors:n}}=_e({resolver:we(ds),defaultValues:{first_name:"",last_name:"",email:"",cell_number:"",role:"staff",company_name:""}}),u=async h=>{var A;const R={first_name:h.first_name.trim(),last_name:h.last_name.trim(),email:h.email.trim().toLowerCase(),cell_number:h.cell_number.trim(),role:h.role,company_name:l?(A=h.company_name)==null?void 0:A.trim():void 0};await r.mutateAsync(R),b()},b=()=>{d(),a(!1)};return e.jsx(Ae,{open:s,onOpenChange:b,children:e.jsxs(De,{className:"max-w-md",children:[e.jsxs(Ce,{children:[e.jsxs(Se,{className:"flex items-center gap-2",children:[e.jsx(ns,{className:"h-5 w-5"}),"Add Team Member"]}),e.jsxs(Re,{children:["Add a new member to"," ",l?"a company":"your team","."]})]}),e.jsxs("form",{onSubmit:c(u),className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(v,{htmlFor:"first_name",children:"First Name *"}),e.jsx(y,{id:"first_name",...m("first_name"),placeholder:"John",className:n.first_name?"border-destructive":""}),n.first_name&&e.jsx("p",{className:"text-xs text-destructive",children:n.first_name.message})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(v,{htmlFor:"last_name",children:"Last Name *"}),e.jsx(y,{id:"last_name",...m("last_name"),placeholder:"Doe",className:n.last_name?"border-destructive":""}),n.last_name&&e.jsx("p",{className:"text-xs text-destructive",children:n.last_name.message})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(v,{htmlFor:"email",children:"Email *"}),e.jsx(y,{id:"email",type:"email",...m("email"),placeholder:"[email protected]",className:n.email?"border-destructive":""}),n.email&&e.jsx("p",{className:"text-xs text-destructive",children:n.email.message})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(v,{htmlFor:"cell_number",children:"Cell Number *"}),e.jsx(y,{id:"cell_number",...m("cell_number"),placeholder:"(555) 123-4567",className:n.cell_number?"border-destructive":""}),n.cell_number&&e.jsx("p",{className:"text-xs text-destructive",children:n.cell_number.message})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(v,{children:"Role *"}),e.jsx(ke,{control:x,name:"role",render:({field:h})=>e.jsxs(Ee,{onValueChange:h.onChange,value:h.value,children:[e.jsx(Pe,{children:e.jsx(Fe,{placeholder:"Select role"})}),e.jsxs(Me,{children:[e.jsx(q,{value:"client",children:"Client"}),e.jsx(q,{value:"staff",children:"Staff"})]})]})}),n.role&&e.jsx("p",{className:"text-xs text-destructive",children:n.role.message})]}),l&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(v,{htmlFor:"company_name",children:"Company Name *"}),e.jsx(y,{id:"company_name",...m("company_name"),placeholder:"acme_corp",className:n.company_name?"border-destructive":""}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Use snake_case (e.g. johnston_group)"}),n.company_name&&e.jsx("p",{className:"text-xs text-destructive",children:n.company_name.message})]}),e.jsxs(Oe,{children:[e.jsx(_,{type:"button",variant:"outline",onClick:b,children:"Cancel"}),e.jsxs(_,{type:"submit",disabled:r.isPending,children:[r.isPending&&e.jsx(k,{className:"h-4 w-4 mr-2 animate-spin"}),"Add Member"]})]})]})]})})};var Z="AlertDialog",[ms]=ze(Z,[Q]),f=Q(),ee=s=>{const{__scopeAlertDialog:a,...t}
11=s,r=f(a);return e.jsx(Ie,{...r,...t,modal:!0})};ee.displayName=Z;var us="AlertDialogTrigger",xs=i.forwardRef((s,a)=>{const{__scopeAlertDialog:t,...r}=s,l=f(t);return e.jsx(He,{...l,...r,ref:a})});xs.displayName=us;var ps="AlertDialogPortal",se=s=>{const{__scopeAlertDialog:a,...t}=s,r=f(a);return e.jsx(qe,{...r,...t})};se.displayName=ps;var hs="AlertDialogOverlay",ae=i.forwardRef((s,a)=>{const{__scopeAlertDialog:t,...r}=s,l=f(t);return e.jsx(Ue,{...l,...r,ref:a})});ae.displayName=hs;var N="AlertDialogContent",[gs,fs]=ms(N),js=Ke("AlertDialogContent"),te=i.forwardRef((s,a)=>{const{__scopeAlertDialog:t,children:r,...l}=s,m=f(t),c=i.useRef(null),d=U(a,c),x=i.useRef(null);return e.jsx($e,{contentName:N,titleName:re,docsSlug:"alert-dialog",children:e.jsx(gs,{scope:t,cancelRef:x,children:e.jsxs(Ve,{role:"alertdialog",...m,...l,ref:d,onOpenAutoFocus:Be(l.onOpenAutoFocus,n=>{var u;n.preventDefault(),(u=x.current)==null||u.focus({preventScroll:!0})}),onPointerDownOutside:n=>n.preventDefault(),onInteractOutside:n=>n.preventDefault(),children:[e.jsx(js,{children:r}),e.jsx(vs,{contentRef:c})]})})})});te.displayName=N;var re="AlertDialogTitle",ne=i.forwardRef((s,a)=>{const{__scopeAlertDialog:t,...r}=s,l=f(t);return e.jsx(Ge,{...l,...r,ref:a})});ne.displayName=re;var le="AlertDialogDescription",oe=i.forwardRef((s,a)=>{const{__scopeAlertDialog:t,...r}=s,l=f(t);return e.jsx(Qe,{...l,...r,ref:a})});oe.displayName=le;var bs="AlertDialogAction",ie=i.forwardRef((s,a)=>{const{__scopeAlertDialog:t,...r}=s,l=f(t);return e.jsx(H,{...l,...r,ref:a})});ie.displayName=bs;var ce="AlertDialogCancel",de=i.forwardRef((s,a)=>{const{__scopeAlertDialog:t,...r}=s,{cancelRef:l}=fs(ce,t),m=f(t),c=U(a,l);return e.jsx(H,{...m,...r,ref:c})});de.displayName=ce;var vs=({contentRef:s})=>{const a=`\`${N}\` requires a description for the component to be accessible for screen reader users. 12 13You can add a description to the \`${N}\` by passing a \`${le}\` component as a child, which also benefits sighted users by adding visible context to the dialog. 14 15Alternatively, you can use your own component as a description by assigning it an \`id\` and passing the same value to the \`aria-describedby\` prop in \`${N}\`. If the description is confusing or duplicative for sighted users, you can use the \`@radix-ui/react-visually-hidden\` primitive as a wrapper around your description component. 16 17For more information, see https://radix-ui.com/primitives/docs/components/alert-dialog`;return i.useEffect(()=>{var r;document.getElementById((r=s.current)==null?void 0:r.getAttribute("aria-describedby"))||console.warn(a)},[a,s]),null},ys=ee,Ns=se,me=ae,ue=te,xe=ie,pe=de,he=ne,ge=oe;const fe=ys,_s=Ns,je=i.forwardRef(({className:s,...a},t)=>e.jsx(me,{className:j("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...a,ref:t}));je.displayName=me.displayName;const P=i.forwardRef(({className:s,...a},t)=>e.jsxs(_s,{children:[e.jsx(je,{}),e.jsx(ue,{ref:t,className:j("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",s),...a}
17)]}));P.displayName=ue.displayName;const F=({className:s,...a})=>e.jsx("div",{className:j("flex flex-col space-y-2 text-center sm:text-left",s),...a});F.displayName="AlertDialogHeader";const M=({className:s,...a})=>e.jsx("div",{className:j("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...a});M.displayName="AlertDialogFooter";const O=i.forwardRef(({className:s,...a},t)=>e.jsx(he,{ref:t,className:j("text-lg font-semibold",s),...a}));O.displayName=he.displayName;const T=i.forwardRef(({className:s,...a},t)=>e.jsx(ge,{ref:t,className:j("text-sm text-muted-foreground",s),...a}));T.displayName=ge.displayName;const L=i.forwardRef(({className:s,...a},t)=>e.jsx(xe,{ref:t,className:j(J(),s),...a}));L.displayName=xe.displayName;const I=i.forwardRef(({className:s,...a},t)=>e.jsx(pe,{ref:t,className:j(J({variant:"outline"}),"mt-2 sm:mt-0",s),...a}));I.displayName=pe.displayName;const z={admin:"bg-violet-100 text-violet-700 dark:bg-violet-900/30 dark:text-violet-400",client:"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",staff:"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400"};function be({member:s,canRemove:a,onRemove:t}){return e.jsxs("div",{className:"flex items-center justify-between gap-3 py-2.5 px-3 rounded-lg hover:bg-muted/40 transition-colors",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("span",{className:"font-medium text-sm text-foreground",children:[s.first_name," ",s.last_name]}),e.jsx(es,{className:`rounded-full px-2 py-0.5 h-auto text-[10px] font-medium border-0 capitalize ${z[s.role]||z.staff}`,children:s.role})]}),e.jsxs("div",{className:"flex items-center gap-4 text-xs text-muted-foreground mt-0.5",children:[s.email&&e.jsxs("span",{className:"flex items-center gap-1 truncate",children:[e.jsx(ss,{className:"h-3 w-3 shrink-0"}),s.email]}),s.cell_number&&e.jsxs("span",{className:"flex items-center gap-1 shrink-0",children:[e.jsx(as,{className:"h-3 w-3"}),s.cell_number]})]})]}),a&&e.jsx(_,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive shrink-0",onClick:t,children:e.jsx(ts,{className:"h-3.5 w-3.5"})})]})}function ws(){const{impersonate:s,membership:a}=w(),{data:t,isLoading:r}=ls(),l=Y(),[m,c]=i.useState(!1),[d,x]=i.useState(null),[n,u]=i.useState(""),[b,h]=i.useState(new Set),[R,A]=i.useState(null),ve=o=>{h(p=>{const g=new Set(p);return g.has(o)?g.delete(o):g.add(o),g})},ye=async o=>{A(o);try{await s(o)}catch{S.error("Failed to switch company")}finally{A(null)}},Ne=async()=>{d&&(await l.mutateAsync(d.id),x(null))},D=(t||[]).filter(o=>o.company_name.toLowerCase().includes(n.toLowerCase())||o.members.some(p=>p.first_name.toLowerCase().includes(n.toLowerCase())||p.last_name.toLowerCase().includes(n.toLowerCase())||p.email.toLowerCase().includes(n.toLowerCase())));return r?e.jsxs("div",{className:"space-y-4 animate-pulse",children:[e.jsx("div",{className:"h-10 bg-muted rounded-lg w-1/3"}),[...Array(3)].map((o,p)=>e.jsx("div",{className:"h-24 bg-muted rounded-lg"},p))]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-xl font-bold font-display sm:text-2xl flex items-center gap-2",children:[e.jsx(Je,{className:"h-5 w-5 text-primary"}),"Companies"]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[D.length," ",D.length===1?"company":"companies"," ·"," ",D.reduce((o,p)=>o+p.members.length,0)," members"]})]}),e.jsxs(_,{size:"sm",className:"gap-1",onClick:()=>c(!0),children:[e.jsx(W,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Add Member"})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(We,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(y,{placeholder:"Search companies or members...",value:n,onChange:o=>u(o.target.value),className:"pl-9"})]}),e.jsx("div",{className:"space-y-2",children:D.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[e.jsx("div",{className:"p-4 rounded-full bg-muted mb-4",children:e.jsx($,{className:"h-8 w-8 text-muted-foreground"})}),e.jsx("h3",{className:"text-lg font-semibold mb-1",children:n?"No matching companies":"No companies yet"}),e.jsx("p",{className:"text-sm text-muted-foreground max-w-sm",children:n?"Try a different search":"Add a member to create the first company."})]}):D.map(o=>{const p=b.has(o.company_name);return e.jsxs("div",{className:"rounded-xl border border-border bg-card overflow-hidden",children:[e.jsxs("button",{onClick:()=>ve(o.company_name),className:"w-full flex items-center gap-3 p-4 text-left hover:bg-muted/40 transition-colors",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10 shrink-0",children:e.jsx($,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-semibold text-sm capitalize truncate",children:o.company_name.replace(/_/g," ")}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[o.members.length," ",o.members.length===1?"member":"members"]})]}),e.jsxs(_,{variant:"outline",size:"sm",className:"gap-1.5 shrink-0 text-xs",onClick:g=>{g.stopPropagation(),ye(o.company_name)},disabled:R!==null,children:[R===o.company_name?e.jsx(k,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(rs,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:"View as"})]}),p?e.jsx(Ye,{className:"h-4 w-4 text-muted-foreground shrink-0"}):e.jsx(Xe,{className:"h-4 w-4 text-muted-foreground shrink-0"})]}),p&&e.jsx("div",{className:"border-t border-border px-3 pb-2 pt-1 space-y-0.5",children:o.members.map(g=>e.jsx(be,{member:g,canRemove:g.email!==(a==null?void 0:a.email),onRemove:()=>x(g)},g.id))})]},o.company_name)})}),e.jsx(X,{open:m,onOpenChange:c}),e.jsx(fe,{open:!!d,onOpenChange:o=>!o&&x(null),children:e.jsxs(P,{children:[e.jsxs(F,{children:[e.jsx(O,{children:"Remove team member?"}),e.jsxs(T,{children:["This will revoke access for"," ",e.jsxs("span",{className:"font-medium text-foreground",children:[d==null?void 0:d.first_name," ",d==null?void 0:d.last_name]})," ","(",d==null?void 0:d.email,")."]})]}),e.jsxs(M,{children:[e.jsx(I,{children:"Cancel"}),e.jsxs(L,{onClick:Ne,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:l.isPending,children:[l.isPending&&e.jsx(k,{className:"h-4 w-4 mr-2 animate-spin"}),"Remove"]})]})]})})]})}function As(){const{membership:s}=w(),{data:a,isLoading:t}=os(),r=Y(),[l,m]=i.useState(!1),[c,d]=i.useState(null),x=(s==null?void 0:s.role)==="client",n=async()=>{c&&(await r.mutateAsync(c.id),d(null))};return t?e.jsxs("div",{className:"space-y-4 animate-pulse",children:[e.jsx("div",{className:"h-10 bg-muted rounded-lg w-1/3"}),[...Array(3)].map((u,b)=>e.jsx("div",{className:"h-20 bg-muted rounded-lg"},b))]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold font-display sm:text-2xl",children:"Team"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[(a==null?void 0:a.length)||0," ",(a==null?void 0:a.length)===1?"member":"members"]})]}),x&&e.jsxs(_,{size:"sm",className:"gap-1",onClick:()=>m(!0),children:[e.jsx(W,{className:"h-4 w-4"}),"Add Member"]})]}),e.jsx("div",{className:"space-y-2",children:a!=null&&a.length?e.jsx("div",{className:"rounded-xl border border-border bg-card px-3 py-2 space-y-0.5",children:a.map(u=>e.jsx(be,{member:u,canRemove:x&&u.email!==(s==null?void 0:s.email),onRemove:()=>d(u)},u.id))}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[e.jsx("div",{className:"p-4 rounded-full bg-muted mb-4",children:e.jsx(Ze,{className:"h-8 w-8 text-muted-foreground"})}),e.jsx("h3",{className:"text-lg font-semibold mb-1",children:"No team members"}),e.jsx("p",{className:"text-sm text-muted-foreground max-w-sm",children:"Add your first team member to get started."})]})}),x&&e.jsx(X,{open:l,onOpenChange:m}),e.jsx(fe,{open:!!c,onOpenChange:u=>!u&&d(null),children:e.jsxs(P,{children:[e.jsxs(F,{children:[e.jsx(O,{children:"Remove team member?"}),e.jsxs(T,{children:["This will revoke access for"," ",e.jsxs("span",{className:"font-medium text-foreground",children:[c==null?void 0:c.first_name," ",c==null?void 0:c.last_name]})," ","(",c==null?void 0:c.email,")."]})]}),e.jsxs(M,{children:[e.jsx(I,{children:"Cancel"}),e.jsxs(L,{onClick:n,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:r.isPending,children:[r.isPending&&e.jsx(k,{className:"h-4 w-4 mr-2 animate-spin"}),"Remove"]})]})]})})]})}const Cs=()=>{const{membership:s}=w(),a=(s==null?void 0:s.role)==="admin";return e.jsx("div",{className:"px-4 py-4 space-y-4 sm:container sm:py-6 sm:space-y-5",children:a?e.jsx(ws,{}):e.jsx(As,{})})};export{Cs 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.