dsql-admin/dsql-app/.local_dist/static/chunks/6946-2c3ce8dcf1028efd.js

1 line
10 KiB
JavaScript
Raw Normal View History

2024-12-08 19:56:57 +00:00
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6946],{80443:(e,t,a)=>{a.d(t,{A:()=>o});var l=a(74848),s=a(96540),c=a(23698),i=a(45165),d=a(620),n=a(21458),r=a(41301);function o(e){var t,o;let{targetUser:u,user:h,setTargetUser:m}=e,p=a(49436);if(!u)return null;let[x,b]=s.useState(!0),[f,v]=s.useState([]),[y,g]=s.useState(!1),[k,j]=s.useState(u?null===(t=u.user_priviledge)||void 0===t?void 0:t.split("|"):[]),[A,w]=s.useState((null==u?void 0:u.database_access)?u.database_access.split("|"):[]),[_,N]=s.useState(u?null===(o=u.database_access)||void 0===o?void 0:o.split("|")[0]:null),[M,C]=s.useState([]),[E,S]=s.useState([]);return s.useEffect(()=>{(0,c.A)("/api/getUserDatabases").then(e=>{e.success&&v(e.databases)})},[]),s.useEffect(()=>{if(u){if(_)(0,c.A)("/api/getDatabaseTables?dbSlug=".concat(_,"&dbOwnerId=").concat(h.id,"&delegatedUserId=").concat(u.invited_user_id)).then(e=>{e.success&&(C(null),setTimeout(()=>{C([...e.tables])},200)),e.accessed_tables&&e.accessed_tables[0]&&!E[0]&&S(e.accessed_tables.map(e=>"".concat(e.database,"-").concat(e.table)))});else{var e;N((null===(e=u.database_access)||void 0===e?void 0:e.split("|")[0])||null)}}},[_]),s.useEffect(()=>{if(b(!0),u){var e,t;j((null===(e=u.user_priviledge)||void 0===e?void 0:e.split("|"))||[]),w((null===(t=u.database_access)||void 0===t?void 0:t.split("|"))||[])}setTimeout(()=>{b(!1)},500)},[u]),s.useEffect(()=>{N((null==A?void 0:A[0])||null)},[A]),(0,l.jsxs)(i.Ay,{title:"target-user-popup",closePopupDispatch:()=>{m(null)},children:[x&&(0,l.jsx)(d.A,{position:"relative"}),!x&&u&&(0,l.jsx)(s.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,c.A)("/api/updateAdminUserAccess",{method:"post",body:{userObject:u,user_priviledge:k.join("|"),database_access:null==A?void 0:A.join("|"),db_tables:A&&A[0]?E.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)(n.A,{checkBoxValues:p.map(e=>({title:e,name:e,default:!!k.includes(e),onChangeHandler:t=>{k.includes(e)?j([...k.filter(t=>t!=e)]):j(t=>[...t,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=>{y?(f.forEach(e=>{setTimeout(()=>{let t=document.getElementById(e.db_slug);(null==t?void 0:t.checked)&&t.click()},200)}),g(!1)):(f.forEach(e=>{setTimeout(()=>{let t=document.getElementById(e.db_slug);t.checked||t.click()},200)}),g(!0))},children:y?"Deselect All":"Select All"}),(0,l.jsx)(n.A,{checkBoxValues:f.map(e=>({title:e.db_name,name:e.db_slug,onChangeHandler:t=>{A.includes(e.db_slug)?w([...A.filter(t=>t!=e.db_slug)]):w(t=>[...t,e.db_slug]),A.length===f.length?g(!0):g(!1)},default:!!A.includes(e.db_slug)})),smallText:!0,flexRow:!0}),A&&A[0]&&(0,l.jsxs)(s.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=>A.includes(e.db_slug)).map(e=>({title:e.db_name,payload:e.db_slug})),name:"databases",onChangeHandler:e=>{N(e.target.value)}}),(0,l.jsx)("div",{className:"h-2"}),M&&M[0]&&(0,l.jsx)(n.A,{checkBoxValues:M.map(e=>({title:e.table_name,name:e.table_slug,onChangeHandler:t=>{E.includes("".concat(_,"-").concat(e.table_slug))?S([...E.filter(t=>t!="".concat(_,"-").concat(e.table_slug))]):S(t=>[...t,"".concat(_,"-").concat(e.table_slug)])},default:!!E.includes("".concat(_,"-").concat(e.table_slug))})),smallText:!0,flexRow:!0})]}),(0,l.jsx)("button",{className:"mt-4 w-full",children:"Update User Access"})]})]})})]})}},2145