1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[852],{3236:function(e,t,a){(window.__NEXT_P=window.__NEXT_P||[]).push(["/admin/users/[id]/edit",function(){return a(1101)}])},1101:function(e,t,a){"use strict";a.r(t),a.d(t,{__N_SSP:function(){return m},default:function(){return p}});var s=a(5893),n=a(7294),i=a(1163),l=a(9152),r=a(9547),o=a.n(r);let d=["amber","brisk","canyon","delta","ember","forest","harbor","jasmine","linen","marble","nectar","orbit","pine","quartz","river","sunset","timber","violet","willow","zephyr"],c=["!","@","#","$"],u=e=>e[Math.floor(Math.random()*e.length)],h=()=>{let e=u(d),t=u(d);for(;t===e;)t=u(d);let a=String(Math.floor(90*Math.random())+10),s=u(c);return"".concat(e,"-").concat(t).concat(a).concat(s)};var m=!0;function p(e){let{user:t,targetUser:a}=e,r=(0,i.useRouter)(),[d,c]=(0,n.useState)(a.name||""),[u,m]=(0,n.useState)(a.email||""),[p,b]=(0,n.useState)(a.role||"sales_user"),[x,j]=(0,n.useState)(!!a.isActive),[f,y]=(0,n.useState)(""),[v,w]=(0,n.useState)(!1),[N,g]=(0,n.useState)(""),[S,k]=(0,n.useState)(""),[C,_]=(0,n.use
1State)(""),[E,P]=(0,n.useState)(!1),F=!!a.isSuperAdmin,T=F&&t.id===a.id,A=!(F&&!T),B=async()=>{if(f)try{await navigator.clipboard.writeText(f),g("Password copied.")}catch(e){g("Could not copy password.")}},L=async e=>{e.preventDefault(),k(""),_(""),P(!0);try{let e=await fetch("/api/admin/users/".concat(a.id),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:d,email:u,role:p,isActive:x,newPassword:f})}),t=await e.json().catch(()=>({}));if(!e.ok){k(t.error||"Failed to update user."),P(!1);return}_("User updated."),y(""),w(!1),g("")}catch(e){k("Failed to update user. Please try again.")}finally{P(!1)}},D=async()=>{if(!F&&confirm("Delete this user permanently?")){k(""),_(""),P(!0);try{let e=await fetch("/api/admin/users/".concat(a.id),{method:"DELETE"}),t=await e.json().catch(()=>({}));if(!e.ok){k(t.error||"Failed to delete user."),P(!1);return}r.push("/admin/users")}catch(e){k("Failed to delete user. Please try again."),P(!1)}}};return(0,s.jsx)(l.L3,{user:t,title:"Edit User",children:(0,s.jsxs)("form",{className:o().form,onSubmit:L,children:[S&&(0,s.jsx)("p",{className:o().error,children:S}),C&&(0,s.jsx)("p",{className:o().success,children:C}),F&&(0,s.jsxs)("p",{className:o().helper,children:["This is the protected superadmin account. It cannot be deactivated, role-changed, or deleted.",T?" You can still reset your own password.":""]}),(0,s.jsxs)("div",{className:o().field,children:[(0,s.jsx)("label",{htmlFor:"name",children:"Name"}),(0,s.jsx)("input",{id:"name",value:d,onChange:e=>c(e.target.value),required:!0})]}),(0,s.jsxs)("div",{className:o().field,children:[(0,s.jsx)("label",{htmlFor:"email",children:"Email"}),(0,s.jsx)("input",{id:"email",type:"email",value:u,onChange:e=>m(e.target.value),required:!0,disabled:F})]}),(0,s.jsxs)("div",{className:o().field,children:[(0,s.jsx)("label",{htmlFor:"role",children:"Role"}),(0,s.jsxs)("select",{id:"role",value:p,onChange:e=>b(e.target.value),disabled:F,children:[(0,s.jsx)("option",{value:"admin",children:"admin"}),(0,s.jsx)("option",{value:"sales_user",children:"sales_user"})]})]}),(0,s.jsxs)("div",{className:o().field,children:[(0,s.jsx)("label",{htmlFor:"newPassword",children:"Reset Password (optional)"}),(0,s.jsx)("input",{id:"newPassword",type:v?"text":"password",value:f,onChange:e=>{y(e.target.value),g("")},minLength:10,disabled:!A}),(0,s.jsxs)("div",{className:o().inlineActions,children:[(0,s.jsx)("button",{className:o().secondaryButton,type:"button",onClick:()=>{A&&(y(h()),w(!0),g(""))},disabled:!A,children:"Generate Easy Password"}),(0,s.jsx)("button",{className:o().ghostButton,type:"button",onClick:()=>w(e=>!e),disabled:!A,children:v?"Hide":"Show"}),(0,s.jsx)("button",{className:o().ghostButton,type:"button",onClick:B,disabled:!A||!f,children:"Copy"})]}),(0,s.jsx)("p",{className:o().helper,children:"Leave blank to keep existing password."}),N?(0,s.jsx)("p",{className:o().helper,children:N}):null]}),(0,s.jsxs)("label",{className:o().checkboxRow,children:[(0,s.jsx)("input",{type:"checkbox",checked:x,onChange:e=>j(e.target.checked),disabled:F}),(0,s.jsx)("span",{children:"Active"})]}),(0,s.jsxs)("div",{className:o().actions,children:[(0,s.jsx)("button",{className:o().button,type:"submit",disabled:E,children:E?"Saving...":"Save Changes"}),(0,s.jsx)("button",{type:"button",className:o().dangerButton,onClick:D,disabled:E||F||t.id===a.id,children:"Delete User"}),(0,s.jsx)("button",{type:"button",className:o().ghostButton,onClick:()=>r.push("/admin/users"),children:"Cancel"})]})]})})}p.noLayout=!0}},function(e){e.O(0,[774,888,179],function(){return e(e.s=3236)}),_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.