1 line
5.8 KiB
JavaScript
1 line
5.8 KiB
JavaScript
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[633],{33356:function(e,n,t){(window.__NEXT_P=window.__NEXT_P||[]).push(["/admin/users/add-user",function(){return t(28043)}])},48150:function(e,n,t){"use strict";t.d(n,{Z:function(){return h}});var r=t(85893),o=t(77827),s=t(94495),i=t(60),l=t(5606),a=t(25808),d=t(67294),u=t(79265),c=t(98388);function f(e){var n,t,s,i;let{isPasswordConfirmed:l,newUser:a,setNewUser:d,setIsPasswordConfirmed:u}=e,c=!!(l&&(null===(n=a.password)||void 0===n?void 0:n.match(/./))&&(null===(t=a.confirmed_password)||void 0===t?void 0:t.match(/./)));return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(o.Z,{placeholder:"Password",title:"Password",type:"password",changeHandler:e=>{d(n=>({...n,password:e}))},validity:{isValid:!((null===(s=a.password)||void 0===s?void 0:s.match(/./))&&(null===(i=a.confirmed_password)||void 0===i?void 0:i.match(/./)))||c,msg:"Passwords don't match"},required:!0,showLabel:!0}),(0,r.jsx)(o.Z,{placeholder:"Confirm Password",title:"Confirm Password",type:"password",changeHandler:e=>{d(n=>({...n,confirmed_password:e})),u(e==a.password)},showLabel:!0})]})}function h(e){var n,t,h,p;let{new_deployment_user:m,existing_user:w}=e,v=function(e){let{new_deployment_user:n,existing_user:t}=e,{pageProps:r}=(0,d.useContext)(l.AppContext),[o,s]=(0,d.useState)(t||{}),{loading:i,setLoading:u}=(0,a.Z)(),[c,f]=(0,d.useState)(!1);return{newUser:o,setNewUser:s,loading:i,setLoading:u,isPasswordConfirmed:c,setIsPasswordConfirmed:f,pageProps:r}}({new_deployment_user:m,existing_user:w}),{newUser:y,setNewUser:g,loading:j,setLoading:x,isPasswordConfirmed:_,setIsPasswordConfirmed:b,pageProps:N}=v,Z=!!(_&&(null===(n=y.password)||void 0===n?void 0:n.match(/./))&&(null===(t=y.confirmed_password)||void 0===t?void 0:t.match(/./)));return(0,r.jsx)("form",{onSubmit:e=>{e.preventDefault()},children:(0,r.jsxs)(i.Z,{className:"w-full items-stretch gap-6",children:[(0,r.jsx)(o.Z,{placeholder:"Eg. John",title:"First Name",defaultValue:null==w?void 0:w.first_name,changeHandler:e=>{g(n=>({...n,first_name:e}))},required:!0,showLabel:!0}),(0,r.jsx)(o.Z,{placeholder:"Eg. Doe",title:"Last Name",defaultValue:null==w?void 0:w.last_name,changeHandler:e=>{g(n=>({...n,last_name:e}))},showLabel:!0}),(0,r.jsx)(o.Z,{placeholder:"Email Address",title:"Email",type:"email",defaultValue:null==w?void 0:w.email,changeHandler:e=>{g(n=>({...n,email:e}))},required:!0,showLabel:!0}),(null===(h=N.user)||void 0===h?void 0:h.id)&&!(null==w?void 0:w.is_super_admin)?(0,r.jsx)(o.Z,{placeholder:"Username",title:"Username",defaultValue:null==w?void 0:w.username,changeHandler:e=>{g(n=>({...n,username:e}))},validationRegex:/^[a-z0-9\-]{3,}$/,info:(0,r.jsxs)(r.Fragment,{children:["Allowed characters:"," ",(0,r.jsx)("code",{children:(0,r.jsx)("b",{children:"a-z, 0-9, -"})}),"."]}),wrapperWrapperProps:{className:(0,c.m6)("items-start!",(null==w?void 0:w.username)?"opacity-70 pointer-events-none":"")},disabled:!!(null==w?void 0:w.username),required:!0,showLabel:!0}):null,(null==w?void 0:w.id)?null:(0,r.jsx)(f,{...v}),(0,r.jsx)(s.Z,{title:"Login",onClick:()=>{var e;if(!Z)return;let n=(null===(e=N.user)||void 0===e?void 0:e.id)?"Add New User?":"Create Super Admin Account?";window.confirm(n)&&(x(!0),(0,u.Z)((null==w?void 0:w.id)?"/api/admin/edit-user":"/api/auth/signup",{method:"POST",body:{new_user:y,user_id:null==w?void 0:w.id}}).then(e=>{if(e.success){var n;(null===(n=N.user)||void 0===n?void 0:n.id)?window.location.pathname="/admin/users":window.location.reload()}else window.alert(e.msg||e.error||"New User Creation Failed!"),console.log("res",e)}).finally(()=>{setTimeout(()=>{x(!1)},5e3)}))},loading:j,children:(null==w?void 0:w.id)?"Edit User":(null===(p=N.user)||void 0===p?void 0:p.super_admin)?"Add User":"Signup"})]})})}},28043:function(e,n,t){"use strict";t.r(n),t.d(n,{__N_SSP:function(){return f},default:function(){return h}});var r=t(85893),o=t(67294),s=t(5606),i=t(60705),l=t(33028),a=t(48150),d=t(60);function u(){let{pageProps:e}=(0,o.useContext)(s.AppContext);return(0,r.jsxs)(o.Fragment,{children:[(0,r.jsx)(l.Z,{title:"Add New User"}),(0,r.jsx)(i.Z,{}),(0,r.jsx)(d.Z,{className:"grid-cell-content max-w-[600px]",children:(0,r.jsx)(a.Z,{})})]})}var c=t(89350),f=!0;function h(){return(0,r.jsx)(c.Z,{children:(0,r.jsx)(u,{})})}},79265:function(e,n,t){"use strict";t.d(n,{Z:function(){return i}});var r=t(96486),o=t.n(r),s={stringify:function(e,n,t){try{return JSON.stringify(e,n||void 0,t)}catch(e){return}}};async function i(e,n){let t;let r={"Content-Type":"application/json"};(null==n?void 0:n.csrfKey)&&n.csrfValue&&(r[n.csrfKey]=n.csrfValue);let i=e;if((null==n?void 0:n.query)&&(i+=function(e){let n="?";if("object"!=typeof e)return console.log("Invalid Query type"),n;if(Array.isArray(e))return console.log("Query is an Array. This is invalid."),n;if(!e)return console.log("No Query provided."),n;let t=Object.keys(e),r=[];return t.forEach(n=>{if(!n||!e[n])return;let t=e[n];if("object"==typeof t){let e=s.stringify(t);r.push("".concat(n,"=").concat(encodeURIComponent(String(e))))}else"string"==typeof t||"number"==typeof t?r.push("".concat(n,"=").concat(encodeURIComponent(t))):r.push("".concat(n,"=").concat(String(t)))}),n+=r.join("&")}(n.query)),"string"==typeof n)try{t="post"===n?(await fetch(i,{method:n,headers:r})).json():(await fetch(i)).json()}catch(e){console.log("FetchAPI error #1:",e.message),t=null}else if("object"==typeof n)try{let e;if(n.body&&"object"==typeof n.body){let e=o().cloneDeep(n.body);n.body=JSON.stringify(e)}if(n.headers){n.headers=o().merge(n.headers,r);let t={...n};e=await fetch(i,t)}else{let t={...n,headers:r};e=await fetch(i,t)}t=e.json()}catch(e){console.log("FetchAPI error #2:",e.message),t=null}else try{let e=await fetch(i);t=await e.json()}catch(e){console.log("FetchAPI error #3:",e.message),t=null}return t}},9008:function(e,n,t){e.exports=t(23867)}},function(e){e.O(0,[662,75,664,433,7,827,910,888,774,179],function(){return e(e.s=33356)}),_N_E=e.O()}]); |