PageSourceSearch

https://healyourrootswellness.com/assets/UserManagement-C8wDr7K0.js

js healyourrootswellness.com collected 2026-10-04 05:45:47 UTC 11,087 bytes, 1 lines download raw bytes

1import{d as ae,t as re,a1 as ne,a2 as te,r as U,bG as le,v as ie,bf as ce,bv as de,w as T,X as D,x as F,j as e,B as b,a5 as oe,as as P,at as me,P as ue,av as R,aw as M,ax as q,ay as I,J as xe,_ as he,$ as je,U as pe,a3 as ge,K as ve,a6 as fe,I as v,V as $,n as be,ag as Ne,W as ye,bg as we,bh as u,bi as x,bj as h,bk as j,bl as p,y as Ce,z as Se,D as Ue,G as Te,H as De,Y as Fe,bx as ke,bo as g,by as Ae,bH as Ee}from"./index-M9vbWaAR.js";import{B as _e}from"./Breadcrumbs-T8gbmSyV.js";import{T as Le,a as Pe,b as H,c as o,d as Re,e as m}from"./table-DVMjlRkO.js";const Me=[["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:"17",x2:"22",y1:"8",y2:"13",key:"3nzzx3"}],["line",{x1:"22",x2:"17",y1:"8",y2:"13",key:"1swrse"}]],qe=ae("user-x",Me),f=[{value:"user",label:"User"},{value:"member",label:"Member"},{value:"moderator",label:"Moderator"},{value:"leads",label:"Leads"},{value:"marketing",label:"Marketing"},{value:"admin",label:"Admin"},{value:"head_client_success",label:"Head of Client Success"},{value:"superadmin",label:"Superadmin"}];function Ie(a,c){let d=f;if(a==="head_client_success"?d=f.filter(r=>r.value!=="superadmin"):a==="admin"?d=f.filter(r=>["user","member","moderator"].includes(r.value)):a!=="superadmin"&&(d=f.filter(r=>r.value==="user")),c&&!d.some(r=>r.value===c)){const r=f.find(t=>t.value===c);r&&(d=[r,...d])}return d}function O(a){return f.find(c=>c.value===a)?.label??a}const $e=ke({firstName:g().min(1,"First name is required"),lastName:g().min(1,"Last name is required"),email:g().email("Invalid email address"),username:g().min(3,"Username must be at least 3 characters").optional(),role:g().min(1,"Role is required"),active:Ae(),password:g().min(6,"Password must be at least 6 characters").optional()});function Ve(){const{toast:a}=re(),{user:c}=ne(),[,d]=te(),[r,t]=U.useState(null),[C,N]=U.useState(!1),[w,S]=U.useState(""),n=le(c)??"",l=c?.role??"",V=Ee(l),z=c?.id,{data:K=[],isLoading:Q,error:G}=ie({queryKey:["/api/users"]}),J=K.filter(s=>{const i=w.trim().toLowerCase();return i?[s.firstName,s.lastName,s.email,s.username??"",O(s.role)].some(se=>se.toLowerCase().includes(i)):!0}),y=ce({resolver:de($e),defaultValues:{firstName:"",lastName:"",email:"",username:"",role:"user",active:!0,password:""}}),k=T({mutationFn:s=>F("/api/users","POST",s),onSuccess:()=>{D.invalidateQueries({queryKey:["/api/users"]}),N(!1),y.reset(),a({title:"Success",description:"User created successfully."})},onError:s=>{a({title:"Error",description:s.message||"Failed to create user.",variant:"destructive"})}}),A=T({mutationFn:({id:s,data:i})=>F(`/api/users/${s}`,"PATCH",i),onSuccess:()=>{D.invalidateQueries({queryKey:["/api/users"]}),t(null),y.reset(),a({title:"Success",description:"User updated successfully."})},onError:s=>{a({title:"Error",description:s.message||"Failed to update user.",variant:"destructive"})}}),E=T({mutationFn:s=>F(`/api/users/${s}`,"DELETE"),onSuccess:()=>{D.invalidateQueries({queryKey:["/api/users"]}),a({title:"Success",description:"User deleted successfully."})},onError:s=>{a({title:"Error",description:s.message||"Failed to delete user.",variant:"destructive"})}}),X=s=>{t(s),y.reset({firstName:s.firstName,lastName:s.lastName,email:s.email,username:s.username||"",role:s.role,active:s.active,password:""})},W=(s,i)=>{window.confirm(`Are you sure you want to delete user "${i}"? This action cannot be undone.`)&&E.mutate(s)},_=s=>{if(r){const i={...s};s.role===r.role&&delete i.role,delete i.password,A.mutate({id:r.id,data:i})}else k.mutate(s)},L=s=>n!=="head_client_success"&&l!=="head_client_success"||s.role!=="superadmin",Y=s=>s.id!==z&&(l==="superadmin"||l==="head_client_success"&&s.role!=="superadmin"||l==="admin"&&s.role!=="admin"&&s.role!=="superadmin"),Z=s=>V||l==="head_client_success"&&s.role!=="superadmin",ee=s=>{switch(s){case"superadmin":return"destructive";case"admin":return"default";case"marketing":return"secondary";case"leads":return"outline";default:return"outline"}};return Q?e.jsx("div",{className:"container mx-auto py-6 max-w-7xl",children:e.jsx("div",{className:"text-center py-8",children:e.jsx("p",{children:"Loading users..."})})}):G?e.jsx("div",{className:"container mx-auto py-6 max-w-7xl",children:e.jsx("div",{className:"text-center py-8",children:e.jsx("p",{className:"text-destructive",children:"Failed to load users. Please try again."})})}):e.jsxs("div",{className:"container mx-auto py-6 max-w-7xl",children:[e.jsx(_e,{items:[{label:"Dashboard",href:"/admin"},{label:"User Management",href:"/admin/users"}]}),e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight",children:"User Management"}),e.jsx("p",{className:"text-muted-foreground",children:"Manage existing account access. Changing a role does not replace login credentials or a linked therapist profile."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(b,{variant:"outline",onClick:()=>d("/admin"),children:[e.jsx(oe,{className:"mr-2 h-4 w-4"}),"Back to Dashboard"]}),e.jsxs(P,{open:C,onOpenChange:N,children:[e.jsx(me,{asChild:!0,children:e.jsxs(b,{children:[e.jsx(ue,{className:"mr-2 h-4 w-4"}),"Add New User"]})}),e.jsxs(R,{className:"max-w-md",children:[e.jsxs(M,{children:[e.jsx(q,{children:"Create New User"}),e.jsx(I,{children:"Create a separate account only if this person does not already have one. If they already sign in or have a therapist profile, edit their existing account instead."})]}),e.jsx(B,{form:y,onSubmit:_,onCancel:()=>N(!1),isSubmitting:k.isPending,isEditing:!1,actorRole:l,canChangeRole:!0})]})]})]})]}),e.jsxs(xe,{children:[e.jsxs(he,{children:[e.jsxs(je,{className:"flex items-center gap-2",children:[e.jsx(pe,{className:"h-5 w-5"}),"All Users"]}),e.jsx(ge,{children:"Search for an existing user or therapist and change their role without changing their sign-in credentials or therapist profile."})]}),e.jsxs(ve,{children:[e.jsxs("div",{className:"relative mb-4 max-w-md",children:[e.jsx(fe,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(v,{value:w,onChange:s=>S(s.target.value),placeholder:"Search by name, email, username, or role",className:"pl-9","aria-label":"Search users"})]}
1),e.jsxs(Le,{children:[e.jsx(Pe,{children:e.jsxs(H,{children:[e.jsx(o,{children:"Name"}),e.jsx(o,{children:"Email"}),e.jsx(o,{children:"Username"}),e.jsx(o,{children:"Role"}),e.jsx(o,{children:"Status"}),e.jsx(o,{children:"Provider"}),e.jsx(o,{children:"Found Us Via"}),e.jsx(o,{children:"Created"}),e.jsx(o,{className:"text-right",children:"Actions"})]})}),e.jsx(Re,{children:J.map(s=>e.jsxs(H,{children:[e.jsxs(m,{className:"font-medium",children:[s.firstName," ",s.lastName]}),e.jsx(m,{children:s.email}),e.jsx(m,{children:s.username||"-"}),e.jsx(m,{children:e.jsx($,{variant:ee(s.role),children:O(s.role)})}),e.jsx(m,{children:e.jsx("div",{className:"flex items-center gap-2",children:s.active?e.jsxs(e.Fragment,{children:[e.jsx(be,{className:"h-4 w-4 text-green-600"}),e.jsx("span",{className:"text-green-600",children:"Active"})]}):e.jsxs(e.Fragment,{children:[e.jsx(qe,{className:"h-4 w-4 text-red-600"}),e.jsx("span",{className:"text-red-600",children:"Inactive"})]})})}),e.jsx(m,{children:e.jsx($,{variant:"outline",children:s.authProvider})}),e.jsx(m,{children:s.referralSource?s.referralSource.replace(/_/g," ").replace(/\b\w/g,i=>i.toUpperCase()):e.jsx("span",{className:"text-muted-foreground",children:"—"})}),e.jsx(m,{children:new Date(s.createdAt).toLocaleDateString()}),e.jsx(m,{className:"text-right",children:e.jsxs("div",{className:"flex gap-2 justify-end",children:[L(s)&&e.jsx(b,{variant:"outline",size:"sm",onClick:()=>X(s),"aria-label":`Edit ${s.firstName} ${s.lastName}`,children:e.jsx(Ne,{className:"h-4 w-4"})}),Z(s)&&e.jsx(b,{variant:"outline",size:"sm",onClick:()=>W(s.id,`${s.firstName} ${s.lastName}`),disabled:E.isPending,"aria-label":`Delete ${s.firstName} ${s.lastName}`,children:e.jsx(ye,{className:"h-4 w-4"})}),!L(s)&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"Protected superadmin account"})]})})]},s.id))})]})]})]}),e.jsx(P,{open:!!r,onOpenChange:()=>t(null),children:e.jsxs(R,{className:"max-w-md",children:[e.jsxs(M,{children:[e.jsx(q,{children:"Edit User"}),e.jsx(I,{children:"Update user information and permissions."})]}),e.jsx(B,{form:y,onSubmit:_,onCancel:()=>t(null),isSubmitting:A.isPending,isEditing:!0,actorRole:l,currentRole:r?.role,canChangeRole:r?Y(r):!1})]})})]})}function B({form:a,onSubmit:c,onCancel:d,isSubmitting:r,isEditing:t=!1,actorRole:C,currentRole:N,canChangeRole:w=!0}){const S=Ie(C,t?N:void 0);return e.jsx(we,{...a,children:e.jsxs("form",{onSubmit:a.handleSubmit(c),className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(u,{control:a.control,name:"firstName",render:({field:n})=>e.jsxs(x,{children:[e.jsx(h,{children:"First Name *"}),e.jsx(j,{children:e.jsx(v,{placeholder:"John",...n})}),e.jsx(p,{})]})}),e.jsx(u,{control:a.control,name:"lastName",render:({field:n})=>e.jsxs(x,{children:[e.jsx(h,{children:"Last Name *"}),e.jsx(j,{children:e.jsx(v,{placeholder:"Doe",...n})}),e.jsx(p,{})]})})]}),e.jsx(u,{control:a.control,name:"email",render:({field:n})=>e.jsxs(x,{children:[e.jsx(h,{children:"Email *"}),e.jsx(j,{children:e.jsx(v,{type:"email",placeholder:"[email protected]",...n})}),e.jsx(p,{})]})}),e.jsx(u,{control:a.control,name:"username",render:({field:n})=>e.jsxs(x,{children:[e.jsx(h,{children:"Username"}),e.jsx(j,{children:e.jsx(v,{placeholder:"johndoe",...n})}),e.jsx(p,{})]})}),e.jsx(u,{control:a.control,name:"role",render:({field:n})=>e.jsxs(x,{children:[e.jsx(h,{children:"Role *"}),e.jsxs(Ce,{onValueChange:n.onChange,value:n.value,disabled:t&&!w,children:[e.jsx(j,{children:e.jsx(Se,{children:e.jsx(Ue,{placeholder:"Select a role"})})}),e.jsx(Te,{children:S.map(l=>e.jsx(De,{value:l.value,children:l.label},l.value))})]}),e.jsx(p,{})]})}),t&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"A role change updates access on this existing account only. The password, sign-in provider, and linked therapist profile are preserved."}),!t&&e.jsx(u,{control:a.control,name:"password",render:({field:n})=>e.jsxs(x,{children:[e.jsx(h,{children:"Password *"}),e.jsx(j,{children:e.jsx(v,{type:"password",placeholder:"Enter password",...n})}),e.jsx(p,{})]})}),e.jsx(u,{control:a.control,name:"active",render:({field:n})=>e.jsxs(x,{className:"flex flex-row items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(h,{children:"Active User"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Allow this user to access the system"})]}),e.jsx(j,{children:e.jsx(Fe,{checked:n.value,onCheckedChange:n.onChange})})]})}),e.jsxs("div",{className:"flex gap-2 pt-4",children:[e.jsx(b,{type:"button",variant:"outline",onClick:d,children:"Cancel"}),e.jsx(b,{type:"submit",disabled:r,children:r?"Saving...":t?"Update User":"Create User"})]})]})})}export{Ve 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.