text: (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[892],{2261:function(e,s,n){(window.__NEXT_P=window.__NEXT_P||[]).push(["/users",function(){return n(5100)}])},7889:function(e,s,n){"use strict";n.d(s,{A:function(){return m},U:function(){return h}});var r=n(5893),t=n(1163),i=n(7536),a=n(5496),c=n(4231),l=n(2546),d=n(1785);function o(e,s,n){return s in e?Object.defineProperty(e,s,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[s]=n,e}function u(e){for(var s=1;s<arguments.length;s++){var n=null!=arguments[s]?arguments[s]:{},r=Object.keys(n);"function"===typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter((function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable})))),r.forEach((function(s){o(e,s,n[s])}))}return e}function m(e){var s,n,o,m,h,f=function(e){return d.W4.register(e).then((function(){d.Ak.success("User added",{keepAfterRouteChange:!0}),p.push(".")})).catch(d.Ak.error)},x=function(e,s){return d.W4.update(e,s).then((function(){d.Ak.success("User updated",{keepAfterRouteChange:!0}),p.push("..")})).catch(d.Ak.error)},j=null===e||void 0===e?void 0:e.user,b=!j,p=(0,t.useRouter)(),N=c.Ry().shape({firstName:c.Z_().required("First Name is required"),lastName:c.Z_().required("Last Name is required"),username:c.Z_().required("Username is required"),password:c.Z_().transform((function(e){return""===e?void 0:e})).concat(b?c.Z_().required("Password is required"):null).min(6,"Password must be at least 6 characters")}),v={resolver:(0,a.X)(N)};b||(v.defaultValues=e.user);var w=(0,i.cI)(v),g=w.register,y=w.handleSubmit,k=w.reset,_=w.formState,S=_.errors;return(0,r.jsxs)("form",{onSubmit:y((function(e){return b?f(e):x(j.id,e)})),children:[(0,r.jsxs)("div",{className:"form-row",children:[(0,r.jsxs)("div",{className:"form-group col",children:[(0,r.jsx)("label",{children:"First Name"}),(0,r.jsx)("input",u({name:"firstName",type:"text"},g("firstName"),{className:"form-control ".concat(S.firstName?"is-invalid":"")})),(0,r.jsx)("div",{className:"invalid-feedback",children:null===(s=S.firstName)||void 0===s?void 0:s.message})]}),(0,r.jsxs)("div",{className:"form-group col",children:[(0,r.jsx)("label",{children:"Last Name"}),(0,r.jsx)("input",u({name:"lastName",type:"text"},g("lastName"),{className:"form-control ".concat(S.lastName?"is-invalid":"")})),(0,r.jsx)("div",{className:"invalid-feedback",children:null===(n=S.lastName)||void 0===n?void 0:n.message})]})]}),(0,r.jsxs)("div",{className:"form-row",children:[(0,r.jsxs)("div",{className:"form-group col",children:[(0,r.jsx)("label",{children:"Username"}),(0,r.jsx)("input",u({name:"username",type:"text"},g("username"),{className:"form-control ".concat(S.username?"is-invalid":"")})),(0,r.jsx)("div",{className:"invalid-feedback",children:null===(o=S.email)||void 0===o?void 0:o.message})]}),(0,r.jsxs)("div",{className:"form-group col",children:[(0,r.jsxs)("label",{children:["Password",!b&&(0,r.jsx)("em",{className:"ml-1",children:"(Leave blank to keep the same password)"})]}),(0,r.jsx)("input",u({name:"password",type:"password"},g("password"),{className:"form-control ".concat(S.password?"is-invalid":"")})),(0,r.jsx)("div",{className:"invalid-feedback",children:null===(m=S.password)||void 0===m?void 0:m.message})]})]}),(0,r.jsx)("div",{className:"form-row",children:(0,r.jsxs)("div",{className:"form-group co text-left",children:[(0,r.jsx)("label",{children:"Admin: "}),(0,r.jsx)("input",u({name:"admin",type:"checkbox"},g("admin"),{id:"admin",className:"form-check-input ".concat(S.admin?"is-invalid":"")})),(0,r.jsx)("div",{className:"invalid-feedback",children:null===(h=S.admin)||void 0===h?void 0:h.message})]})}),(0,r.jsxs)("div",{className:"form-group",children:[(0,r.jsxs)("button",{type:"submit",disabled:_.isSubmitting,className:"btn btn-primary mr-2",children:[_.isSubmitting&&(0,r.jsx)("span",{className:"spinner-border spinner-border-sm mr-1"}),"Save"]}),(0,r.jsx)("button",{onClick:function(){return k(v.defaultValues)},type:"button",disabled:_.isSubmitting,className:"btn btn-secondary",children:"Reset"}),(0,r.jsx)(l.rU,{href:"/users",className:"btn btn-link",children:"Cancel"})]})]})}function h(e){var s=e.children;return(0,r.jsx)("div",{className:"p-4",children:(0,r.jsx)("div",{className:"container",children:s})})}},5100:function(e,s,n){"use strict";n.r(s);var r=n(5893),t=n(7294),i=n(2546),a=n(7889),c=n(1785);s.default=function(){var e=(0,t.useState)(null),s=e[0],n=e[1];return(0,t.useEffect)((function(){c.W4.getAll().then((function(e){return n(e)}))}),[]),(0,r.jsxs)(a.U,{children:[(0,r.jsx)("h1",{children:"Users"}),(0,r.jsx)(i.rU,{href:"/users/add",className:"btn btn-sm btn-success mb-2",children:"Add User"}),(0,r.jsxs)("table",{className:"table table-striped",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{children:[(0,r.jsx)("th",{style:{width:"30%"},children:"First Name"}),(0,r.jsx)("th",{style:{width:"30%"},children:"Last Name"}),(0,r.jsx)("th",{style:{width:"30%"},children:"Username"}),(0,r.jsx)("th",{style:{width:"30%"},children:"Admin"}),(0,r.jsx)("th",{style:{width:"10%"}})]})}),(0,r.jsxs)("tbody",{children:[s&&s.map((function(e){return(0,r.jsxs)("tr",{children:[(0,r.jsx)("td",{children:e.firstName}),(0,r.jsx)("td",{children:e.lastName}),(0,r.jsx)("td",{children:e.username}),(0,r.jsx)("td",{children:(0,r.jsx)("input",{type:"checkbox",checked:e.admin})}),(0,r.jsxs)("td",{style:{whiteSpace:"nowrap"},children:[(0,r.jsx)(i.rU,{href:"/users/edit/".concat(e.id),className:"btn btn-sm btn-primary mr-1",children:"Edit"}),(0,r.jsx)("button",{onClick:function(){return r=e.id,n(s.map((function(e){return e.id===r&&(e.isDeleting=!0),e}))),void c.W4.delete(r).then((function(){n((function(e){return e.filter((function(e){return e.id!==r}))}))}));var r},className:"btn btn-sm btn-danger btn-delete-user",disabled:e.isDeleting,children:e.isDeleting?(0,r.jsx)("span",{className:"spinner-border spinner-border-sm"}):(0,r.jsx)("span",{children:"Delete"})})]})]},e.id)})),!s&&(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:"4",children:(0,r.jsx)(i.$j,{})})}),s&&!s.length&&(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:"4",className:"text-center",children:(0,r.jsx)("div",{className:"p-2",children:"No Users To Display"})})})]})]})]})}}},function(e){e.O(0,[978,774,888,179],(function(){return s=2261,e(e.s=s);var s}));var s=e.O();_N_E=s}]);