PageSourceSearch

https://bizzbox.ai/assets/CompanyTools-D6DZudNl.js

js bizzbox.ai collected 2026-10-05 11:51:19 UTC 4,979 bytes, 1 lines download raw bytes

1import{r as e,g as t,j as a}from"./vendor-react-CCcYlSr6.js";import{u as o,s,W as i,h as r,C as n,t as l,k as d,p as c,c as m,L as p,E as y}from"./index-BAjqQvK2.js";import{S as u}from"./switch-BSDwOapm.js";import{N as h}from"./Navigation-CXenQgvX.js";import"./vendor-query-BN8P0Aoi.js";import"./vendor-supabase-BVFpzqvp.js";import"./ThemeSwitcher-DDKbOC19.js";import"./usePortalTheme-ktf-7eDS.js";import"./colorUtils-BHeCG2RN.js";const x=()=>{const[x,f]=e.useState([]),[b,j]=e.useState(!1),[_,v]=e.useState(!1),[w,g]=e.useState(!1),[N,k]=e.useState(null),{toast:q}=o(),E=t();e.useEffect(()=>{S()},[]),e.useEffect(()=>{const e=()=>{S()};return window.addEventListener("company-tools-updated",e),()=>window.removeEventListener("company-tools-updated",e)},[]);const S=async()=>{j(!0);try{const{data:{user:e}}=await s.auth.getUser();if(!e)return void E("/auth");const{data:t,error:a}=await s.from("company_users").select("company_id").eq("user_id",e.id).maybeSingle();if(a)throw a;if(!t)return q({title:"No Company Found",description:"Please complete company onboarding first",variant:"destructive"}),void E("/company/onboarding");k(t.company_id);const{data:o}=await s.from("user_roles").select("role").eq("user_id",e.id).eq("company_id",t.company_id).single();g("company_admin"===o?.role);const{data:i,error:r}=await s.from("available_tools").select("*").eq("is_active",!0).order("tool_name");if(r)throw r;const{data:n,error:l}=await s.from("company_tools").select("tool_key, enabled").eq("company_id",t.company_id);if(l)throw l;const d=(i||[]).map(e=>({...e,enabled:n?.find(t=>t.tool_key===e.tool_key)?.enabled||!1}));f(d)}catch(e){q({title:"Error",description:"Failed to load tools",variant:"destructive"})}finally{j(!1)}},T=x.reduce((e,t)=>{const a=t.category||"Other";return e[a]||(e[a]=[]),e[a].push(t),e},{});return a.jsxs(a.Fragment,{children:[a.jsx(h,{}),a.jsxs("div",{className:"container mx-auto p-6 max-w-6xl",children:[a.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[a.jsx(i,{className:"h-8 w-8 text-primary"}),a.jsx("h1",{className:"text-3xl font-bold",children:"Company Tools"})]}),a.jsx("div",{className:"mb-6",children:a.jsx("p",{className:"text-muted-foreground",children:w?"Manage which tools are enabled for your company. Toggle switches to enable or disable tools.":"View the tools available for your company. Contact your company administrator to request changes."})}),b?a.jsx("div",{className:"text-center py-20",children:a.jsx(r,{className:"animate-spin h-8 w-8 mx-auto text-primary"})}):a.jsxs("div",{className:"space-y-6",children:[Object.entries(T).map(([e,t])=>a.jsxs(n,{children:[a.jsxs(l,{children:[a.jsx(d,{children:e}),a.jsxs(c,{children:[t.length," tool",1!==t.length?"s":""," in this category"]})]}),a.jsx(m,{children:a.jsx("div",{className:"grid md:grid-cols-2 gap-4",children:t.map(e=>a.jsx("div",{className:"p-4 border rounded-lg",children:a.jsxs("div",{className:"flex items-start justify-between mb-2",children:[a.jsxs("div",{className:"flex-1",children:[a.jsx(p,{htmlFor:`tool-${e.tool_key}`,className:"text-base font-medium cursor-pointer",children:e.tool_name}),a.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:e.description})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[w&&a.jsx(u,{id:`tool-${e.tool_key}`,checked:e.enabled,onCheckedChange:t=>(async(e,t)=>{if(N&&w){v(!0);try{const{data:o}=await s.from("company_tools").select("id").eq("company_id",N).eq("tool_key",e).maybeSingle();if(o){const{error:a}=await s.from("company_tools").update({enabled:t}).eq("company_id",N).eq("tool_key",e);if(a)throw a}else{const{error:a}=await s.from("company_tools").insert({company_id:N,tool_key:e,enabled:t});if(a)throw a}if(f(x.map(a=>a.tool_key===e?{...a,enabled:t}:a)),t)try{const{data:{user:t}}=await s.auth.getUser();await s.functions.invoke("notify-tool-enabled",{body:{company_id:N,tool_key:e,enabled_by_user_id:t?.id}});const{data:a}=await s.from("company_users").select("user_id").eq("company_id",N);q({title:"Tool Enabled!",description:`Welcome emails sent to ${a?.length||0} team members`})}catch(a){q({title:"Tool Enabled",description:"Tool enabled successfully (email notifications may be delayed)"})}else q({title:"Success",description:"Tool disabled successfully"});window.dispatchEvent(new CustomEvent("company-tools-updated",{detail:{companyId:N}}))}catch(o){q({title:"Error",description:"Failed to update tool",variant:"destructive"})}finally{v(!1)}}})(e.tool_key,t),disabled:_}),!w&&a.jsx(y,{variant:e.enabled?"default":"secondary",children:e.enabled?"Enabled":"Disabled"})]})]})},e.id))})})]},e)),0===x.length&&!b&&a.jsx(n,{children:a.jsxs(m,{className:"text-center py-20",children:[a.jsx(i,{className:"h-16 w-16 mx-auto mb-4 text-muted-foreground"}),a.jsx("h3",{className:"text-xl font-semibold mb-2",children:"No Tools Available"}),a.jsx("p",{className:"text-muted-foreground",children:"There are no tools available in the system yet."})]})})]})]})]})};export{x 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.