PageSourceSearch

https://dashboard.voo.chat/assets/departments-OFqH3hKB.js

js voo.chat collected 2026-10-06 16:16:39 UTC 9,558 bytes, 1 lines download raw bytes

1import{w as re,a1 as z,a2 as Q,aR as A,a3 as Y,af as ne,aS as K,a9 as ie,ac as le,T as oe,c as ce,r,t as c,j as e}from"./index-zHIJQHEM.js";import{l as de}from"./firebase-dashboard-DOHxQdyQ.js";import{c as O,C as T}from"./card-CDbECwhX.js";import{B as m}from"./button-CF3fTBb6.js";import{I as q}from"./input-D_VHSRb_.js";import{L as y}from"./label-CyMN9ODR.js";import{T as me}from"./textarea-iLhn4vA7.js";import{B as H}from"./badge-C9vBNQPF.js";import{R as pe,a as V}from"./radio-group-Cg94JQBV.js";import{T as ue,a as he,b as U,c as v,d as xe,e as b}from"./table-pO-1fu8k.js";import{D as fe,a as ge,b as je,c as ye,d as ve,e as be}from"./dialog-CSP43bAr.js";import{A as Ne,a as De,b as we,c as Ce,d as Se,e as Te,f as Pe,g as Ae,h as Ee}from"./alert-dialog-BNfNvv6W.js";import{S as ke,a as Ie,b as Re,c as Le,d as Fe}from"./select-m4eyydyg.js";import{P as Be,a as Me,b as Oe}from"./popover-DS7e2n5q.js";import{C as qe}from"./chevrons-up-down-BGT7KHHb.js";import{S as He}from"./search-CzBP5-_F.js";import{P as Ve,T as Ue}from"./trash-2-Ce_t0__h.js";import{L as P}from"./loader-circle-BXo1LIey.js";import{P as _e}from"./pencil-BzSiKz63.js";import"./firebase-members-BiqOY63n.js";import"./index-CfYrpjHA.js";import"./index-CCeiIsGX.js";import"./index-DmiWIjhS.js";import"./Combination-CvBMPJcf.js";import"./index-DpoNoRtV.js";import"./index-DKSXiZle.js";import"./circle-QnxToPzd.js";import"./index-D3zZH8ng.js";import"./index-DqkWgb9C.js";import"./index-D0Epn_t3.js";import"./chevron-down-B8s9jLBU.js";import"./check-CCOE5l7L.js";const Ge=[["path",{d:"M10 12h4",key:"a56b0p"}],["path",{d:"M10 8h4",key:"1sr2af"}],["path",{d:"M14 21v-3a2 2 0 0 0-4 0v3",key:"1rgiei"}],["path",{d:"M6 10H4a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-2",key:"secmi2"}],["path",{d:"M6 21V5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v16",key:"16ra0t"}]],ze=re("building-2",Ge);async function Qe(a){if(!a)return[];const l=z(A(),Q("property","==",a));return(await Y(l)).docs.map(o=>({id:o.id,...o.data()}))}async function Ye(a){if(!a)return[];const l=z(A(),Q("userId","==",a));return(await Y(l)).docs.map(o=>({id:o.id,...o.data()})).filter(o=>!o.property)}async function Ke(a){return(await le(A(),{...a,createdAt:oe()})).id}async function Je(a,l){await ie(K(a),l)}async function We(a){await ne(K(a))}const _="voochat-departments-property-id",G=a=>({name:"",description:"",status:"Enable",property:a});function At(){const a=ce(t=>t.user),[l,o]=r.useState([]),[n,N]=r.useState(""),[J,E]=r.useState(!1),[k,f]=r.useState([]),[u,g]=r.useState([]),[W,I]=r.useState(!1),[D,X]=r.useState(""),[Z,h]=r.useState(!1),[w,R]=r.useState(!1),[L,F]=r.useState(null),[j,C]=r.useState(null),[i,p]=r.useState(G("")),$=l.find(t=>t.id===n),S=r.useCallback(async()=>{if(!n||!a?.id){f([]),g([]);return}I(!0);try{const[t,s]=await Promise.all([Qe(n),Ye(a.id)]);f(t),g(s)}catch{c.error("Failed to load departments"),f([]),g([])}finally{I(!1)}},[n,a?.id]);r.useEffect(()=>{a&&de(a).then(t=>{if(o(t),t.length===0)return;const s=localStorage.getItem(_),d=t.find(ae=>ae.id===s);N(d?.id??t[0].id)})},[a]),r.useEffect(()=>{n&&localStorage.setItem(_,n)},[n]),r.useEffect(()=>{S()},[S]);const x=r.useMemo(()=>{const t=new Map;for(const s of[...k,...u])t.set(s.id,s);return Array.from(t.values())},[k,u]),B=r.useMemo(()=>{const t=D.trim().toLowerCase();return t?x.filter(s=>[s.name,s.description,s.status].filter(Boolean).join(" ").toLowerCase().includes(t)):x},[x,D]),M=()=>{C(null),p(G(n)),h(!0)},ee=t=>{C(t),p({name:t.name??"",description:t.description??"",status:t.status==="disabled"?"disabled":"Enable",property:t.property||n}),h(!0)},te=async()=>{if(!i.name.trim()){c.error("Name is required");return}if(!i.description.trim()){c.error("Description is required");return}if(!i.property){c.error("Property is required");return}if(a?.id){R(!0);try{const t={name:i.name.trim(),description:i.description.trim(),status:i.status,property:i.property};j?(await Je(j.id,t),c.success("Department updated")):(await Ke({...t,companyId:a.c
1ompanyId,userId:a.id}),c.success("Department added")),h(!1),C(null),i.property!==n?N(i.property):await S()}catch{c.error(j?"Failed to update department":"Failed to create department")}finally{R(!1)}}},se=async t=>{F(t);try{await We(t),f(s=>s.filter(d=>d.id!==t)),g(s=>s.filter(d=>d.id!==t)),c.success("Department deleted")}catch{c.error("Failed to delete department")}finally{F(null)}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 justify-between",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(Be,{open:J,onOpenChange:E,children:[e.jsx(Me,{asChild:!0,children:e.jsxs(m,{variant:"outline",className:"min-w-[180px] justify-between",children:[e.jsx("span",{className:"truncate",children:$?.name??"Select property"}),e.jsx(qe,{className:"h-4 w-4 opacity-50 shrink-0"})]})}),e.jsx(Oe,{className:"w-64 p-1",align:"start",children:l.map(t=>e.jsx("button",{type:"button",className:O("w-full text-left px-3 py-2 rounded-md text-sm hover:bg-accent",t.id===n&&"bg-accent"),onClick:()=>{N(t.id),E(!1)},children:t.name},t.id))})]}),e.jsxs("div",{className:"relative",children:[e.jsx(He,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(q,{className:"pl-9 w-56",placeholder:"Search departments…",value:D,onChange:t=>X(t.target.value)})]})]}),e.jsxs(m,{onClick:M,disabled:!n,children:[e.jsx(Ve,{className:"h-4 w-4 mr-2"}),"Add department"]})]}),u.length>0&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[u.length," legacy department",u.length===1?"":"s"," without a property are shown here — edit to assign them to a property."]}),W?e.jsxs(T,{className:"p-10 flex items-center justify-center text-muted-foreground gap-2",children:[e.jsx(P,{className:"h-5 w-5 animate-spin"}),"Loading departments…"]}):B.length===0?e.jsxs(T,{className:"p-10 text-center",children:[e.jsx(ze,{className:"h-10 w-10 mx-auto text-muted-foreground/40 mb-3"}),e.jsx("p",{className:"text-muted-foreground",children:x.length===0?"No departments yet for this property.":"No departments match your search."}),x.length===0&&e.jsx(m,{className:"mt-3",onClick:M,disabled:!n,children:"Create your first department"})]}):e.jsx(T,{className:"rounded-lg overflow-hidden",children:e.jsxs(ue,{children:[e.jsx(he,{children:e.jsxs(U,{children:[e.jsx(v,{children:"Name"}),e.jsx(v,{children:"Description"}),e.jsx(v,{children:"Status"}),e.jsx(v,{className:"w-28 text-right",children:"Actions"})]})}),e.jsx(xe,{children:B.map(t=>{const s=t.status==="Enable",d=!t.property;return e.jsxs(U,{children:[e.jsx(b,{className:"font-medium",children:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[t.name,d&&e.jsx(H,{variant:"outline",className:"font-normal text-[10px]",children:"No property"})]})}),e.jsx(b,{className:"max-w-[360px] truncate text-muted-foreground",children:t.description||"—"}),e.jsx(b,{children:e.jsx(H,{variant:s?"default":"secondary",className:O("font-normal",s&&"bg-emerald-600 hover:bg-emerald-600"),children:s?"Enabled":"Disabled"})}),e.jsx(b,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx(m,{variant:"ghost",size:"icon",onClick:()=>ee(t),children:e.jsx(_e,{className:"h-4 w-4"})}),e.jsxs(Ne,{children:[e.jsx(De,{asChild:!0,children:e.jsx(m,{variant:"ghost",size:"icon",className:"text-destructive",disabled:L===t.id,children:L===t.id?e.jsx(P,{className:"h-4 w-4 animate-spin"}):e.jsx(Ue,{className:"h-4 w-4"})})}),e.jsxs(we,{children:[e.jsxs(Ce,{children:[e.jsx(Se,{children:"Delete department?"}),e.jsxs(Te,{children:['"',t.name,'" will be permanently removed.']})]}),e.jsxs(Pe,{children:[e.jsx(Ae,{children:"Cancel"}),e.jsx(Ee,{className:"bg-destructive text-destructive-foreground",onClick:()=>{se(t.id)},children:"Delete"})]})]})]})]})})]},t.id)})})]})}),e.jsx(fe,{open:Z,onOpenChange:h,children:e.jsxs(ge,{className:"max-w-md",children:[e.jsxs(je,{children:[e.jsx(ye,{children:j?"Edit department":"Add department"}),e.jsx(ve,{children:"Departments are scoped to a property, like Triggers."})]}),e.jsxs("div",{className:"grid gap-4 py-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(y,{children:"Property"}),e.jsxs(ke,{value:i.property,onValueChange:t=>p(s=>({...s,property:t})),children:[e.jsx(Ie,{children:e.jsx(Re,{placeholder:"Select property"})}),e.jsx(Le,{children:l.map(t=>e.jsx(Fe,{value:t.id,children:t.name},t.id))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(y,{children:"Name"}),e.jsx(q,{value:i.name,onChange:t=>p(s=>({...s,name:t.target.value})),placeholder:"Enter name"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Status"}),e.jsxs(pe,{value:i.status,onValueChange:t=>p(s=>({...s,status:t})),className:"flex gap-4",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[e.jsx(V,{value:"Enable",id:"dept-enable"}),"Enable"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[e.jsx(V,{value:"disabled",id:"dept-disabled"}),"Disabled"]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(y,{children:"Description"}),e.jsx(me,{value:i.description,onChange:t=>p(s=>({...s,description:t.target.value})),placeholder:"Description",className:"min-h-24"})]})]}),e.jsxs(be,{children:[e.jsx(m,{variant:"outline",onClick:()=>h(!1),disabled:w,children:"Cancel"}),e.jsxs(m,{onClick:()=>{te()},disabled:w,children:[w&&e.jsx(P,{className:"h-4 w-4 mr-2 animate-spin"}),"Submit"]})]})]})})]})}export{At as component};

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.