"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[361],{361:(e,s,t)=>{t.d(s,{A:()=>o});var l=t(4848),a=t(6540),n=t(9020),i=t(5655),c=t(1710),d=t(2408),r=t(6959);function o(e){var s,o;let{targetUser:u,user:m,setTargetUser:h}=e,p=t(9436);if(!u)return null;let[x,b]=a.useState(!0),[f,g]=a.useState([]),[v,j]=a.useState(!1),[_,w]=a.useState(u&&(null===(s=u.user_priviledge)||void 0===s?void 0:s.split("|"))||[]),[N,y]=a.useState((null==u?void 0:u.database_access)?u.database_access.split("|"):[]),[A,k]=a.useState(u&&(null===(o=u.database_access)||void 0===o?void 0:o.split("|")[0])||null),[E,S]=a.useState([]),[T,C]=a.useState([]);return a.useEffect(()=>{(0,n.A)("/api/getUserDatabases").then(e=>{e.success&&g(e.databases)})},[]),a.useEffect(()=>{if(u){if(A)(0,n.A)("/api/getDatabaseTables?dbSlug=".concat(A,"&dbOwnerId=").concat(m.id,"&delegatedUserId=").concat(u.invited_user_id)).then(e=>{e.success&&(S(null),setTimeout(()=>{S([...e.tables])},200)),e.accessed_tables&&e.accessed_tables[0]&&!(null==T?void 0:T[0])&&C(e.accessed_tables.map(e=>"".concat(e.database,"-").concat(e.table)))});else{var e;k((null===(e=u.database_access)||void 0===e?void 0:e.split("|")[0])||null)}}},[A]),a.useEffect(()=>{if(b(!0),u){var e,s;w((null===(e=u.user_priviledge)||void 0===e?void 0:e.split("|"))||[]),y((null===(s=u.database_access)||void 0===s?void 0:s.split("|"))||[])}setTimeout(()=>{b(!1)},500)},[u]),a.useEffect(()=>{k((null==N?void 0:N[0])||null)},[N]),(0,l.jsxs)(i.Ay,{title:"target-user-popup",closePopupDispatch:()=>{h(void 0)},children:[x&&(0,l.jsx)(c.A,{position:"relative"}),!x&&u&&(0,l.jsx)(a.Fragment,{children:(0,l.jsxs)("div",{className:"flex-col w-full items-start p-4",children:[(0,l.jsxs)("h4",{className:"m-0",children:["Edit ",u.first_name," ",u.last_name,"'s Access"]}),(0,l.jsx)("hr",{}),(0,l.jsxs)("form",{className:"flex flex-col items-start w-full",onSubmit:e=>{e.preventDefault(),b(!0),(0,n.A)("/api/updateAdminUserAccess",{method:"post",body:{userObject:u,user_priviledge:_.join("|"),database_access:null==N?void 0:N.join("|"),db_tables:N&&N[0]?T.join("|"):"",inv_user_id:u.invited_user_id}},!0).then(e=>{window.location.reload(),setTimeout(()=>{b(!1)},500)})},children:[(0,l.jsx)("h3",{className:"m-0 text-lg font-semibold mb-1 text-slate-600",children:"User Priviledges"}),(0,l.jsx)(d.A,{checkBoxValues:p.map(e=>({title:e,name:e,default:!!_.includes(e),onChangeHandler:s=>{_.includes(e)?w([..._.filter(s=>s!=e)]):w(s=>[...s,e])}})),smallText:!0,flexRow:!0}),(0,l.jsx)("hr",{className:"my-6"}),(0,l.jsx)("h3",{className:"m-0 text-lg font-semibold mb-2 text-slate-600",children:"Databases Access"}),(0,l.jsx)("span",{className:"button outlined gray px-4 py-1 -mt-1 mb-1.5",onClick:e=>{v?(f.forEach(e=>{setTimeout(()=>{let s=document.getElementById(e.db_slug);(null==s?void 0:s.checked)&&s.click()},200)}),j(!1)):(f.forEach(e=>{setTimeout(()=>{let s=document.getElementById(e.db_slug);s.checked||s.click()},200)}),j(!0))},children:v?"Deselect All":"Select All"}),(0,l.jsx)(d.A,{checkBoxValues:f.map(e=>({title:e.db_name,name:e.db_slug,onChangeHandler:s=>{N.includes(e.db_slug)?y([...N.filter(s=>s!=e.db_slug)]):y(s=>[...s,e.db_slug]),N.length===f.length?j(!0):j(!1)},default:!!N.includes(e.db_slug)})),smallText:!0,flexRow:!0}),N&&N[0]&&(0,l.jsxs)(a.Fragment,{children:[(0,l.jsx)("hr",{className:"my-6"}),(0,l.jsx)("h3",{className:"m-0 text-lg font-semibold mb-2 text-slate-600",children:"Database Tables"}),(0,l.jsx)(r.A,{required:!0,selectOptions:f.filter(e=>N.includes(e.db_slug)).map(e=>({title:e.db_name,payload:e.db_slug})),name:"databases",onChangeHandler:e=>{k(e.target.value)}}),(0,l.jsx)("div",{className:"h-2"}),E&&E[0]&&(0,l.jsx)(d.A,{checkBoxValues:E.map(e=>({title:e.table_name,name:e.table_slug,onChangeHandler:s=>{T.includes("".concat(A,"-").concat(e.table_slug))?C([...T.filter(s=>s!="".concat(A,"-").concat(e.table_slug))]):C(s=>[...s,"".concat(A,"-").concat(e.table_slug)])},default:!!T.includes("".concat(A,"-").concat(e.table_slug))})),smallText:!0,flexRow:!0})]}),(0,l.jsx)("button",{className:"mt-4 w-full",children:"Update User Access"})]})]})})]})}},2408:(e,s,t)=>{t.d(s,{A:()=>a});var l=t(4848);function a(e){let{name:s,checkBoxValues:t,setAlert:a,labelColor:n,flexRow:i,baseText:c,smallText:d,className:r}=e;return(0,l.jsx)("div",{className:"flex items-start gap-x-4"+(i?" flex-row flex-wrap gap-y-2 ":" flex-col gap-y-4 ")+(r||""),children:t.map((e,t)=>{let{payload:i,title:r,onChangeHandler:o,fixed:u,jsx:m}=e,h=e.name?"".concat(s,"-").concat(e.name):i?s+"-"+i:s;return(0,l.jsxs)("div",{className:"flex items-center"+(e.default&&u?" pointer-events-none":"")+(d?" gap-1 ":" gap-2 ")+((null==e?void 0:e.className)?e.className:""),children:[(0,l.jsx)("input",{className:"m-0"+(d?" w-4 h-4":" w-5 h-5"),type:"checkbox",defaultChecked:!!e.default,name:h,id:h,onChange:s=>{a&&a(null),o&&o(s,e)},value:i,style:{minWidth:"20px"},...e.props}),m||(0,l.jsx)("label",{htmlFor:h,className:"m-0 "+(n||"text-slate-800 dark:text-white/80")+(c||d?" text-base":" text-lg"),children:r})]},t+1)})})}t(6540)},6959:(e,s,t)=>{t.d(s,{A:()=>n});var l=t(4848),a=t(2027);function n(e){let{selectOptions:s,name:t,onChangeHandler:n,required:i,setAlert:c,title:d,defaultValue:r,info:o,id:u}=e;try{function m(e){if(e.type.match(/enter/i)&&window.innerWidth<1200)return;let s=e.target.closest(".info-wrapper"),t=s.querySelector(".info-dropdown");if(e.type.match(/leave/i)&&!t.classList.contains("hidden")){t.classList.add("hidden");return}if(!(e.type.match(/leave/i)&&t.classList.contains("hidden"))){if(!s){t.classList.add("hidden");return}if(t.classList.contains("hidden")){t.classList.remove("hidden");return}t.classList.add("hidden")}}return(0,l.jsxs)("div",{className:"form-select-block flex items-start flex-col gap-0.5 w-full relative"+(o?" pr-8":""),children:[d&&(0,l.jsxs)("label",{htmlFor:t,children:[d,i?"":" (optional)"]}),(0,l.jsxs)("div",{className:"flex items-center w-full relative",children:[(0,l.jsx)("select",{name:t,id:u||t,className:"w-full bg-white",required:i,onChange:e=>{c&&c(null),e.target.classList.remove("warning"),n&&n(e)},defaultValue:r||void 0,children:s.map((e,s)=>{let{payload:t,title:a}=e;return(0,l.jsx)("option",{value:t,selected:!!e.default,children:a},s+1)})}),(0,l.jsx)(a.A,{className:"absolute right-2 text-base text-slate-500 pointer-events-none",size:20}),o&&(0,l.jsxs)("div",{className:"info-wrapper absolute -right-10 w-8 h-8 rounded-full bg-white flex items-center justify-center z-10",style:{top:"50%",transform:"translate(0,-50%)"},onMouseEnter:m,onMouseLeave:m,onClick:m,children:[(0,l.jsx)("img",{src:"/images/info-outlined-black.png",alt:"",className:"w-6 h-6 object-contain opacity-60 pointer-events-none"}),(0,l.jsx)("div",{className:"info-dropdown absolute top-9 right-0 bg-white w-52 md:w-96 p-2 sm:p-6 shadow-xl rounded hidden text-center border border-slate-300 border-solid",children:(0,l.jsx)("span",{children:o})}),(0,l.jsx)("div",{className:"absolute -top-2 w-12",style:{height:"45px"}})]})]})]})}catch(e){return console.log("ERROR in FormSelect =>",e),(0,l.jsx)("div",{children:"Form Select Error"})}}t(6540)},9436:e=>{e.exports=JSON.parse('["Edit Tables","Update Entries","Create Table","Delete Entries","Delete Tables"]')}}]);