(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[335],{21991:function(e,t,n){Promise.resolve().then(n.bind(n,47963))},29116:function(e,t,n){"use strict";n.d(t,{Gi:function(){return y},Nq:function(){return a},OL:function(){return f},Rf:function(){return s},Y:function(){return d},Zw:function(){return c},a6:function(){return x},eJ:function(){return h},hn:function(){return p},ke:function(){return m},tS:function(){return i},vw:function(){return l},xZ:function(){return o},yM:function(){return u}});let r=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};try{let n=await fetch("".concat("https://milimanibackend.sigraelfasolutions.com/api","/").concat(e),{credentials:"include",...t});if(!n.ok){let e=await n.text();throw{message:"API Error: ".concat(n.status," ").concat(n.statusText),status:n.status,statusText:n.statusText,body:e}}return await n.json()}catch(e){throw console.error("API Fetch Error:",e),e}},s=async()=>r("users"),a=async(e,t)=>r("users/".concat(e),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),c=async()=>r("members"),o=async()=>r("visitors"),i=async e=>r("visitors/".concat(e)),l=async()=>r("events"),d=async e=>r("events/".concat(e)),u=async e=>r("events",{method:"POST",body:JSON.stringify(e)}),h=async(e,t)=>r("events/".concat(e),{method:"PUT",body:JSON.stringify(t)}),p=async()=>r("prayers"),m=async e=>r("prayers",{method:"POST",body:JSON.stringify(e)}),f=async(e,t)=>r("prayers/".concat(e),{method:"PUT",body:JSON.stringify(t)}),x=async()=>r("inquiries"),y=async()=>r("cell-groups")},47963:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return c}});var r=n(57437),s=n(29116),a=n(2265);function c(){let[e,t]=(0,a.useState)([]),[n,c]=(0,a.useState)("user");(0,a.useEffect)(()=>{(async()=>{try{let e=await (0,s.Rf)();t(e);let n=localStorage.getItem("role")||"user";c(n)}catch(e){console.error("Error fetching users:",e)}})()},[]);let o=async(e,n)=>{try{await (0,s.Nq)(e,{approved:!n}),t(t=>t.map(t=>t.id===e?{...t,approved:!n}:t))}catch(e){console.error("Error updating approval:",e)}},i=async(e,n)=>{try{await (0,s.Nq)(e,{role:n}),t(t=>t.map(t=>t.id===e?{...t,role:n}:t))}catch(e){console.error("Error updating role:",e)}};return(0,r.jsxs)("div",{className:"bg-white p-6 m-4 rounded-md",children:[(0,r.jsx)("h1",{className:"text-2xl font-bold mb-4",children:"User Management"}),(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsxs)("table",{className:"min-w-full bg-gray-100 text-sm rounded-md",children:[(0,r.jsx)("thead",{className:"bg-gray-300",children:(0,r.jsxs)("tr",{children:[(0,r.jsx)("th",{className:"p-3 text-left",children:"Name"}),(0,r.jsx)("th",{className:"p-3 text-left",children:"Email"}),(0,r.jsx)("th",{className:"p-3 text-left",children:"Role"}),(0,r.jsx)("th",{className:"p-3 text-left",children:"Approved"}),(0,r.jsx)("th",{className:"p-3 text-left",children:"Joined"}),(0,r.jsx)("th",{className:"p-3 text-left",children:"Actions"})]})}),(0,r.jsx)("tbody",{children:e.map(e=>(0,r.jsxs)("tr",{className:"border-t border-gray-300 hover:bg-gray-200 transition",children:[(0,r.jsxs)("td",{className:"p-3",children:[e.first_name," ",e.last_name]}),(0,r.jsx)("td",{className:"p-3",children:e.email}),(0,r.jsx)("td",{className:"p-3 capitalize",children:e.role}),(0,r.jsx)("td",{className:"p-3",children:e.approved?"Yes":"No"}),(0,r.jsx)("td",{className:"p-3",children:new Date(e.createdAt).toLocaleDateString()}),(0,r.jsxs)("td",{className:"p-3 flex gap-2 items-center",children:[(0,r.jsx)("button",{onClick:()=>o(e.id,e.approved),className:"px-3 py-1 text-white rounded text-xs ".concat(e.approved?"bg-red-500 hover:bg-red-600":"bg-green-600 hover:bg-green-700"),children:e.approved?"Unapprove":"Approve"}),"superadmin"===n&&(0,r.jsxs)("select",{value:e.role,onChange:t=>i(e.id,t.target.value),className:"p-1 text-sm border rounded",children:[(0,r.jsx)("option",{value:"user",children:"User"}),(0,r.jsx)("option",{value:"admin",children:"Admin"}),(0,r.jsx)("option",{value:"superadmin",children:"Superadmin"})]})]})]},e.id))})]})})]})}}},function(e){e.O(0,[971,117,744],function(){return e(e.s=21991)}),_N_E=e.O()}]);