1!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},s=(new e.Error).stack;s&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[s]="a1fc620a-e326-43e4-a581-6496b1cea2a1",e._sentryDebugIdIdentifier="sentry-dbid-a1fc620a-e326-43e4-a581-6496b1cea2a1")}catch(e){}}(),(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4594],{29517:(e,s,r)=>{"use strict";r.d(s,{Ep:()=>i,O0:()=>t,nW:()=>o,xr:()=>l});var a=r(13415);let t=async()=>{let{data:{session:e}}=await a.N.auth.getSession();if(!(null==e?void 0:e.user))throw Error("User must be logged in");try{console.log("getRoles");let{data:e,error:s}=await a.N.from("role_permissions").select("role_name");if(s)throw Error(s.message);return e.map(e=>e.role_name)}catch(e){return console.error("Error fetching roles:",e),[]}},l=async()=>{let{data:{session:e}}=await a.N.auth.getSession();if(!(null==e?void 0:e.user))throw Error("User must be logged in");try{let{data:e,error:s}=await a.N.from("role_permissions").select("role_name, default_permissions");if(s)throw Error(s.message);return e.map(e=>({roleName:e.role_name,defaultPermissions:e.default_permissions}))}catch(e){return console.error("Error fetching roles:",e),[]}},i=async()=>{let{data:{session:e}}=await a.N.auth.getSession();if(!(null==e?void 0:e.user))throw Error("User must be logged in");try{console.log("getUniquePermissions");let{data:e,error:s}=await a.N.from("role_permissions").select("role_name, default_permissions");if(s)throw Error(s.message);let r=e.flatMap(e=>e.default_permissions);return[...new Set(r)]}catch(e){return console.error("Error fetching unique permissions:",e),[]}},o=async(e,s)=>{let{data:{session:r}}=await a.N.auth.getSession();if(!(null==r?void 0:r.user))throw Error("User must be logged in");try{console.log("updateDefaultPermissions");let{data:r,error:t,status:l}=await a.N.from("role_permissions").update({default_permissions:s}).eq("role_name",e);if(console.log("update call status",l),t)throw Error(t.message);return r}catch(e){return console.error("Error updating permissions:",e),null}}},32257:(e,s,r)=>{"use strict";r.d(s,{A:()=>a});let a=(0,r(17963).A)("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]])},45328:(e,s,r)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/manage-users",function(){return r(61417)}])},45806:(e,s,r)=>{"use strict";r.d(s,{AB:()=>i,CF:()=>n,N6:()=>d,S0:()=>c,hH:()=>l,mJ:()=>o,v_:()=>t});var a=r(13415);async function t(e,s,r,t){let{error:l}=await a.N.from("workspace_members").update({role:r}).eq("workspace_id",e).eq("user_id",s);if(l)throw Error(l.message);if(t.length){let{error:e}=await a.N.from("users").update({user_permissions:t}).eq("id",s);if(e)throw Error(e.message)}}async function l(e,s){let{error:r}=await a.N.from("workspace_members").update({is_active:!1}).eq("workspace_id",e).eq("user_id",s);if(r)throw Error(r.message)}async function i(e){let{data:s,error:r}=await a.N.from("workspace_members").select("user_id, role, is_active, users:user_id (id, email, first_name, last_name, user_permissions)").eq("workspace_id",e).eq("is_active",!0);if(r)throw Error(r.message);return(null!=s?s:[]).map(e=>{var s,r,a,t,l,i,o,n,c,d;return{id:null!=(i=null==(s=e.users)?void 0:s.id)?i:e.user_id,email:null!=(o=null==(r=e.users)?void 0:r.email)?o:"",firstName:null!=(n=null==(a=e.users)?void 0:a.first_name)?n:"",lastName:null!=(c=null==(t=e.users)?void 0:t.last_name)?c:"",role:e.role,permissions:null!=(d=null==(l=e.users)?void 0:l.user_permissions)?d:[]}})}async function o(e,s){try{let{data:{session:r}}=await a.N.auth.getSession();if(!(null==r?void 0:r.user))throw Error("User must be logged in");let{data:t,error:l}=await a.N.from("users").select("settings").eq("id",e).single();l&&console.error(l);let i={...null==t?void 0:t.settings,...s};await a.N.from("users").update({settings:i}).eq("id",e);let{data:o,error:n}=await a.N.from("users").select("settings").eq("id",e).single();return n&&console.error(n),o||null}catch(e){return console.error("Error updating user settings:",e),!1}}async function n(){console.log("getAllUsers");try{let{data:e,error:s}=await a.N.from("users").select("*");if(s)return console.error("Error fetching users:",s),[];return e.map(e=>({id:e.id,email:e.email,firstName:e.first_name,lastName:e.last_name,role:e.role,company:e.company,createdAt:e.created_at,updatedAt:e.updated_at,permissions:e.user_permissions,avatar:e.avatar,settings:e.settings}))||[]}catch(e){return console.error("Error fetching all users:",e),[]}}let c=async(e,s)=>{let{data:{session:r}}=await a.N.auth.getSession();if(!(null==r?void 0:r.user))throw Error("User must be logged in");try{let{data:r,error:t}=await a.N.from("users").update({role:s}).eq("id",e);if(t)throw Error(t.message);return r}catch(e){return console.error("Error updating user role:",e),null}},d=async(e,s)=>{let{data:{session:r}}=await a.N.auth.getSession();if(!(null==r?void 0:r.user))throw Error("User must be logged in");try{let{data:r,error:t}=await a.N.from("users").update({user_permissions:s}).eq("id",e);if(t)throw t;return r}catch(e){throw console.error("Error updating user permissions:",e),e}}},54410:(e,s,r)=>{"use strict";r.d(s,{A:()=>a});let a=(0,r(17963).A)("Shield",[["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",ke
1y:"oel41y"}]])},61417:(e,s,r)=>{"use strict";r.r(s),r.d(s,{default:()=>g});var a=r(37876),t=r(14232),l=r(45806),i=r(29517),o=r(54410),n=r(32257);function c(e){let{user:s,allPermissions:r,onSave:l,onCancel:i}=e,[c,d]=(0,t.useState)(s.permissions||[]);return(0,a.jsx)("div",{className:"fixed inset-0 flex items-center justify-center z-50 bg-gray-900 bg-opacity-50",children:(0,a.jsxs)("div",{className:"bg-white p-6 rounded-lg max-w-2xl w-full max-h-[90vh]",children:[(0,a.jsx)("div",{className:"px-6 py-4 border-b border-gray-200 flex items-center justify-between",children:(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)(o.A,{className:"h-6 w-6 text-indigo-600"}),(0,a.jsxs)("h2",{className:"ml-3 text-xl font-semibold text-gray-900",children:["Edit Permissions for ",s.firstName," ",s.lastName]})]})}),(0,a.jsx)("div",{className:"px-6 py-4 max-h-[60vh] overflow-y-auto",children:(0,a.jsx)("div",{className:"space-y-6",children:(0,a.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:r.map(e=>(0,a.jsxs)("label",{className:"relative flex items-center p-4 border rounded-lg hover:border-indigo-500 cursor-pointer",children:[(0,a.jsx)("input",{type:"checkbox",className:"hidden",checked:c.includes(e),onChange:()=>{d(s=>s.includes(e)?s.filter(s=>s!==e):[...s,e])}}),(0,a.jsx)("div",{className:"flex-shrink-0 h-6 w-6 mr-3 rounded-full flex items-center justify-center ".concat(c.includes(e)?"bg-indigo-600":"border-2 border-gray-300"),children:c.includes(e)&&(0,a.jsx)(n.A,{className:"h-4 w-4 text-white"})}),(0,a.jsx)("span",{className:"text-sm font-medium text-gray-900",children:e.replace(":",": ")})]},e))})})}),(0,a.jsxs)("div",{className:"mt-4 flex justify-end",children:[(0,a.jsx)("button",{onClick:i,className:"mr-2 text-gray-500",children:"Cancel"}),(0,a.jsx)("button",{onClick:()=>l(s.id,c),className:"px-4 py-2 text-white bg-blue-600 rounded",children:"Save"})]})]})})}let d=e=>{let{user:s,onSave:r,onCancel:l}=e,[i,o]=(0,t.useState)(s),n=e=>{let{name:s,value:r}=e.target;o(e=>({...e,[s]:r}))};return(0,a.jsx)("div",{className:"fixed inset-0 flex justify-center items-center bg-gray-500 bg-opacity-50",children:(0,a.jsx)("div",{className:"bg-white dark:bg-gray-800 shadow rounded-lg overflow-hidden max-w-2xl w-full max-h-[90vh]",children:(0,a.jsxs)("div",{className:"px-6 py-4 border-b border-gray-200 dark:border-gray-700",children:[(0,a.jsx)("h2",{className:"text-xl font-semibold mb-4 text-gray-400",children:"Edit User Details"}),(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{htmlFor:"firstName",className:"block text-sm font-medium text-gray-400",children:"First Name"}),(0,a.jsx)("input",{type:"text",id:"firstName",name:"firstName",value:i.firstName,onChange:n,className:"mt-1 px-4 py-2 border rounded-md w-full"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{htmlFor:"lastName",className:"block text-sm font-medium text-gray-400",children:"Last Name"}),(0,a.jsx)("input",{type:"text",id:"lastName",name:"lastName",value:i.lastName,onChange:n,className:"mt-1 px-4 py-2 border rounded-md w-full"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{htmlFor:"title",className:"block text-sm font-medium text-gray-400",children:"Company"}),(0,a.jsx)("input",{type:"text",id:"title",name:"title",value:i.company,onChange:n,className:"mt-1 px-4 py-2 border rounded-md w-full"})]})]}),(0,a.jsxs)("div",{className:"mt-4 flex justify-end gap-4",children:[(0,a.jsx)("button",{onClick:l,className:"px-4 py-2 bg-gray-300 text-gray-700 rounded-md",children:"Cancel"}),(0,a.jsx)("button",{onClick:()=>{r(i)},className:"px-4 py-2 bg-blue-500 text-white rounded-md",children:"Save"})]})]})})})};var u=r(65333),m=r(89099),x=r(55892),p=r(32446);function h(){let[e,s]=(0,t.useState)([]),[r,o]=(0,t.useState)([]),[n,h]=(0,t.useState)([]),[g,y]=(0,t.useState)(null),[f,N]=(0,t.useState)(null),[b,w]=(0,t.useState)(null),[j,v]=(0,t.useState)(1),[_,k]=(0,t.useState)("firstName"),[C,E]=(0,t.useState)("asc"),[S,A]=(0,t.useState)({role:"",company:""}),[q,U]=(0,t.useState)(""),[L,F]=(0,t.useState)(!0),P=(0,t.useRef)(null),R=(0,m.useRouter)(),{user:D}=(0,x.A)(),I=e.sort((e,s)=>e[_]<s[_]?"asc"===C?-1:1:e[_]>s[_]?"asc"===C?1:-1:0).filter(e=>{let s=e.role.toLowerCase().includes(S.role.toLowerCase()),r=e.company.toLowerCase().includes(S.company.toLowerCase());return s&&r}).filter(e=>{let s="".concat(e.firstName," ").concat(e.lastName).toLowerCase(),r=q.toLowerCase();return s.includes(r)||e.email.toLowerCase().includes(r)||e.company.toLowerCase().includes(r)}),M=5*j,O=I.slice(M-5,M),T=e=>v(e),z=e=>{_===e?E("asc"===C?"desc":"asc"):(k(e),E("asc"))},V=(e,s)=>{A({...S,[s]:e.target.value})},W=async(e,r)=>{try{await (0,l.S0)(e,r),s(s=>s.map(s=>s.id===e?{...s,role:r}:s)),p.oR.success("User Role Updated Successfully")}catch(e){console.error("Error updating user role:",e)}},X=async(e,r)=>{try{await (0,l.N6)(e,r),s(s=>s.map(s=>s.id===e?{...s,permissions:r}:s)),y(null)}catch(e){console.log(e instanceof Error?e.message:"Failed to update permissions")}},B=Math.ceil(I.length/5);return(0,t.useEffect)(()=>{!async function(){console.log("fetchUsersAndRoles"),F(!0);let e=await (0,l.CF)(),r=await (0,i.O0)(),a=await (0,i.Ep)();console.log("Permissions Data Fetched"),s(e),o(r),h(a),F(!1)}()},[]),(0,t.useEffect)(()=>{let e=e=>{P.current&&!P.current.contains(e.target)&&w(null)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[]),(0,a.jsxs)("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8",children:[(0,a.jsxs)("div",{className:"mb-4 flex space-x-4",children:[(0,a.jsx)("input",{type:"text",placeholder:"Filter by Role",value:S.role,onChange:e=>V(e,"role"),className:"px-4 py-2 border rounded-md"}),(0,a.jsx)("input",{type:"text",placeholder:"Filter by Company",value:S.company,onChange:e=>V(e,"company"),className:"px-4 py-2 border rounded-md"}),(0,a.jsx)("input",{type:"text",placeholder:"Search by name, email, or agency",value:q,onChange:e=>{U(e.target.value)},className:"px-4 py-2 border rounded-md w-full"})]}),(0,a.jsx)("div",{className:"relative overflow-x-auto",children:L?(0,a.jsx)("div",{className:"animate-pulse",children:(0,a.jsxs)("table",{className:"w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400",children:[(0,a.jsx)("thead",{className:"text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400",children:(0,a.jsxs)("tr",{children:[(0,a.jsx)("th",{scope:"col",className:"px-6 py-3",children:(0,a.jsx)("div",{className:"bg-gray-300 h-4 w-32 rounded"})}),(0,a.jsx)("th",{scope:"col",className:"px-6 py-3",children:(0,a.jsx)("div",{className:"bg-gray-300 h-4 w-32 rounded"})}),(0,a.jsx)("th",{scope:"col",className:"px-6 py-3",children:(0,a.jsx)("div",{className:"bg-gray-300 h-4 w-32 rounded"})}),(0,a.jsx)("th",{scope:"col",className:"px-6 py-3",children:(0,a.jsx)("div",{className:"bg-gray-300 h-4 w-32 rounded"})}),(0,a.jsx)("th",{scope:"col",className:"px-6 py-3",children:(0,a.jsx)("div",{className:"bg-gray-300 h-4 w-32 rounded"})})]})}),(0,a.jsx)("tbody",{children:[...Array(10)].map((e,s)=>(0,a.jsxs)("tr",{className:"bg-white border-b dark:bg-gray-800 dark:border-gray-700",children:[(0,a.jsx)("td",{className:"px-6 py-4",children:(0,a.jsx)("div",{className:"bg-gray-200 h-4 w-32 rounded"})}),(0,a.jsx)("td",{className:"px-6 py-4",children:(0,a.jsx)("div",{className:"bg-gray-200 h-4 w-32 rounded"})}),(0,a.jsx)("td",{className:"px-6 py-4",children:(0,a.jsx)("div",{className:"bg-gray-200 h-4 w-32 rounded"})}),(0,a.jsx)("td",{className:"px-6 py-4",children:(0,a.jsx)("div",{className:"bg-gray-200 h-4 w-32 rounded"})}),(0,a.jsx)("td",{className:"px-6 py-4",children:(0,a.jsx)("div",{className:"bg-gray-200 h-4 w-32 rounded"})})]},s))})]})}):(0,a.jsxs)("table",{className:"w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400",children:[(0,a.jsx)("thead",{className:"text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400",children:(0,a.jsxs)("tr",{children:[(0,a.jsx)("th",{scope:"col",className:"px-6 py-3 cursor-pointer",onClick:()=>z("email"),children:"Email"}),(0,a.jsx)("th",{scope:"col",className:"px-6 py-3 cursor-pointer",onClick:()=>z("firstName"),children:"First Name"}),(0,a.jsx)("th",{scope:"col",className:"px-6 py-3 cursor-pointer",onClick:()=>z("lastName"),children:"Last Name"}),(0,a.jsx)("th",{scope:"col",className:"px-6 py-3 cursor-pointer",onClick:()=>z("role"),children:"Role"}),(0,a.jsx)("th",{scope:"col",className:"px-6 py-3 cursor-pointer",onClick:()=>z("company"),children:"Company"}),(0,a.jsx)("th",{scope:"col",className:"px-6 py-3",children:"Actions"})]})}),(0,a.jsx)("tbody",{children:null==O?void 0:O.map((e,s)=>(0,a.jsxs)("tr",{className:"bg-white border-b dark:bg-gray-800 dark:border-gray-700 cursor-pointer",children:[(0,a.jsx)("th",{scope:"row",className:"px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white",children:e.email}),(0,a.jsx)("td",{className:"px-6 py-4",children:null==e?void 0:e.firstName}),(0,a.jsx)("td",{className:"px-6 py-4",children:null==e?void 0:e.lastName}),(0,a.jsx)("td",{className:"px-6 py-4",children:(0,a.jsx)("select",{value:e.role,onChange:s=>W(e.id,s.target.value),className:"px-4 py-2 border rounded-md",children:r.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})}),(0,a.jsx)("td",{className:"px-6 py-4",children:null==e?void 0:e.company}),(0,a.jsx)("td",{className:"px-6 py-4 whitespace-nowrap text-right text-sm font-medium",children:(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)("button",{onClick:()=>w(b===e.id?null:e.id),className:"text-gray-400 hover:text-gray-500",children:(0,a.jsx)(u.A,{className:"h-5 w-5"})}),b===e.id&&(0,a.jsx)("div",{ref:P,className:"absolute right-0 mt-2 w-48 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 z-10",children:(0,a.jsxs)("div",{className:"py-1 flex flex-col",children:[(0,a.jsx)("button",{onClick:()=>{N(e),w(null)},className:"w-full text-left px-4 py-2 text-sm text-gray-700 hover:bg-gray-100",children:"Edit User"}),(0,a.jsx)("button",{onClick:()=>{y(e),w(null)},className:"w-full text-left px-4 py-2 text-sm text-blue-500 hover:bg-gray-100",children:"Edit Permissions"}),(0,a.jsx)("button",{onClick:()=>{R.push("/manage-user-workspace/".concat(null==e?void 0:e.id)),w(null)},className:"w-full text-left px-4 py-2 text-sm text-green-500 hover:bg-gray-100",children:"Edit Worksp
1ace"})]})})]})})]},s))})]})}),(0,a.jsxs)("div",{className:"mt-4 flex justify-center",children:[(0,a.jsx)("button",{onClick:()=>T(j-1),disabled:1===j,className:"px-4 py-2 bg-gray-300 text-gray-700 rounded-l-md disabled:opacity-50",children:"Previous"}),[...Array(B)].map((e,s)=>(0,a.jsx)("button",{onClick:()=>T(s+1),className:"px-4 py-2 mx-1 rounded-md ".concat(j===s+1?"bg-blue-500 text-white":"bg-gray-200 text-gray-700"),children:s+1},s)),(0,a.jsx)("button",{onClick:()=>T(j+1),disabled:j===B,className:"px-4 py-2 bg-gray-300 text-gray-700 rounded-r-md disabled:opacity-50",children:"Next"})]}),g&&(0,a.jsx)(c,{user:g,allPermissions:n,onSave:(e,s)=>X(e,s),onCancel:()=>y(null)}),f&&(0,a.jsx)(d,{user:f,onSave:e=>{s(s=>s.map(s=>s.id===e.id?e:s)),N(null)},onCancel:()=>{N(null)}})]})}function g(){return(0,a.jsx)(h,{})}},65333:(e,s,r)=>{"use strict";r.d(s,{A:()=>a});let a=(0,r(17963).A)("EllipsisVertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]])}},e=>{e.O(0,[636,6593,8792],()=>e(e.s=45328)),_N_E=e.O()}]);
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.