(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5926],{97385:function(e,t,a){(window.__NEXT_P=window.__NEXT_P||[]).push(["/admin/[user_id]/databases/[single]/users/add-user",function(){return a(14437)}])},14437:function(e,t,a){"use strict";a.r(t),a.d(t,{AddNewDbUserContext:function(){return p},__N_SSP:function(){return h},default:function(){return _}});var s=a(85893),n=a(67294),r=a(54858),d=a(828),i=a(424),u=a(61781),l=a(86729),o=a(95264),c=a(81926);function m(e){var t=n.useContext(p),r=t.user,m=t.database,f=(t.table,t.query,t.confirmedDelegetedUser,a(19169),(0,d.Z)(n.useState("invitation"),2)),b=(f[0],f[1],(0,d.Z)(n.useState(!1),2)),h=b[0],_=b[1],x=(0,d.Z)(n.useState(!1),2),v=(x[0],x[1],(0,d.Z)(n.useState(["Edit"]),2)),g=(v[0],v[1],(0,d.Z)(n.useState(m.db_slug),2)),j=g[0],w=(g[1],(0,d.Z)(n.useState(null),2)),N=(w[0],w[1],(0,d.Z)(n.useState(null),2)),Z=N[0],U=N[1],y=(0,d.Z)(n.useState([]),2),D=(y[0],y[1],(0,d.Z)(n.useState([]),2));D[0],D[1];return(0,s.jsxs)(n.Fragment,{children:[(0,s.jsxs)("div",{className:"flex-col items-start gap-0 w-full",children:[(0,s.jsx)("div",{className:"w-full justify-between flex-wrap",children:(0,s.jsxs)("div",{children:[(0,s.jsx)(u.Z,{}),(0,s.jsxs)("h1",{className:"text-3xl m-0",children:["Add A New User to ",m.db_name]})]})}),(0,s.jsx)(i.Z,{user:r})]}),(0,s.jsxs)("section",{className:"paper",children:[h&&(0,s.jsx)(o.Z,{}),(0,s.jsxs)("form",{onSubmit:function(e){e.preventDefault(),_(!0);var t=e.target,a=Array.from(t),s={};a.forEach((function(e){var t,a;(null===(t=e.nodeName)||void 0===t?void 0:t.match(/button/i))||e.name&&(null===(a=e.value)||void 0===a?void 0:a.match(/./))&&(s[e.name]=e.value)}));var n={payload:s,dbFullName:m.db_full_name,dbId:m.id};(0,l.Z)("/api/addDbUser",{method:"post",body:n},!0).then((function(e){e.success?Z?(Z.imageName="".concat(j,"-user-").concat(e.newUserId),Z.mimeType="jpeg",delete Z.imageBase64Full,(0,l.Z)("/api/addUserMedia",{method:"post",body:{media:[Z],folder:j.replace(/_/g,"-"),type:"image"}},!0).then((function(t){(0,l.Z)("/api/updateDbUser",{method:"post",body:{dbFullName:m.db_full_name,payload:{id:e.newUserId,image:t.mediaData[0].media_url,image_thumbnail:t.mediaData[0].media_thumbnail_url}}},!0).then((function(e){e.success&&(window.location.pathname="/admin/".concat(null===r||void 0===r?void 0:r.id,"/databases/").concat(m.db_slug,"/users")),setTimeout((function(){_(!1)}),500)}))}))):window.location.pathname="/admin/".concat(null===r||void 0===r?void 0:r.id,"/databases/").concat(m.db_slug,"/users"):setTimeout((function(){_(!1)}),500)}))},className:"w-full flex flex-col items-stretch gap-4",children:[(0,s.jsx)(c.Z,{user:r,targetDb:m.db_full_name,database:m,userImage:Z,setUserImage:U}),(0,s.jsx)("button",{children:"Add User"})]})]})]})}var f=a(4423),b={},h=!0,p=n.createContext(b);function _(e){var t=e.user,a=e.database,n=e.table,d=e.query,i=e.confirmedDelegetedUser,u=(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("title",{children:"Users | Datasquirel"}),(0,s.jsx)("meta",{name:"description",content:"Welcome to your data app"})]});return(0,s.jsx)(r.Z,{head:u,user:t,extraHeaderContent:(0,s.jsx)(f.Z,{database:a,query:d,confirmedDelegetedUser:i,user:t}),children:(0,s.jsx)(p.Provider,{value:{user:t,database:a,table:n,query:d,confirmedDelegetedUser:i},children:(0,s.jsx)(m,{})})})}},19169:function(e){"use strict";e.exports=JSON.parse('["Edit Tables","Update Entries","Create Table","Delete Entries","Delete Tables"]')}},function(e){e.O(0,[9365,194,7901,2870,9719,9774,2888,179],(function(){return t=97385,e(e.s=t);var t}));var t=e.O();_N_E=t}]);