dsql-admin/dsql-app/.local_dist/static/chunks/3857-402e95bd26a58769.js

1 line
9.5 KiB
JavaScript
Raw Normal View History

2024-12-09 09:39:09 +00:00
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3857],{443:(e,t,a)=>{a.d(t,{A:()=>o});var l=a(4848),s=a(6540),i=a(3698),n=a(5165),c=a(620),d=a(1458),r=a(1301);function o(e){var t,o;let{targetUser:u,user:h,setTargetUser:m}=e,p=a(9436);if(!u)return null;let[x,b]=s.useState(!0),[f,y]=s.useState([]),[v,g]=s.useState(!1),[k,A]=s.useState(u?null===(t=u.user_priviledge)||void 0===t?void 0:t.split("|"):[]),[j,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,E]=s.useState([]),[S,C]=s.useState([]);return s.useEffect(()=>{(0,i.A)("/api/getUserDatabases").then(e=>{e.success&&y(e.databases)})},[]),s.useEffect(()=>{if(u){if(_)(0,i.A)("/api/getDatabaseTables?dbSlug=".concat(_,"&dbOwnerId=").concat(h.id,"&delegatedUserId=").concat(u.invited_user_id)).then(e=>{e.success&&(E(null),setTimeout(()=>{E([...e.tables])},200)),e.accessed_tables&&e.accessed_tables[0]&&!S[0]&&C(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;A((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==j?void 0:j[0])||null)},[j]),(0,l.jsxs)(n.Ay,{title:"target-user-popup",closePopupDispatch:()=>{m(null)},children:[x&&(0,l.jsx)(c.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,i.A)("/api/updateAdminUserAccess",{method:"post",body:{userObject:u,user_priviledge:k.join("|"),database_access:null==j?void 0:j.join("|"),db_tables:j&&j[0]?S.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:!!k.includes(e),onChangeHandler:t=>{k.includes(e)?A([...k.filter(t=>t!=e)]):A(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=>{v?(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:v?"Deselect All":"Select All"}),(0,l.jsx)(d.A,{checkBoxValues:f.map(e=>({title:e.db_name,name:e.db_slug,onChangeHandler:t=>{j.includes(e.db_slug)?w([...j.filter(t=>t!=e.db_slug)]):w(t=>[...t,e.db_slug]),j.length===f.length?g(!0):g(!1)},default:!!j.includes(e.db_slug)})),smallText:!0,flexRow:!0}),j&&j[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=>j.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)(d.A,{checkBoxValues:M.map(e=>({title:e.table_name,name:e.table_slug,onChangeHandler:t=>{S.includes("".concat(_,"-").concat(e.table_slug))?C([...S.filter(t=>t!="".concat(_,"-").concat(e.table_slug))]):C(t=>[...t,"".concat(_,"-").concat(e.table_slug)])},default:!!S.includes("".concat(_,"-").concat(e.table_slug))})),smallText:!0,flexRow:!0})]}),(0,l.jsx)("button",{className:"mt-4 w-full",children:"Update User Access"})]})]})})]})}},1458:(e,t,a)=