1import{u as L,f as i,j as e,b_ as P,I as d}from"./index-DGRgO-qd.js";import{r as a,h as p}from"./vendor-CcMWqYlm.js";import{u as T,D as I}from"./DispatchHeader-Cso82vzO.js";import"./leaflet-BYsLm_qT.js";import"./useAuth-CLjCP_1I.js";function K(){const s=T(),[l,z]=a.useState(null),[h,E]=a.useState(null),[M,c]=a.useState(0),[y,g]=a.useState(""),[x,f]=a.useState(""),[j,v]=a.useState(""),[b,S]=a.useState(""),[_,C]=a.useState(!1),[k,N]=a.useState(!1),[A,m]=a.useState(null);if(L({title:"Manage contractors",robots:"noindex,follow"}),a.useEffect(()=>{var n;if(s.loading||!((n=s.contractor)!=null&&n.is_super_admin)||!i)return;let t=!0;return i.from("contractors").select("id,email,display_name,company,phone,is_super_admin,status,notes").order("created_at",{ascending:!1}).then(({data:r,error:o})=>{if(t){if(o){E(o.message);return}z(r??[])}}),()=>{t=!1}},[s.loading,s.contractor,M]),s.loading)return e.jsx("p",{style:{padding:"2rem"},children:"Loadingâ¦"});if(!s.user)return e.jsx(p,{to:P(),replace:!0});if(!s.contractor)return e.jsx(p,{to:"/dispatch",replace:!0});if(!s.contractor.is_super_admin)return e.jsx(p,{to:"/dispatch",replace:!0});async function R(t){t.preventDefault(),m(null);const n=y.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(n)){m("Enter a valid email address.");return}if(!i)return;N(!0);const{error:r}=await i.from("contractors").insert({email:n,display_name:x.trim()||null,company:j.trim()||null,phone:b.trim()||null,is_super_admin:_,status:"active"});if(N(!1),r){m(r.message);return}g(""),f(""),v(""),S(""),C(!1),c(o=>o+1)}async function u(t,n){i&&(await i.from("contractors").update({status:n}).eq("id",t),c(r=>r+1))}async function D(t,n){i&&(await i.from("contractors").update({is_super_admin:!n}).eq("id",t),c(r=>r+1))}return e.jsx("section",{className:"section",children:e.jsxs("div",{className:"container",children:[e.jsx(I,{contractor:s.contractor}),e.jsx("h1",{style:{marginTop:0},children:"Manage contractors"}),e.jsxs("p",{style:{color:"var(--jse-text-muted)"},children:["Anyone in this list with status ",e.jsx("strong",{children:"active"})," can sign in to /dispatch and see incoming haul requests. Pause to temporarily revoke access; remove to revoke permanently."]}),e.jsx("h2",{style:{marginTop:"2rem",fontSize:"1.1rem"},children:"Add a contractor"}),e.jsxs("form",{className:"form",onSubmit:R,style:{display:"grid",gap:"0.75rem",maxWidth:540},noValidate:!0,children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"add-email",children:"Email (required)"}),e.jsx(d,{id:"add-email",type:"email",inputMode:"email",value:y,onChange:t=>g(t.target.value),placeholder:"[email protected]"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"add-name",children:"Display name"}),e.jsx(d,{id:"add-name",value:x,onChange:t=>f(t.target.value),placeholder:"Jane Hauler"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"add-company",children:"Company"}),e.jsx(d,{id:"add-company",value:j,onChange:t=>v(t.target.value),placeholder:"Hauler & Sons"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"add-phone",children:"Phone"}),e.jsx(d,{id:"add-phone",type:"tel",value:b,onChange:t=>S(t.target.value),placeholder:"303-555-0100"})]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",fontSize:"0.9rem"},children:[e.jsx("input",{type:"checkbox",checked:_,onChange:t=>C(t.target.checked)}),"Make this contractor a super-admin (can manage other contractors)"]}),A&&e.jsx("div",{className:"field-error",children:A}),e.jsx("div",{children:e.jsx("button",{type:"submit",className:"btn btn-primary",disabled:k,children:k?"Addingâ¦":"Add contractor"})})]}),e.jsx("h2",{style:{marginTop:"2.5rem",fontSize:"1.1rem"},children:"Current contractors"}),h&&e.jsxs("p",{style:{color:"var(--jse-danger, #e25d5d)"},children:["Couldn't load contractors: ",h]}),l===null?e.jsx("p",{style:{color:"var(--jse-text-muted)"},children:"Loadingâ¦"}):l.length===0?e.jsx("p",{style:{color:"var(--jse-text-muted)"},children:"No contractors yet."}):e.jsx("div",{style:{display:"grid",gap:"0.5rem",marginTop:"1rem"},children:l.map(t=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr auto",gap:"0.75rem",alignItems:"center",padding:"0.75rem 1rem",background:"var(--jse-bg-elev, #f8faf4)",border:"1px solid var(--jse-border, #e6ebe2)",borderRadius:8,opacity:t.status==="active"?1:.55},children:[e.jsxs("div",{children:[e.jsxs("div",{style:{fontWeight:600},children:[t.display_name??t.email,t.is_super_admin&&e.jsx("span",{style:{marginLeft:6,fontSize:"0.7rem",padding:"2px 6px",borderRadius:4,background:"var(--jse-green, #b6df4a)",color:"#0c0e10",fontWeight:700},children:"ADMIN"})]}),e.jsxs("div",{style:{fontSize:"0.85rem",color:"var(--jse-text-muted)"},children:[t.email,t.company?` · ${t.company}`:"",t.phone?` · ${t.phone}`:""," · ","status: ",e.jsx("strong",{children:t.status})]})]}),e.jsxs("div",{style:{display:"flex",gap:"0.4rem",flexWrap:"wrap",justifyContent:"flex-end"},children:[t.status==="active"?e.jsx("button",{type:"button",onClick:()=>u(t.id,"paused"),className:"btn btn-secondary",style:{padding:"0.3rem 0.6rem",fontSize:"0.8rem"},children:"Pause"}):e.jsx("button",{type:"button",onClick:()=>u(t.id,"active"),className:"btn btn-secondary",style:{padding:"0.3rem 0.6rem",fontSize:"0.8rem"},children:"Reactivate"}),e.jsx("button",{type:"button",onClick:()=>D(t.id,t.is_super_admin),className:"btn btn-secondary",style:{padding:"0.3rem 0.6rem",fontSize:"0.8rem"},children:t.is_super_admin?"Remove admin":"Make admin"}),t.status!=="removed"&&e.jsx("button",{type:"button",onClick:()=>{window.confirm(`Remove ${t.email}? They will lose access to /dispatch immediately.`)&&u(t.id,"removed")},className:"btn btn-secondary",style:{padding:"0.3rem 0.6rem",fontSize:"0.8rem",color:"var(--jse-danger, #e25d5d)"},children:"Remove"})]})]},t.id))})]})})}export{K 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.