PageSourceSearch

https://ehr.roojh.com/assets/RBACSettings-Bh5V7HDM.js

js roojh.com collected 2026-09-24 14:19:23 UTC 34,497 bytes, 21 lines download raw bytes

1import{ad as V,r as l,b as _,j as e,A as L,af as q,w as M,T as G,B as K,c as Q}from"./index-BPZ0Tu-q.js";import{U as Y}from"./user-check-B4Ql6JI_.js";import{S as J}from"./search-DbEWOi6v.js";import{D as ee}from"./Drawer-B-78RTPq.js";import{S as te,a as se,b as re}from"./Stepper-BrKk5vuw.js";import{D as ae}from"./Dialog-BlI2Fgst.js";import{D as le}from"./DialogContent-B16Ubs63.js";import{D as ne}from"./DialogActions-DLhv-LTc.js";import{B as W}from"./Button-CJX4vknK.js";import{P as ie}from"./plus-MHkvfz3o.js";import{P as oe}from"./pencil-DdMl2maR.js";import{C as ce}from"./calendar-BBRiFoj4.js";import"./index-CW4QP1nW.js";import"./debounce-B4KKL1rx.js";import"./Paper-BVAQp4ao.js";import"./useId-DWBHnGLh.js";import"./dialogTitleClasses-BxAwWPO8.js";import"./ButtonBase-CHULMRoT.js";import"./useIsFocusVisible-Di6E_YNW.js";import"./assertThisInitialized-CPFABtj-.js";(function(){try{var i=typeof globalThis<"u"?globalThis:typeof global<"u"?global:typeof window<"u"?window:typeof self<"u"?self:{};i["__faroGitHash_roojh-web"]="e10f4edfac9af7700f53a2e4507d7c1e30f45024"}catch{}})();(function(){try{var i=typeof globalThis<"u"?globalThis:typeof global<"u"?global:typeof window<"u"?window:typeof self<"u"?self:{};i["__faroBundleId_roojh-web"]="1790253054184ad54def21a"}catch{}})();/**
2 * @license lucide-react v0.427.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const de=V("ScrollText",[["path",{d:"M15 12h-5",key:"r7krc0"}],["path",{d:"M15 8h-5",key:"1khuty"}],["path",{d:"M19 17V5a2 2 0 0 0-2-2H4",key:"zz82l3"}],["path",{d:"M8 21h12a2 2 0 0 0 2-2v-1a1 1 0 0 0-1-1H11a1 1 0 0 0-1 1v1a2 2 0 1 1-4 0V5a2 2 0 1 0-4 0v2a1 1 0 0 0 1 1h3",key:"1ph1d7"}]]);/**
7 * @license lucide-react v0.427.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const Z=V("ShieldCheck",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);/**
12 * @license lucide-react v0.427.0 - ISC
13 *
14 * This source code is licensed under the ISC license.
15 * See the LICENSE file in the root directory of this source tree.
16 */const xe=V("UserRound",[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]]);/**
17 * @license lucide-react v0.427.0 - ISC
18 *
19 * This source code is licensed under the ISC license.
20 * See the LICENSE file in the root directory of this source tree.
21 */const pe=V("Users",[["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"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]]),$=["View","Create","Edit","Delete"],me=({permissions:i,onChange:b,onFeaturesLoad:d})=>{const[f,D]=l.useState([]),[z,C]=l.useState({}),[j,g]=l.useState({}),[u,v]=l.useState(!0),[E,I]=l.useState(null),{apiCall:P}=_(),o=s=>s.trim().toLowerCase(),y=s=>(s.level1||"Other").trim()||"Other",A=s=>(s.level2||"").trim(),T=s=>o((s.name||y(s)).trim()||"Other"),t=s=>o(y(s));l.useEffect(()=>{(async()=>{v(!0),I(null);try{const r=await P(!0,"api/v1/webFeatures/getWebFeatures",L.GET),h=Array.isArray(r)?r:(r==null?void 0:r.data)??[];D(h),d(h);const m={},a={},c=new Set;h.forEach(p=>{if(p.type!=="navigation")return;const N=(p.name||y(p)).trim()||"Other",k=o(N);c.add(k),m[k]=!1}),h.forEach(p=>{if(p.type==="navigation")return;const N=o(y(p));if(!c.has(N))return;const k=A(p);if(k){const B=o(k);a[`${N}::${B}`]=!1}}),C(m),g(a);const S={...i};h.forEach(p=>{S[p._id]||(p.isBoolean?S[p._id]={enabled:!1}:(S[p._id]={},$.forEach(N=>{S[p._id][N]=!0})))}),b(S)}catch{I("Failed to load permissions. Please try again.")}finally{v(!1)}})()},[]);const n=f.filter(s=>s.isBoolean),R=s=>{var h;const r=((h=i[s._id])==null?void 0:h.enabled)??!1;return e.jsx("div",{className:"rounded-lg border border-[#204289] bg-[#EEF4FF] ring-1 ring-[#204289]/20 px-4 py-3 mb-2",children:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[12px] font-semibold text-[#153168]",children:s.name}),s.description&&e.jsx("p",{className:"text-[10px] text-gray-400 mt-0.5",children:s.description})]}),e.jsx("button",{type:"button",onClick:()=>{b({...i,[s._id]:{enabled:!r}})},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors focus:outline-none ${r?"bg-[#204289]":"bg-gray-300"}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 transform rounded-full bg-white shadow transition-transform ${r?"translate-x-4":"translate-x-1"}`})})]})},s._id)},w=(s,r)=>{const h=f.find(p=>p._id===s),m=i[s]??{},a=!!m[r],c={...m};r==="View"?a?$.forEach(p=>{c[p]=!1}):c.View=!0:a?c[r]=!1:(c[r]=!0,c.View=!0);const S={...i,[s]:c};if((h==null?void 0:h.type)==="navigation"&&a){const p=T(h);f.filter(k=>k.type!=="navigation"&&t(k)===p).map(k=>
21k._id).forEach(k=>{const B={...S[k]??{}};r==="View"?$.forEach(X=>{B[X]=!1}):B[r]=!1,S[k]=B})}b(S)},x=(()=>{const s={};return f.forEach(r=>{if(r.type!=="navigation")return;const h=(r.name||y(r)).trim()||"Other",m=o(h);s[m]?s[m].navigationItem||(s[m].navigationItem=r):s[m]={label:h,navigationItem:r,ungrouped:[],level2Groups:{}}}),f.forEach(r=>{if(r.type==="navigation")return;const h=y(r),m=o(h);if(!s[m])return;const a=A(r),c=o(a);a?(s[m].level2Groups[c]||(s[m].level2Groups[c]={label:a,items:[]}),s[m].level2Groups[c].items.push(r)):s[m].ungrouped.push(r)}),s})(),F=(s,r)=>{const h=i[s._id]??{},m=!!h.View,a=s.type==="navigation",c=!!(r!=null&&r.isChild),S=(r==null?void 0:r.parentViewEnabled)??!0,p=c&&!S;return e.jsxs("div",{className:`rounded-lg px-4 py-3 ${a?"border-2 border-[#204289] bg-[#EEF4FF] ring-1 ring-[#204289]/20":p?"border border-gray-200 bg-gray-50 opacity-75":"border border-gray-200 bg-white"}`,children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("div",{className:"flex items-center justify-between gap-2",children:e.jsx("p",{className:`text-[12px] font-semibold ${a?"text-[#153168]":"text-gray-700"}`,children:s.name})}),s.description?e.jsx("p",{className:"text-[10px] text-gray-400 mt-0.5",children:s.description}):null,a?e.jsx("p",{className:"text-[10px] text-[#204289] mt-1 font-medium",children:"Navigation Permission - Turning this off also turns off permissions for all items in this section."}):null]}),e.jsx("div",{className:"grid grid-cols-3 gap-x-4 gap-y-2.5",children:$.map(N=>{const k=!!h[N],B=p||N!=="View"&&!m;return e.jsxs("div",{className:`flex items-center gap-3 ${B?"opacity-40":""}`,title:p?"Enable parent Navigation Permission View first":B?"Enable View first":void 0,children:[e.jsx("span",{className:"text-[11px] text-gray-600 w-10",children:N}),B&&e.jsx("svg",{viewBox:"0 0 12 12",className:"w-2.5 h-2.5 text-gray-400 fill-current",children:e.jsx("path",{d:"M9 5H8V3.5a2 2 0 0 0-4 0V5H3a1 1 0 0 0-1 1v4a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1ZM5 3.5a1 1 0 0 1 2 0V5H5V3.5Z"})}),e.jsx("button",{type:"button",disabled:B,onClick:()=>w(s._id,N),className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors focus:outline-none ${B?"cursor-not-allowed bg-gray-200":k?"bg-[#204289]":"bg-gray-300"}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 transform rounded-full bg-white shadow transition-transform ${k?"translate-x-4":"translate-x-1"}`})})]},N)})})]},s._id)};return u?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx("div",{className:"w-5 h-5 border-2 border-[#204289] border-t-transparent rounded-full animate-spin"})}):E?e.jsx("p",{className:"text-[12px] text-red-500 text-center py-10",children:E}):e.jsxs("div",{className:"flex flex-col gap-4 max-h-[calc(100vh-280px)] overflow-y-auto pr-1",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-[13px] font-semibold text-gray-800",children:"Permission Matrix"}),e.jsx("p",{className:"text-[11px] text-gray-500 mt-0.5",children:"Toggle switches to grant or revoke permissions"})]}),n.length>0&&e.jsx("div",{className:"flex flex-col gap-2 mb-2",children:n.map(R)}),e.jsx("div",{className:"flex flex-col gap-3 ",children:Object.entries(x).map(([s,r])=>{var a;const h=z[s],m=r.navigationItem?!!(i[r.navigationItem._id]??{}).View:!0;return e.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white",children:[e.jsxs("button",{type:"button",onClick:()=>C(c=>({...c,[s]:!c[s]})),className:"flex items-center justify-between px-4 py-4 w-full cursor-pointer focus:outline-none bg-transparent border-0",style:{textAlign:"left"},children:[e.jsx("span",{className:"text-[13px] font-semibold text-[#153168]",children:((a=r.navigationItem)==null?void 0:a.name)||r.label}),e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full border border-gray-300 bg-white px-2 py-1 text-[10px] font-medium text-gray-700 hover:bg-gray-50",children:[e.jsx("svg",{viewBox:"0 0 20 20",className:`h-3 w-3 text-gray-600 transition-transform ${h?"rotate-90":"rotate-0"}`,fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M7 5l6 5-6 5"})}),h?"Collapse section":"Expand section"]})]}),h&&e.jsxs("div",{className:"px-4 py-4 flex flex-col gap-3",children:[r.navigationItem&&e.jsx("div",{className:"grid grid-cols-1 gap-3",children:F(r.navigationItem)}),(r.ungrouped.length>0||Object.keys(r.level2Groups).length>0)&&e.jsxs("div",{className:"ml-2 pl-4 flex flex-col gap-3",children:[e.jsx("div",{className:"border-b border-gray-200 pb-1 text-[10px] font-semibold uppercase tracking-wide text-gray-500",children:"Applies under this navigation"}),r.ungrouped.length>0&&e.jsx("div",{className:"ml-4 grid grid-cols-1 gap-3",children:r.ungrouped.map(c=>F(c,{isChild:!0,parentViewEnabled:m}))}),Object.entries(r.level2Groups).map(([c,S])=>{const p=`${s}::${c}`;return e.jsxs("div",{className:"ml-4 rounded-md border border-gray-100 bg-gray-50 px-3 py-2",children:[e.jsxs("button",{type:"button",onClick:()=>g(N=>({...N,[p]:!N[p]})),className:"flex items-center justify-between w-full cursor-pointer focus:outline-none bg-transparent border-0 px-0 py-0",style:{textAlign:"left"},children:[e.jsx("span",{className:"text-[11px] font-medium text-gray-700",children:S.label}),e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-gray-300 bg-white px-2 py-0.5 text-[10px] font-medium text-gray-600 hover:bg-gray-100",children:[e.jsx("svg",{viewBox:"0 0 20 20",className:`h-3 w-3 text-gray-600 transition-transform ${j[p]?"rotate-90":"rotate-0"}`,fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M7 5l6 5-6 5"})}),j[p]?"Collapse":"Expand"]})]}),j[p]&&e.jsx("div",{className:"grid grid-cols-1 gap-3 mt-2",children:S.items.map(N=>F(N,{isChild:!0,parentViewEnabled:m}))})]},p)})]})]})]},s)})})]})},he=({data:i,onChange:b,onNameExists:d})=>{const[f,D]=l.useState(!1),[z,C]=l.useState(!1),[j,g]=l.useState(!1),[u,v]=l.useState(!1),{apiCall:E}=_(),I=f&&!i.roleName.trim(),P=async()=>{const o=i.roleName.trim();if(!o){g(!1),d(!1);return}
21try{v(!0);const y=localStorage.getItem("enterpriseId"),A=await E(!0,`api/v1/accessControl/checkName?name=${encodeURIComponent(o)}&enterpriseId=${y}`,L.GET),T=(A==null?void 0:A.exists)??!1;g(T),d(T)}catch{g(!1),d(!1)}finally{v(!1)}};return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("label",{className:"text-[11px] font-medium text-gray-700",children:["Role Name ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"text",placeholder:"e.g. Doctor, Receptionist",value:i.roleName,onChange:o=>{const y=o.target.value;/^[A-Za-z\s-]*$/.test(y)?(C(!1),g(!1),d(!1),b({...i,roleName:y})):C(!0)},onBlur:async()=>{D(!0),await P()},className:`w-full border rounded-md px-3 py-2 text-[12px] outline-none focus:border-blue-400 ${I||j?"border-red-400":"border-gray-300"}`}),u&&e.jsx("span",{className:"absolute right-3 top-1/2 -translate-y-1/2 text-[10px] text-gray-400",children:"Checking..."})]}),I&&e.jsx("span",{className:"text-[10px] text-red-500",children:"Role name is required"}),z&&e.jsx("span",{className:"text-[10px] text-red-500",children:"Only letters, spaces, and '-' are allowed"}),j&&!I&&e.jsx("span",{className:"text-[10px] text-red-500",children:"Role name already exists. Please choose a different name."})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{className:"text-[11px] font-medium text-gray-700",children:"Description"}),e.jsx("textarea",{placeholder:"Describe what this role can do...",rows:3,value:i.description,onChange:o=>b({...i,description:o.target.value}),className:"border border-gray-300 rounded-md px-3 py-2 text-[12px] outline-none focus:border-blue-400 resize-none"})]})]})},H=localStorage.getItem("enterpriseId")??"",ue=({selectedUserIds:i,onChange:b,onUsersChange:d})=>{const[f,D]=l.useState([]),[z,C]=l.useState(!0),[j,g]=l.useState(null),[u,v]=l.useState(""),[E,I]=l.useState("all"),{apiCall:P}=_();l.useEffect(()=>{(async()=>{C(!0),g(null);try{const[n,R]=await Promise.allSettled([P(!0,`api/v1/doctor/getAuthentictedDoctors?enterpriseId=${H}`,L.GET),P(!0,`api/v1/mongoProvider/getAssistants?enterpriseId=${H}`,L.GET)]),w=n.status==="fulfilled"?n.value:[],x=R.status==="fulfilled"?R.value:{},F=(Array.isArray(w)?w:[]).map(a=>({id:a.userId,name:a.name,profileImage:a.profileImage,type:"doctor"})),r=((x==null?void 0:x.assistant)??[]).map(a=>{var p,N,k;const c=(p=a==null?void 0:a.assistantId)==null?void 0:p.userId,S=(c==null?void 0:c._id)??c??(a==null?void 0:a.userId);return S?{id:String(S),name:(c==null?void 0:c.name)??((N=a==null?void 0:a.assistantId)==null?void 0:N.name)??"Assistant",profileImage:(c==null?void 0:c.profileImage)??((k=a==null?void 0:a.assistantId)==null?void 0:k.profileImage),type:"assistant"}:null}).filter(Boolean),m=[...F,...r].filter((a,c,S)=>S.findIndex(p=>p.id===a.id)===c);console.log("Doctors:",F),console.log("Assistants:",r),console.log("Combined unique users:",m),D(m),d(m),n.status==="rejected"&&R.status==="rejected"&&g("Failed to load users. Please try again.")}catch{g("Failed to load users. Please try again.")}finally{C(!1)}})()},[]);const o=f.filter(t=>{const n=E==="all"||t.type===E,R=t.name.toLowerCase().includes(u.toLowerCase());return n&&R}),y=t=>{if(i.includes(t)){const n=i.filter(R=>R!==t);console.log("Selected user IDs:",n),b(n)}else{const n=[...i,t];console.log("Selected user IDs:",n),b(n)}},A=t=>t.split(" ").slice(0,2).map(n=>n[0]).join("").toUpperCase(),T={all:f.length,doctor:f.filter(t=>t.type==="doctor").length,assistant:f.filter(t=>t.type==="assistant").length};return e.jsxs("div",{className:"flex flex-col gap-4 min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-[11px] text-gray-500",children:"Select users to assign to this role."}),i.length>0&&e.jsxs("span",{className:"flex items-center gap-1 text-[11px] font-medium text-[#204289] bg-blue-50 px-2 py-0.5 rounded-full",children:[e.jsx(Y,{className:"size-3"}),i.length," selected"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(J,{className:"absolute left-3 top-1/2 -translate-y-1/2 size-3.5 text-gray-400"}),e.jsx("input",{type:"text",placeholder:"Search by name...",value:u,onChange:t=>v(t.target.value),className:"w-full border border-gray-300 rounded-md pl-8 pr-3 py-2 text-[12px] outline-none focus:border-blue-400"}),u&&e.jsx("button",{onClick:()=>v(""),className:"absolute right-3 top-1/2 -translate-y-1/2",children:e.jsx(q,{className:"size-3.5 text-gray-400 hover:text-gray-600"})})]}),e.jsx("div",{className:"flex gap-1 border-b border-gray-200",children:["all","doctor","assistant"].map(t=>e.jsxs("button",{onClick:()=>I(t),className:`px-3 py-1.5 text-[11px] font-medium capitalize transition-colors border-b-2 -mb-px ${E===t?"border-[#204289] text-[#204289]":"border-transparent text-gray-500 hover:text-gray-700"}`,children:[t==="all"?"All":t==="doctor"?"Doctors":"Assistants",e.jsxs("span",{className:"ml-1 text-[10px] text-gray-400",children:["(",T[t],")"]})]},t))}),e.jsx("div",{className:"flex flex-col gap-1.5 flex-1 overflow-y-auto pr-1 min-h-0",children:z?e.jsx("div",{className:"flex items-center justify-center py-10",children:e.jsx("div",{className:"w-5 h-5 border-2 border-[#204289] border-t-transparent roun
21ded-full animate-spin"})}):j?e.jsx("p",{className:"text-[12px] text-red-500 text-center py-6",children:j}):o.length===0?e.jsx("p",{className:"text-[12px] text-gray-400 text-center py-6",children:"No users found."}):o.map(t=>{const n=i.includes(t.id);return e.jsxs("button",{onClick:()=>y(t.id),className:`flex items-center gap-3 px-3 py-2.5 rounded-md border text-left transition-all ${n?"border-[#204289] bg-blue-50":"border-gray-200 hover:border-gray-300 hover:bg-gray-50"}`,children:[e.jsx("div",{className:`size-8 rounded-full flex items-center justify-center flex-shrink-0 text-[11px] font-semibold ${t.type==="doctor"?"bg-indigo-100 text-indigo-700":"bg-emerald-100 text-emerald-700"}`,children:t.profileImage?e.jsx("img",{src:t.profileImage,alt:t.name,className:"size-8 rounded-full object-cover"}):A(t.name)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[12px] font-medium text-gray-800 truncate",children:t.name}),e.jsx("p",{className:"text-[10px] text-gray-400 capitalize",children:t.type})]}),e.jsx("div",{className:`size-4 rounded border-2 flex items-center justify-center flex-shrink-0 transition-colors ${n?"bg-[#204289] border-[#204289]":"border-gray-300"}`,children:n&&e.jsx("svg",{viewBox:"0 0 10 8",className:"w-2.5 h-2.5 fill-white",children:e.jsx("path",{d:"M1 4l2.5 2.5L9 1",stroke:"white",strokeWidth:"1.5",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"})})})]},t.id)})})]})};function U({title:i,icon:b,children:d,onEdit:f}){return e.jsxs("div",{className:"rounded-lg border border-gray-200 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 border-b border-gray-200 bg-gray-50",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-gray-400",children:b}),e.jsx("h3",{className:"text-[12px] font-semibold text-gray-700",children:i})]}),f&&e.jsx("button",{onClick:f,className:"text-[11px] text-[#204289] hover:underline font-medium",children:"Edit"})]}),e.jsx("div",{className:"px-4 py-3",children:d})]})}const fe=({basics:i,permissions:b,selectedUserIds:d,allUsers:f,onEdit:D,feature:z})=>{const C=f.filter(u=>d.includes(u.id)),j=Object.entries(b).filter(([,u])=>Object.values(u).some(Boolean)),g=j.reduce((u,[,v])=>u+Object.values(v).filter(Boolean).length,0);return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-[13px] font-semibold text-gray-800",children:"Review & Confirm"}),e.jsx("p",{className:"text-[11px] text-gray-500 mt-0.5",children:"Double-check your setup before you submit."})]}),e.jsx(U,{title:"Role Information",icon:e.jsx(de,{size:14}),onEdit:()=>D(0),children:e.jsxs("div",{className:"flex flex-col divide-y divide-gray-100",children:[e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[11px] text-gray-500",children:"Role Name"}),e.jsx("span",{className:"text-[12px] font-medium text-gray-800",children:i.roleName||"—"})]}),e.jsxs("div",{className:"flex items-start justify-between py-2 gap-4",children:[e.jsx("span",{className:"text-[11px] text-gray-500 shrink-0",children:"Description"}),e.jsx("span",{className:"text-[12px] text-gray-600 text-right leading-relaxed",children:i.description||"—"})]})]})}),e.jsx(U,{title:"Permissions",icon:e.jsx(Z,{size:14}),onEdit:()=>D(1),children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between py-1",children:[e.jsx("span",{className:"text-[11px] text-gray-500",children:"Total"}),e.jsxs("span",{className:"text-[11px] font-medium text-[#204289] bg-blue-50 px-2.5 py-0.5 rounded-full border border-blue-100",children:[g," Permission",g!==1?"s":""]})]}),j.length>0?e.jsx("div",{className:"flex flex-col divide-y divide-gray-100",children:j.map(([u,v])=>{var P;const E=Object.entries(v).filter(([,o])=>o).map(([o])=>o),I=((P=z.find(o=>o._id===u))==null?void 0:P.name)??u;return e.jsxs("div",{className:"flex items-start justify-between gap-3 py-2",children:[e.jsx("span",{className:"text-[12px] text-gray-700 shrink-0",children:I}),e.jsx("div",{className:"flex flex-wrap gap-1 justify-end",children:E.map(o=>e.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full bg-green-50 text-green-700 border border-green-200 font-medium",children:o},o))})]},u)})}):e.jsx("p",{className:"text-[11px] text-gray-400 italic py-1",children:"No permissions configured."})]})}),e.jsxs(U,{title:"Assigned Users",icon:e.jsx(xe,{size:14}),onEdit:()=>D(2),children:[e.jsxs("div",{className:"flex items-center justify-between py-1",children:[e.jsx("span",{className:"text-[11px] text-gray-500",children:"Total"}),e.jsxs("span",{className:"text-[11px] font-medium text-[#204289] bg-blue-50 px-2.5 py-0.5 rounded-full border border-blue-100",children:[d.length," User",d.length!==1?"s":""]})]}),d.length>0?e.jsx("div",{className:"flex flex-col divide-y divide-gray-100 mt-1",children:C.map(u=>e.jsxs("div",{className:"flex items-center gap-2.5 py-2",children:[e.jsx("div",{className:`size-6 rounded-full flex items-center justify-center flex-shrink-0 text-[10px] font-semibold ${u.type==="doctor"?"bg-indigo-100 text-indigo-700":"bg-emerald-100 text-emerald-700"}`,children:u.name.split(" ").slice(0,2).map(v=>v[0]).join("").toUpperCase()}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[12px] text-gray-700 truncate",children:u.name}),e.jsx("p",{className:"text-[10px] text-gray-400 capitalize",children:u.type})]})]},u.id))}):e.jsx("p",{className:"text-[11px] text-gray-400 italic py-1",children:"No users assigned."})]})]})},O=["Role Basics","Permissions","Users","Review"],ge=({open:i,onClose:b})=>{const[d,f]=l.useState(0),[D,z]=l.useState([]),[C,j]=l.useState({}),[g,u]=l.useState({roleName:"",description:""}),[v,E]=l.useState([]),[I,P]=l.useState([]),[o,y]=l.useState(!1),{apiCall:A}=_(),T=()=>{d===0&&!g.roleName.trim()||d===0&&o||d<O.length-1&&f(w=>w+1)},t=()=>{d>0&&f(w=>w-1)},n=()=>{f(0),z([]),j({}),u({roleName:"",description:""}),b()},R=async()=>{try{const w=localStorage.getItem("enterpriseId"),x=Object.entries(C).map(([h,m])=>{const a=I.find(c=>c._id===h);return a&&a.isBoolean?{featureName:a.name??h,featureId:h,enabled:!!m.enabled}:{featureName:(a==null?void 0:a.name)??h,featureId:h,canView:!!m.View,canAdd:!!m.Create,canEdit:!!m.Edit,canDelete:!!m.Delete,canApprove:!!m.Approve,canExport:!!m.Export}}),s=JSON.parse(localStorage.getItem("provider")??"{}").userId,r={name:g.roleName,description:g.description,controls:x,enterpriseId:w,status:"draft",createdBy:s,modifiedBy:s,userIds:D};console.log("Submitting payload:",r),await A(!0,"api/v1/accessControl/create",L.POST,JSON.stringify(r)),n()}catch(w){console.error("Failed to create role:",w)}};return e.jsxs(ee,{anchor:"right",open:i,onClose:n,PaperProps:{sx:{width:"50%",padding:"24px",display:"flex",flexDirection:"column"}},children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("div",{children:e.jsx("h2",{className:"text-[15px] font-bold text-gray-800",children:"Create New Role"})}),e.jsx("button",{onClick:n,className:"p-2 rounded-md hover:bg-gray-100",children:e.jsx(q,{className:"size-4 text-gray-500"})})]}),e.jsx(te,{activeStep:d,alternativeLabel:!0,className:"mb-6",children:O.map((w,x)=>e.jsx(se,{children:e.jsx(re,{sx:{"& .MuiStepIcon-root":{color:x<d?"#59C383":x===d?"#204289":"grey.400"},"& .MuiStepLabel-label":{margin:"0px !important",color:"#212121 !important",fontWeight:"400 !important",fontSize:"13px !important",fontFamily:"Rubik !important"}},children:w})},w))}),e.jsx("hr",{className:"border-[#e0e0e0] mb-6"}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[d===0&&e.jsx(he,{data:g,onChange:u,onNameExists:y}),d===1&&e.jsx(me,{permissions:C,onChange:j,onFeaturesLoad:P}),d===2&&e.jsx(ue,{selectedUserIds:D,onChange:z,onUsersChange:E}),d===3&&e.jsx(fe,{basics:g,permissions:C,selectedUserIds:D,allUsers:v,onEdit:f,feature:I})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6 pt-4 border-t border-[#e0e0e0]",children:[e.jsx("button",{onClick:d===0?n:t,className:"px-4 py-2 rounded-[6px] border border-gray-300 text-[12px] font-medium text-gray-600 hover:bg-gray-50",children:d===0?"Cancel":"Back"}),e.jsx("button",{onClick:d===O.length-1?R:T,disabled:d===0&&(!g.roleName.trim()||o),className:"bg-royal-blue px-7 py-2 rounded-[6px] text-[12px] font-medium text-white disabled:opacity-50 disabled:cursor-not-allowed",children:d===O.length-1?"Submit":"Next"})]})]})},ye=()=>{const[i,b]=l.useState([]),[d,f]=l.useState(!1),[D,z]=l.useState([]),[C,j]=l.useState(!1),[g,u]=l.useState(!1),[v,E]=l.useState(null),[I,P]=l.useState(null),{apiCall:o}=_(),y=localStorage.getItem("enterpriseId"),A=async()=>
21{if(y){f(!0);try{const x=await o(!0,`api/v1/deletionGuard/blocked-users?enterpriseId=${y}`,L.GET);b(x.items??[])}catch(x){console.error("Failed to fetch blocked users:",x)}finally{f(!1)}}},T=async x=>{if(y){f(!0);try{const F=await o(!0,`api/v1/deletionGuard/audit?userId=${x}&enterpriseId=${y}`,L.GET);z(F.items??[]),j(!0)}catch(F){console.error("Failed to fetch audit entries:",F)}finally{f(!1)}}},t=(x,F)=>{E(F||x),P(x),u(!0)},n=()=>{u(!1),E(null),P(null)},R=async()=>{if(!(!y||!I))try{await o(!0,`api/v1/deletionGuard/restore/${I}`,L.POST,JSON.stringify({enterpriseId:y})),K.success("User restored successfully"),n(),A()}catch{K.error("Unable to restore user at this time")}};l.useEffect(()=>{A()},[y]);const w=l.useMemo(()=>i,[i]);return e.jsxs("div",{className:"bg-white p-4 rounded-lg border border-[#e0e0e0]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-[14px] font-semibold text-gray-800",children:"Deletion blocks"}),e.jsx("p",{className:"text-[11px] text-gray-500",children:"View users whose delete privileges are currently suspended."})]}),e.jsx("button",{onClick:A,className:"bg-royal-blue flex rounded-[6px] border-[2px] border-[#EAECF0] px-3 py-1 gap-[8px] items-center text-[12px] font-medium text-white",children:"Refresh"})]}),d?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx("div",{className:"w-5 h-5 border-2 border-[#204289] border-t-transparent rounded-full animate-spin"})}):w.length===0?e.jsx("p",{className:"text-[12px] text-gray-400 text-center py-10",children:"No blocked users found."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full text-left text-[12px] border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-200",children:[e.jsx("th",{className:"py-3 px-2",children:"User"}),e.jsx("th",{className:"py-3 px-2",children:"Blocked At"}),e.jsx("th",{className:"py-3 px-2",children:"Reason"}),e.jsx("th",{className:"py-3 px-2",children:"Actions"})]})}),e.jsx("tbody",{children:w.map(x=>e.jsxs("tr",{className:"border-b border-gray-100",children:[e.jsxs("td",{className:"py-3 px-2 text-gray-700",children:[e.jsx("div",{className:"font-medium text-gray-800",children:x.username||"Unknown user"}),e.jsx("div",{className:"text-[11px] text-gray-500",children:x.userId})]}),e.jsx("td",{className:"py-3 px-2 text-gray-500",children:new Date(x.blockedAt).toLocaleString()}),e.jsx("td",{className:"py-3 px-2 text-gray-500",children:x.reason||"—"}),e.jsxs("td",{className:"py-3 px-2 flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>T(x.userId),className:"flex rounded-[6px] border-[2px] border-[#EAECF0] px-3 py-1 items-center text-[12px] font-medium text-[#1d4ed8] bg-white",children:"Audit"}),e.jsx("button",{type:"button",onClick:()=>t(x.userId,x.username),className:"bg-emerald-600 flex rounded-[6px] px-3 py-1 items-center text-[12px] font-medium text-white",children:"Restore"})]})]},x._id))})]})}),e.jsxs(ae,{open:g,onClose:n,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px"}},children:[e.jsx(M,{sx:{background:"#ECFDF3",px:"24px",py:"14px",borderBottom:"1px solid #A7F3D0"},children:e.jsx(G,{sx:{fontFamily:"Rubik",fontWeight:600,fontSize:"14px",color:"#047857"},children:"Restore Delete Privileges"})}),e.jsx(le,{sx:{pt:"16px !important"},children:e.jsxs(G,{sx:{fontFamily:"Rubik",fontSize:"13px",color:"#313437"},children:["Are you sure you want to restore delete privileges for"," ",e.jsx(M,{component:"span",sx:{fontWeight:600},children:v}),"?"]})}),e.jsxs(ne,{sx:{px:"24px",pb:"16px"},children:[e.jsx(W,{onClick:n,sx:{textTransform:"none",borderRadius:"8px",color:"#374151",border:"1px solid #D1D5DB",px:"16px",py:"8px",fontSize:"12px"},children:"Cancel"}),e.jsx(W,{onClick:R,sx:{textTransform:"none",borderRadius:"8px",px:"16px",py:"8px",fontSize:"12px",backgroundColor:"#16A34A",color:"#fff","&:hover":{backgroundColor:"#15803D"}},children:"Restore"})]})]}),C&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/30",children:e.jsxs("div",{className:"w-[min(95%,700px)] rounded-xl bg-white p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-[15px] font-semibold",children:"Deletion audit"}),e.jsx("button",{type:"button",onClick:()=>
21j(!1),className:"flex rounded-[6px] border-[2px] border-[#EAECF0] px-3 py-1 items-center text-[12px] font-medium text-[#374151] bg-white",children:"Close"})]}),e.jsx("div",{className:"max-h-[60vh] overflow-y-auto",children:e.jsxs("table",{className:"min-w-full text-left text-[12px] border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-200",children:[e.jsx("th",{className:"py-2 px-2",children:"Time"}),e.jsx("th",{className:"py-2 px-2",children:"Path"}),e.jsx("th",{className:"py-2 px-2",children:"Outcome"}),e.jsx("th",{className:"py-2 px-2",children:"Entity"})]})}),e.jsx("tbody",{children:D.map(x=>e.jsxs("tr",{className:"border-b border-gray-100",children:[e.jsx("td",{className:"py-2 px-2 text-gray-500",children:new Date(x.createdAt).toLocaleString()}),e.jsx("td",{className:"py-2 px-2 text-gray-700",children:x.path}),e.jsx("td",{className:"py-2 px-2 text-gray-700",children:x.outcome}),e.jsx("td",{className:"py-2 px-2 text-gray-700",children:x.entity})]},x._id))})]})})]})})]})},$e=()=>{const[i,b]=l.useState([]),[d,f]=l.useState(!0),[D,z]=l.useState(null),[C,j]=l.useState(""),[g,u]=l.useState(!1),[v,E]=l.useState(!1),{apiCall:I}=_(),P=Q(),o=async()=>{f(!0);try{const t=await I(!0,"api/v1/accessControl/list?enterpriseId="+localStorage.getItem("enterpriseId"),L.GET);console.log("Roles API response:",t);const n=(t==null?void 0:t.items)??[];b(n),n.length>0&&z(n[0]._id)}catch(t){console.error("Failed to fetch roles:",t)}finally{f(!1)}};l.useEffect(()=>{o()},[]);const y=(t,n,R)=>{t.stopPropagation(),P(`/settings/rbac/edit/${n}`,{state:{roleName:R}})},A=i.filter(t=>t.name.toLowerCase().includes(C.toLowerCase())),T=t=>new Date(t).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"});return e.jsxs("div",{className:"flex flex-col gap-4 px-4 py-4",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("h1",{className:"text-[16px] font-bold text-gray-800",children:"Access Control (RBAC)"}),e.jsx("p",{className:"text-[11px] text-gray-500",children:"Manage who can access what across your organization."})]}),e.jsxs("div",{className:"bg-white p-4 rounded-lg border border-[#e0e0e0]",children:[e.jsxs("div",{className:"flex justify-end items-center gap-2 mb-4",children:[g&&e.jsx("input",{autoFocus:!0,t
21ype:"text",value:C,onChange:t=>j(t.target.value),placeholder:"Search roles...",className:"border border-gray-300 rounded-md px-3 py-1.5 text-[11px] outline-none focus:border-blue-400"}),e.jsx("button",{onClick:()=>u(t=>!t),className:"p-2 rounded-md hover:bg-gray-100",children:e.jsx(J,{className:"size-4 text-gray-500"})}),e.jsxs("button",{className:"bg-royal-blue flex rounded-[6px] border-[2px] border-[#EAECF0] px-3 py-1 gap-[8px] items-center",onClick:()=>E(!0),children:[e.jsx(ie,{className:"text-white [&&]:size-3",strokeWidth:3}),e.jsx("span",{className:"text-[12px] font-medium text-white",children:"Create Role"})]})]}),d?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx("div",{className:"w-5 h-5 border-2 border-[#204289] border-t-transparent rounded-full animate-spin"})}):A.length===0?e.jsx("p",{className:"text-[12px] text-gray-400 text-center py-10",children:"No roles found."}):e.jsx("div",{className:"grid grid-cols-2 gap-4",children:A.map(t=>{var n,R;return e.jsxs("div",{onClick:()=>z(t._id),className:"rounded-xl p-4 cursor-pointer flex flex-col gap-3 bg-white",style:{border:D===t._id?"1.5px solid #3b82f6":"1.5px solid #e0e0e0"},children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-gray-800 font-semibold text-[13px]",children:t.name}),e.jsx("div",{className:"flex items-center gap-1",children:e.jsx("button",{onClick:w=>y(w,t._id,t.name),className:"p-1.5 rounded-md hover:bg-gray-100 transition-colors",title:"Edit role",children:e.jsx(oe,{className:"size-3.5 text-gray-400 hover:text-[#204289]"})})})]}),e.jsx("p",{className:"text-[11px] text-gray-500 line-clamp-2",children:t.description||"—"}),e.jsxs("div",{className:"flex items-center gap-1.5 text-gray-500",children:[e.jsx(Z,{className:"size-3.5"}),e.jsxs("span",{className:"text-[11px]",children:[((n=t.controls)==null?void 0:n.length)??0," permission module",(((R=t.controls)==null?void 0:R.length)??0)!==1?"s":""]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-gray-500",children:[e.jsx(pe,{className:"size-3.5"}),e.jsxs("span",{className:"text-[11px]",children:[t.userCount??0," user",(t.userCount??0)!==1?"s":""," assigned"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-gray-400",children:[e.jsx(ce,{className:"size-3.5"}),e.jsxs("span",{className:"text-[11px]",children:["Updated ",T(t.modifiedAt)]})]})]},t._id)})})]}),e.jsx(ge,{open:v,onClose:()=>{E(!1),o()}}),e.jsx("div",{className:"mt-4",children:e.jsx(ye,{})})]})};export{$e 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.