PageSourceSearch

https://living-corporate.com/assets/organizations-9vOzBT-x.js

js living-corporate.com collected 2026-10-02 05:00:39 UTC 33,383 bytes, 1 lines download raw bytes

1import{e as ae,u as se,b as te,v as re,r as v,aS as R,f as Q,i as C,j as e,o as T,B as g,m as K,X as ie,l as h,I as j,d as J,E as ne}from"./index-QiiZ-xPT.js";import{h as $}from"./course-builder-access-DQmIWoOG.js";import{N as G}from"./Navigation-r93ZBuy6.js";import{F as H}from"./Footer-3JNsJayo.js";import{L as u}from"./label-BA9Xin3m.js";import{T as oe}from"./textarea-Bd1mcSz8.js";import{D as _,f as le,a as W,b as V,c as X}from"./dialog-D2VXyQJN.js";import{L as Z}from"./lock-NaFetfNF.js";import{C as de}from"./chevron-left-BlU_Pgs7.js";import{B as Y}from"./building-2-Bz-h5bHH.js";import{P as D}from"./plus-BG3Uc6gN.js";import{C as ce}from"./check-KTa2Xihg.js";import{U as me}from"./users-JkJLChox.js";import{G as ee}from"./globe-3tsuvpPT.js";import{P as I}from"./palette-Bun6nNlR.js";import{T as ue}from"./trash-2-D3MslYjV.js";import{E as xe}from"./eye-BVhHQpi4.js";import{S as ge}from"./save-BsB7cS8F.js";import"./checkbox-CrGTwbPu.js";import"./index-DqZlRfV5.js";import"./select-B1P2Vx_w.js";import"./index-BMyKsIJE.js";import"./Combination-TP2Egp2x.js";import"./chevron-down-BWOHa16b.js";import"./dropdown-menu-D4zjGRmc.js";import"./index-Bj3iuRQR.js";import"./chevron-right-f4G5e4zR.js";import"./circle-2nw1jhuN.js";import"./useTranslation-XedzLvcK.js";import"./log-out-CqAuLeet.js";import"./BrandSponsor-DEW6i_On.js";import"./card-DkXabqFf.js";import"./mail-Cr62Xklx.js";import"./twitter-BzZd48jL.js";const pe=[["polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12",key:"o97t9d"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}]],he=ae("inbox",pe);function Ze(){const{user:o,isLoading:E,isAuthenticated:r}=se(),[,l]=te(),c=re(),[d,f]=v.useState(null),[w,N]=v.useState(!1),[F,p]=v.useState(""),A=o?.membershipTier==="admin"||!!o?.isSuperAdmin,s=R(o),m=R(o),{data:x,isLoading:b}=Q({queryKey:["/api/admin/organizations"],queryFn:async()=>{const a=await fetch("/api/admin/organizations",{credentials:"include"});if(!a.ok)throw new Error("Failed to fetch organizations");return a.json()},enabled:r&&A}),z=C({mutationFn:async a=>{const i=await fetch("/api/admin/organizations",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(a)});if(!i.ok)throw new Error("Failed to create organization");return i.json()},onSuccess:()=>{c.invalidateQueries({queryKey:["/api/admin/organizations"]}),N(!1)}}),O=C({mutationFn:async({orgId:a,data:i})=>{const t=await fetch(`/api/admin/organizations/${a}`,{method:"PATCH",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(i)});if(!t.ok)throw new Error("Failed to update organization");return t.json()},onSuccess:(a,i)=>{f(t=>t&&t.id===i.orgId?{...t,...a||{}}:t),c.invalidateQueries({queryKey:["/api/admin/organizations"]})}}),B=C({mutationFn:async({orgId:a,enabled:i})=>{const t=await fetch(`/api/admin/organizations/${a}/learning-access`,{method:"PATCH",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({enabled:i})}),L=await t.json().catch(()=>({}));if(!t.ok)throw new Error(L.message||"Failed to update learning access");return L},onSuccess:(a,i)=>{f(t=>t&&t.id===i.orgId?{...t,learningAccessEnabled:a.learningAccessEnabled}:t),c.invalidateQueries({queryKey:["/api/admin/organizations"]}),h.success(a.learningAccessEnabled?"Learning access enabled":"Learning access disabled")},onError:a=>h.error(a.message)}),y=C({mutationFn:async({orgId:a,enabled:i,agreementAcknowledged:t})=>{const L=await fetch(`/api/admin/organizations/${a}/course-builder-manual-access`,{method:"PATCH",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({enabled:i,...i?{agreementAcknowledged:t}:{}})}),q=await L.json().catch(()=>({}));if(!L.ok)throw new Error(q.message||q.error||"Failed to update manual Course Builder access");return q},onSuccess:(a,i)=>{f(t=>t&&t.id===i.orgId?{...t,courseBuilderManualGrant:a.courseBuilderManualGrant,courseBuilderEnabled:a.courseBuilderEnabled,learningAccessEnabled:a.learningAccessEnabled}:t),c.invalidateQueries({queryKey:["/api/admin/organizations"]}),h.success(a.courseBuilderManualGrant?"Manual Course Builder access granted":"Manual Course Builder access removed")},onError:a=>h.error(a.message)}),P=C({mutationFn:async({orgId:a})=>{const i=await fetch(`/api/admin/organizations/${a}`,{method:"PATCH",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({courseBuilderEnabled:!1})}),t=await i.json().catch(()=>({}));if(!i.ok)throw new Error(t.message||t.error||"Failed to cancel the paid Course Builder add-on");return t},onSuccess:(a,i)=>{f(t=>t&&t.id===i.orgId?{...t,...a||{},courseBuilderEnabled:!1}:t),c.invalidateQueries({queryKey:["/api/admin/organizations"]}),h.success("Paid Course Builder add-on cancellation requested")},onError:a=>h.error(a.message)}),U=C({mutationFn:async({orgId:a,domain:i})=>{const t=await fetch(`/api/admin/organizations/${a}/domains`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({domain:i})});if(!t.ok)throw new Error("Failed to add domain");return t.json()},onSuccess:()=>{c.invalidateQueries({queryKey:["/api/admin/organizations"]}),p("")}}),M=C({mutationFn:async({orgId:a,domainId:i})=>{const t=await fetch(`/api/admin/organizations/${a}/domains/${i}`,{method:"DELETE",credentials:"include"});if(!t.ok)throw new Error("Failed to remove domain");return t.json()},onSuccess:()=>{c.invalidateQueries({queryKey:["/api/admin/organizations"]})}}),{data:S}=Q({queryKey:["/api/admin/course-builder/requests"],queryFn:async()=>{const a=await fetch("/api/admin/course-builder/requests?status=pending",{credentials:"include"});if(!a.ok)throw new Error("Failed to fetch access requests");return a.json()},enabled:r&&A}),n=C({mutationFn:async({id:a,status:i})=>{const t=await fetch(`/api/admin/course-builder/requests/${a}`,{method:"PATCH",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({status:i})});if(!t.ok)throw new Error("Failed to update request");return t.json()},onSuccess:(a,i)=>{c.invalidateQueries({queryKey:["/api/admin/course-builder/requests"]}),c.invalidateQueries({queryKey:["/api/admin/organizations"]}),h.success(i.status==="approved"?"Request approved":"Request dismissed")},onError:()=>h.error("Could not update the request. Please try again.")});return E?e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:e.jsx(T,{className:"w-8 h-8 animate-spin text-primary"})}):A?e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(G,{}),e.jsx("section",{className:"pt-32 pb-8 bg-gradient-to-b from-primary/10 to-background",children:e.jsx("div",{className:"max-w-6xl mx-auto px-6",children:e.jsxs(K.div,{initial:{opacity:0,y:20}
1,animate:{opacity:1,y:0},children:[e.jsxs(g,{variant:"ghost",size:"sm",onClick:()=>l("/admin"),className:"mb-4",children:[e.jsx(de,{size:16,className:"mr-1"}),"Back to Admin"]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"font-display text-3xl font-bold mb-2 flex items-center gap-3",children:[e.jsx(Y,{className:"text-primary"}),"Enterprise Organizations"]}),e.jsxs("p",{className:"text-muted-foreground",children:[x?.length||0," organizations configured"]})]}),e.jsxs(_,{open:w,onOpenChange:N,children:[e.jsx(le,{asChild:!0,children:e.jsxs(g,{className:"gap-2","data-testid":"button-create-org",children:[e.jsx(D,{size:18}),"Create Organization"]})}),e.jsxs(W,{className:"max-w-lg max-h-[80vh] overflow-y-auto",children:[e.jsx(V,{children:e.jsx(X,{className:"text-lg",children:"Create New Organization"})}),e.jsx(fe,{onSubmit:a=>z.mutate(a),isLoading:z.isPending})]})]})]})]})})}),S&&S.length>0&&e.jsx("section",{className:"py-4",children:e.jsx("div",{className:"max-w-6xl mx-auto px-6",children:e.jsxs("div",{className:"rounded-xl border border-amber-300/50 bg-amber-50 dark:bg-amber-950/20 p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3 font-semibold",children:[e.jsx(he,{size:18,className:"text-amber-600"}),"Course Builder access requests",e.jsxs("span",{className:"text-xs font-normal bg-amber-200/60 dark:bg-amber-800/40 px-2 py-0.5 rounded-full",children:[S.length," pending"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"Approving turns on the add-on for the requested org. Dismissing leaves the add-on off."}),e.jsx("div",{className:"space-y-2",children:S.map(a=>e.jsxs("div",{className:"flex items-center justify-between gap-3 bg-card rounded-lg border px-3 py-2","data-testid":`row-access-request-${a.id}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium truncate",children:a.orgName||a.orgSlug||"Unknown org"}),e.jsxs("div",{className:"text-xs text-muted-foreground truncate",children:[a.email||a.userId,a.note?` — "${a.note}"`:""]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs(g,{size:"sm",onClick:()=>n.mutate({id:a.id,status:"approved"}),disabled:n.isPending,"data-testid":`button-approve-request-${a.id}`,children:[e.jsx(ce,{size:14,className:"mr-1"}),"Approve"]}),e.jsxs(g,{size:"sm",variant:"outline",onClick:()=>n.mutate({id:a.id,status:"dismissed"}),disabled:n.isPending,"data-testid":`button-dismiss-request-${a.id}`,children:[e.jsx(ie,{size:14,className:"mr-1"}),"Dismiss"]})]})]},a.id))})]})})}),e.jsx("section",{className:"py-8",children:e.jsx("div",{className:"max-w-6xl mx-auto px-6",children:b?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(T,{className:"w-8 h-8 animate-spin text-primary"})}):x?.length===0?e.jsxs("div",{className:"text-center py-12 bg-card rounded-xl border",children:[e.jsx(Y,{size:48,className:"mx-auto text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"No Organizations Yet"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"Create your first enterprise organization to get started."})]}):e.jsx("div",{className:"grid gap-6 md:grid-cols-2 lg:grid-cols-3",children:x?.map(a=>e.jsxs(K.div,{initial:{opacity:0}
1,animate:{opacity:1},className:"bg-card rounded-xl border p-6 hover:shadow-lg transition-shadow cursor-pointer",onClick:()=>f(a),"data-testid":`org-card-${a.slug}`,children:[e.jsxs("div",{className:"flex items-start gap-4 mb-4",children:[a.logoUrl?e.jsx("img",{src:a.logoUrl,alt:a.name,className:"w-12 h-12 rounded-lg object-contain bg-muted"}):e.jsx("div",{className:"w-12 h-12 rounded-lg flex items-center justify-center text-white font-bold",style:{backgroundColor:a.primaryColor||"#6366f1"},children:a.name.charAt(0)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-semibold truncate",children:a.name}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a.slug})]})]}),e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground mb-4",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(me,{size:14}),a.currentSeats," users"]}),a.pendingInvites>0&&e.jsxs("span",{className:"flex items-center gap-1 text-amber-600 dark:text-amber-400",children:[a.pendingInvites," pending"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ee,{size:14}),a.domains.length," domains"]})]}),e.jsx("div",{className:"flex gap-2",children:[a.primaryColor,a.secondaryColor,a.accentColor].filter(
1Boolean).map((i,t)=>e.jsx("div",{className:"w-6 h-6 rounded-full border",style:{backgroundColor:i||"#ccc"}},t))}),e.jsx("div",{className:"mt-4 pt-4 border-t",children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("span",{className:`text-xs px-2 py-1 rounded-full ${a.isActive?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":"bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400"}`,children:a.isActive?"Active":"Inactive"}),e.jsxs("span",{className:`text-xs px-2 py-1 rounded-full ${a.learningAccessEnabled!==!1?"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400":"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400"}`,"data-testid":`org-learning-access-${a.slug}`,children:["Learning ",a.learningAccessEnabled!==!1?"ON":"OFF"]}),e.jsxs("span",{className:`text-xs px-2 py-1 rounded-full ${a.isActive&&a.learningAccessEnabled!==!1&&$(a)?"bg-violet-100 text-violet-700 dark:bg-violet-900/30 dark:text-violet-400":"bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400"}`,"data-testid":`org-course-builder-access-${a.slug}`,children:["Course Builder"," ",a.isActive&&a.learningAccessEnabled!==!1&&$(a)?"AVAILABLE":"OFF"]})]})})]},a.id))})})}),e.jsx(_,{open:!!d,onOpenChange:a=>!a&&f(null),children:e.jsxs(W,{className:"max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsx(V,{children:e.jsxs(X,{className:"flex items-center gap-2",children:[e.jsx(I,{size:20}),"Edit Organization: ",d?.name]})}),d&&e.jsx(je,{org:d,onUpdate:a=>O.mutate({orgId:d.id,data:a}),onToggleLearningAccess:a=>B.mutate({orgId:d.id,enabled:a}),canToggleLearningAccess:s,onToggleCourseBuilderManualAccess:(a,i)=>y.mutate({orgId:d.id,enabled:a,agreementAcknowledged:i}),onCancelPaidCourseBuilder:()=>{window.confirm("Cancel the paid Course Builder add-on for this organization? This will cancel its billing subscription. Any manual agreement access will remain active.")&&P.mutate({orgId:d.id})},canToggleCourseBuilderManualAccess:m,manualAccessError:y.variables?.orgId===d.id&&y.error instanceof Error?y.error.message:null,onAddDomain:a=>U.mutate({orgId:d.id,domain:a}),onRemoveDomain:a=>M.mutate({orgId:d.id,domainId:a}),isUpdating:O.isPending||B.isPending||y.isPending||P.isPending,newDomain:F,setNewDomain:p},d.id)]})}),e.jsx(H,{})]}):e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(G,{}),e.jsxs("div",{className:"pt-32 pb-16 max-w-lg mx-auto px-6 text-center",children:[e.jsx(Z,{size:48,className:"mx-auto text-muted-foreground mb-4"}),e.jsx("h1",{className:"text-3xl font-bold mb-4",children:"Admin Access Required"}),e.jsx("p",{className:"text-muted-foreground mb-8",children:"This area is restricted to administrators only."}),e.jsx(g,{onClick:()=>l("/admin"),children:"Back to Admin"})]}),e.jsx(H,{})]})}function fe({onSubmit:o,isLoading:E}){const[r,l]=v.useState({name:"",slug:"",logoUrl:"",primaryColor:"#6366f1",secondaryColor:"#4f46e5",accentColor:"#818cf8",domains:"",adminEmails:""}),[c,d]=v.useState(!1),[f,w]=v.useState(!1),[N,F]=v.useState(!1),p=async s=>{if(s){d(!0);try{const m=await fetch("/api/admin/extract-colors",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({imageUrl:s})});if(m.ok){const x=await m.json();l(b=>({...b,primaryColor:x.primary,secondaryColor:x.secondary,accentColor:x.accent})),w(!0)}else{const x=await m.json().catch(()=>({message:"Could not extract colors from this image"}));h.error(x.message||"Could not extract colors from this image")}}catch{h.error("Could not reach the server. Please try again.")}finally{d(!1)}}},k=s=>{l({...r,logoUrl:s}),w(!1)},A=s=>{s.preventDefault();const m=r.domains.split(",").map(b=>b.trim().toLowerCase()).filter(Boolean),x=r.adminEmails.split(",").map(b=>b.trim().toLowerCase()).filter(Boolean);o({...r,domains:m,adminEmails:x})};return e.jsxs("form",{onSubmit:A,className:"space-y-4",children:[e.jsx("div",{className:"bg-primary/5 border border-primary/20 rounded-lg p-3",children:e.jsxs("p",{className:"text-xs text-muted-foreground",children:[e.jsx("strong",{children:"Quick Setup:"})," Enter the company logo URL, name, and email domain. Brand colors will be automatically extracted from the logo."]})}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u,{htmlFor:"logoUrl",className:"text-sm",children:"Company Logo URL *"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{id:"logoUrl",value:r.logoUrl,onChange:s=>k(s.target.value),onBlur:()=>{r.logoUrl&&!f&&!c&&p(r.logoUrl)},placeholder:"https://company.com/logo.png",className:"flex-1","data-testid":"input-org-logo"}),e.jsxs(g,{type:"button",variant:"outline",onClick:()=>p(r.logoUrl),disabled:!r.logoUrl||c,"data-testid":"button-extract-colors",children:[c?e.jsx(T,{size:16,className:"animate-spin"}):e.jsx(I,{size:16}),e.jsx("span",{className:"ml-2",children:"Extract Colors"})]})]}),r.logoUrl&&e.jsxs("div",{className:"mt-2 flex items-center gap-3",children:[e.jsx("img",{src:r.logoUrl,alt:"Logo preview",className:"w-10 h-10 object-contain bg-muted rounded border",onError:s=>s.currentTarget.style.display="none","data-testid":"img-logo-preview"}),f&&e.jsxs("div",{className:"flex items-center gap-2","data-testid":"status-colors-extracted",children:[e.jsx("span",{className:"text-sm text-green-600",children:"Colors extracted:"}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx("div",{className:"w-6 h-6 rounded border",style:{backgroundColor:r.primaryColor},title:"Primary","data-testid":"swatch-primary"}),e.jsx("div",{className:"w-6 h-6 rounded border",style:{backgroundColor:r.secondaryColor},title:"Secondary","data-testid":"swatch-secondary"}),e.jsx("div",{className:"w-6 h-6 rounded border",style:{backgroundColor:r.accentColor},title:"Accent","data-testid":"swatch-accent"})]})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u,{htmlFor:"name",className:"text-sm",children:"Organization Name *"}),e.jsx(j,{id:"name",value:r.name,onChange:s=>l({...r,name:s.target.value,slug:s.target.value.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,"")}),placeholder:"Acme Corporation",required:!0,"data-testid":"input-org-name"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Portal URL: /",r.slug||"company-name"]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u,{htmlFor:"domains",className:"text-sm",children:"Email Domain *"}),e.jsx(j,{id:"domains",value:r.domains,onChange:s=>l({...r,domains:s.target.value}),placeholder:"acme.com",required:!0,"data-testid":"input-org-domains"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Employees signing up with this email domain will automatically join this organization. Use commas to add multiple domains."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u,{htmlFor:"adminEmails",className:"text-sm",children:"Organization Admin Email(s)"}),e.jsx(j,{id:"adminEmails",value:r.adminEmails,onChange:s=>l({...r,adminEmails:s.target.value}),placeholder:"[email protected], [email protected]","data-testid":"input-org-admin-emails"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"These users will have admin access to the organization dashboard and reports. They will receive an email invitation. Use commas to add multiple admins."})]}),e.jsxs("div",{className:"border-t pt-4",children:[e.jsxs(g,{type:"button",variant:"ghost",size:"sm",onClick:()=>F(!N),className:"text-muted-foreground","data-testid":"button-toggle-advanced",children:[N?"Hide":"Show"," Advanced Options"]}),N&&e.jsxs("div",{className:"mt-3 space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u,{htmlFor:"slug",className:"text-sm",children:"Custom URL Slug"}),e.jsx(j,{id:"slug",value:r.slug,onChange:s=>l({...r,slug:s.target.value}),placeholder:"acme-corp","data-testid":"input-org-slug"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u,{className:"text-sm",children:"Brand Colors (auto-detected from logo)"}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(u,{className:"text-xs",children:"Primary"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("input",{type:"color",value:r.primaryColor,onChange:s=>l({...r,primaryColor:s.target.value}),className:"w-8 h-8 rounded cursor-pointer","data-testid":"input-color-primary"}),e.jsx(j,{value:r.primaryColor,onChange:s=>l({...r,primaryColor:s.target.value}),className:"flex-1","data-testid":"input-color-primary-hex"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(u,{className:"text-xs",children:"Secondary"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("input",{type:"color",value:r.secondaryColor,onChange:s=>l({...r,secondaryColor:s.target.value}),className:"w-8 h-8 rounded cursor-pointer","data-testid":"input-color-secondary"}),e.jsx(j,{value:r.secondaryColor,onChange:s=>l({...r,secondaryColor:s.target.value}),className:"flex-1","data-testid":"input-color-secondary-hex"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(u,{className:"text-xs",children:"Accent"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("input",{type:"color",value:r.accentColor,onChange:s=>l({...r,accentColor:s.target.value}),className:"w-8 h-8 rounded cursor-pointer","data-testid":"input-color-accent"}),e.jsx(j,{value:r.accentColor,onChange:s=>l({...r,accentColor:s.target.value}),className:"flex-1","data-testid":"input-color-accent-hex"})]})]})]})]})]})]}),e.jsx("div",{className:"flex justify-end gap-3 pt-3 border-t",children:e.jsxs(g,{type:"submit",disabled:E||!r.name||!r.domains,"data-testid":"button-submit-org",children:[E?e.jsx(T,{size:16,className:"mr-2 animate-spin"}):e.jsx(D,{size:16,className:"mr-2"}),"Create Branded Portal"]})})]})}function je({org:o,onUpdate:E,onToggleLearningAccess:r,canToggleLearningAccess:l,onToggleCourseBuilderManualA
1ccess:c,onCancelPaidCourseBuilder:d,canToggleCourseBuilderManualAccess:f,manualAccessError:w,onAddDomain:N,onRemoveDomain:F,isUpdating:p,newDomain:k,setNewDomain:A}){const[s,m]=v.useState({name:o.name,logoUrl:o.logoUrl||"",primaryColor:o.primaryColor||"#6366f1",secondaryColor:o.secondaryColor||"#4f46e5",accentColor:o.accentColor||"#818cf8",backgroundColor:o.backgroundColor||"#ffffff",textColor:o.textColor||"#0f172a",welcomeMessage:o.welcomeMessage||"",isActive:o.isActive}),[x,b]=v.useState(!1),[z,O]=v.useState(o.courseBuilderManualGrant===!0),B=o.courseBuilderEnabled===!0,y=o.courseBuilderManualGrant===!0,P=o.isActive&&o.learningAccessEnabled!==!1&&$(o),U=o.isActive?o.learningAccessEnabled===!1?"Unavailable while learning access is suspended":"Unavailable":"Unavailable while organization is inactive",M=n=>{if(n&&!z){h.error("Confirm that a signed agreement is in place before granting manual access");return}c(n,n?z:void 0)},S=async n=>{if(n){b(!0);try{const a=await fetch("/api/admin/extract-colors",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({imageUrl:n})});if(a.ok){const i=await a.json();m(t=>({...t,primaryColor:i.primary,secondaryColor:i.secondary,accentColor:i.accent}))}else{const i=await a.json().catch(()=>({message:"Could not extract colors from this image"}));h.error(i.message||"Could not extract colors from this image")}}catch{h.error("Could not reach the server. Please try again.")}b(!1)}};return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"grid md:grid-cols-2 gap-8",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"edit-name",children:"Organization Name"}),e.jsx(j,{id:"edit-name",value:s.name,onChange:n=>m({...s,name:n.target.value}),"data-testid":"input-edit-org-name"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"edit-logo",children:"Logo URL"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{id:"edit-logo",value:s.logoUrl,onChange:n=>m({...s,logoUrl:n.target.value}),placeholder:"https://example.com/logo.png","data-testid":"input-edit-org-logo",className:"flex-1"}),e.jsx(g,{type:"button",variant:"outline",size:"sm",onClick:()=>S(s.logoUrl),disabled:!s.logoUrl||x,"data-testid":"button-refresh-colors",children:x?e.jsx(T,{size:16,className:"animate-spin"}):e.jsx(I,{size:16})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"edit-welcome",children:"Welcome Message"}),e.jsx(oe,{id:"edit-welcome",value:s.welcomeMessage,onChange:n=>m({...s,welcomeMessage:n.target.value}),placeholder:"Welcome to your company's learning portal...",rows:3,"data-testid":"input-edit-org-welcome"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Brand Colors"}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:[{key:"primaryColor",label:"Primary"},{key:"secondaryColor",label:"Secondary"},{key:"accentColor",label:"Accent"},{key:"backgroundColor",label:"Background"},{key:"textColor",label:"Text"}].map(({key:n,label:a})=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"color",value:s[n],onChange:i=>m({...s,[n]:i.target.value}),className:"w-8 h-8 rounded cursor-pointer"}),e.jsx("span",{className:"text-sm",children:a})]},n))})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",id:"edit-active",checked:s.isActive,onChange:n=>m({...s,isActive:n.target.checked}),className:"rounded"}),e.jsx(u,{htmlFor:"edit-active",children:"Organization is active"})]}),e.jsxs("div",{className:"rounded-xl border border-primary/30 bg-primary/5 p-4",children:[e.jsx("div",{className:"flex items-start justify-between gap-3",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 font-medium",children:[e.jsx(J,{size:16,className:"text-primary"}),"Course Builder access"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Paid access is managed by the subscription. This control never starts checkout or changes billing. Use the separate cancellation action below only when you intend to cancel the paid add-on."})]})}),e.jsxs("div",{className:"mt-3 grid gap-2 text-xs","data-testid":"course-builder
1-access-states",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{children:"Manual agreement grant"}),e.jsx("span",{className:y?"font-medium text-primary":"font-medium text-muted-foreground","data-testid":"text-course-builder-manual-state",children:y?"Granted":"Not granted"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{children:"Paid subscription"}),e.jsx("span",{className:B?"font-medium text-primary":"font-medium text-muted-foreground","data-testid":"text-course-builder-paid-state",children:B?"Active":"Not active"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 border-t pt-2",children:[e.jsx("span",{className:"font-medium",children:"Effective Course Builder access"}),e.jsx("span",{className:P?"font-semibold text-primary":"font-semibold text-muted-foreground","data-testid":"text-course-builder-effective-state",children:P?"Available":U})]})]}),B&&e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3 border-t pt-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Cancelling paid access does not remove a manual agreement grant."}),e.jsx(g,{type:"button",variant:"outline",size:"sm",onClick:d,disabled:p,"data-testid":"button-cancel-paid-course-builder",children:"Cancel paid add-on"})]})]}),f&&e.jsxs("div",{className:"rounded-xl border border-emerald-300/60 bg-emerald-50/60 dark:bg-emerald-950/20 p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 font-medium",children:[e.jsx(J,{size:16,className:"text-emerald-700 dark:text-emerald-400"}),"Manual Course Builder access"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Agreement-based access is independent from billing. It is available only to the platform owner and never creates or cancels a subscription."})]}),e.jsxs("label",{className:"relative inline-flex items-center shrink-0 cursor-pointer",children:[e.jsx("input",{type:"checkbox",className:"sr-only peer",checked:y,disabled:p,onChange:n=>M(n.target.checked),"aria-label":"Toggle manual Course Builder access","data-testid":"toggle-course-builder-manual-access"}),e.jsx("div",{className:"w-11 h-6 bg-muted rounded-full peer peer-checked:bg-emerald-600 peer-disabled:opacity-60 peer-checked:after:translate-x-5 after:content-[''] after:absolute after:top-0.5 after:left-0.5 after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all"})]})]}),e.jsxs("label",{htmlFor:`course-builder-agreement-${o.id}`,className:"mt-3 flex cursor-pointer items-start gap-2 text-xs",children:[e.jsx("input",{id:`course-builder-agreement-${o.id}`,type:"checkbox",checked:z,disabled:p,onChange:n=>O(n.target.checked),className:"mt-0.5 rounded","data-testid":"checkbox-course-builder-agreement"}),e.jsx("span",{children:"I confirm that a signed agreement is in place for this organization."})]}),e.jsx("div",{className:"mt-2 text-xs font-medium",role:"status","aria-live":"polite","data-testid":"text-course-builder-manual-feedback",children:w?`Could not save manual access: ${w}`:p?"Saving manual access change…":y?"Manual access is active. Removing it will not cancel paid access.":z?"Agreement acknowledged. Turn on the grant when ready.":"Agreement confirmation is required to enable manual access."})]}),l&&e.jsxs("div",{className:"rounded-xl border border-amber-300/60 bg-amber-50/60 dark:bg-amber-950/20 p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 font-medium",children:[e.jsx(Z,{size:16,className:"text-amber-600"}),"Learning access"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Turn this off to lock every client role—administrators, managers, and learners—out of this organization's dashboards, reports, exports, settings, content tools, Course Builder, and learning content. Existing data and progress are preserved until access is restored; public pages, personal purchases, and the owner's recovery controls remain available."})]}),e.jsxs("label",{className:"relative inline-flex items-center shrink-0 cursor-pointer",children:[e.jsx("input",{type:"checkbox",className:"sr-only peer",checked:o.learningAccessEnabled!==!1,disabled:p,onChange:n=>r(n.target.checked),"data-testid":"toggle-learning-access"}),e.jsx("div",{className:"w-11 h-6 bg-muted rounded-full peer peer-checked:bg-primary peer-disabled:opacity-60 peer-checked:after:translate-x-5 after:content-[''] after:absolute after:top-0.5 after:left-0.5 after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all"})]})]}),e.jsxs("div",{className:"mt-2 text-xs font-medium","data-testid":"text-learning-access-state",children:["Currently:"," ",e.jsx("span",{className:o.learningAccessEnabled!==!1?"text-primary":"text-amber-700",children:o.learningAccessEnabled!==!1?"Enabled":"Disabled"})]})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(u,{children:"Email Domains"}),e.jsx("div",{className:"space-y-2",children:o.domains.map(n=>e.jsxs("div",{className:"flex items-center justify-between bg-muted/50 rounded-lg px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ee,{size:14,className:"text-muted-foreground"}),e.jsx("span",{className:"font-mono text-sm",children:n.domain}),n.isPrimary&&e.jsx("span",{className:"text-xs bg-primary/10 text-primary px-1.5 py-0.5 rounded",children:"Primary"})]}),e.jsx(g,{variant:"ghost",size:"sm",onClick:()=>F(n.id),"data-testid":`button-remove-domain-${n.domain}`,children:e.jsx(ue,{size:14,className:"text-destructive"})})]},n.id))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{value:k,onChange:n=>A(n.target.value),placeholder:"Add domain (e.g., company.com)","data-testid":"input-add-domain"}),e.jsx(g,{variant:"outline",onClick:()=>k&&N(k),disabled:!k,"data-testid":"button-add-domain",children:e.jsx(D,{size:16})})]})]}),e.jsxs("div",{className:"p-4 bg-muted/30 rounded-xl space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(xe,{size:16}),"Brand Preview"]}),e.jsxs("div",{className:"rounded-lg p-4 border",style:{backgroundColor:s.backgroundColor,color:s.textColor},children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[s.logoUrl?e.jsx("img",{src:s.logoUrl,alt:"Logo",className:"w-8 h-8 object-contain"}):e.jsx("div",{className:"w-8 h-8 rounded flex items-center justify-center text-white font-bold text-sm",style:{backgroundColor:s.primaryColor},children:s.name.charAt(0)}),e.jsx("span",{className:"font-semibold",children:s.name})]}),e.jsxs("div",{className:"flex gap-2 mb-3",children:[e.jsx("div",{className:"px-3 py-1.5 rounded text-white text-sm",style:{backgroundColor:s.primaryColor},children:"Primary Button"}),e.jsx("div",{className:"px-3 py-1.5 rounded text-white text-sm",style:{backgroundColor:s.secondaryColor},children:"Secondary"})]}),e.jsx("div",{className:"text-sm px-2 py-1 rounded inline-block",style:{backgroundColor:s.accentColor+"20",color:s.accentColor},children:"Accent highlight"})]})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-4 border-t",children:[e.jsxs(g,{variant:"outline",onClick:()=>window.open(`/org/${o.slug}/dashboard`,"_blank"),"data-testid":"button-enter-environment",children:[e.jsx(ne,{size:16,className:"mr-2"}),"Enter Admin Dashboard"]}),e.jsxs(g,{onClick:()=>E(s),disabled:p,"data-testid":"button-save-org",children:[p?e.jsx(T,{size:16,className:"mr-2 animate-spin"}):e.jsx(ge,{size:16,className:"mr-2"}),"Save Changes"]})]})]})}export{Ze 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.