1 line
16 KiB
JavaScript
1 line
16 KiB
JavaScript
"use strict";(()=>{var e={};e.id=5662,e.ids=[636,5662],e.modules={30671:(e,s)=>{Object.defineProperty(s,"M",{enumerable:!0,get:function(){return function e(s,t){return t in s?s[t]:"then"in s&&"function"==typeof s.then?s.then(s=>e(s,t)):"function"==typeof s&&"default"===t?s:void 0}}})},67777:(e,s,t)=>{t.r(s),t.d(s,{config:()=>C,default:()=>M,getServerSideProps:()=>E,getStaticPaths:()=>k,getStaticProps:()=>P,reportWebVitals:()=>F,routeModule:()=>H,unstable_getServerProps:()=>T,unstable_getServerSideProps:()=>R,unstable_getStaticParams:()=>O,unstable_getStaticPaths:()=>I,unstable_getStaticProps:()=>U});var i={};t.r(i),t.d(i,{UsersContext:()=>w,default:()=>q,getServerSideProps:()=>S});var r=t(63865),a=t(9455),l=t(30671),n=t(49407),u=t(68268),o=t(8732),d=t(82015),c=t.n(d),m=t(95222),p=t(20048),x=t.n(p),h=t(84312),v=t(58548),y=t(21347);function f({user:e,setTargetUser:s,users:t,adminUsers:i,invitedAccounts:r}){return(0,o.jsx)(c().Fragment,{children:(0,o.jsxs)("section",{className:"paper",children:[(0,o.jsx)("h2",{className:"text-xl m-0",children:"Users List"}),(0,o.jsxs)("div",{className:"card no-hover items-center w-full justify-between",children:[(0,o.jsxs)("div",{className:"gap-2",children:[(0,o.jsx)("div",{className:"w-10 h-10 rounded-full overflow-hidden",children:(0,o.jsx)("img",{src:e.image_thumbnail,alt:"Main User Image",width:40,className:"w-full h-full object-cover"})}),(0,o.jsxs)("span",{className:"font-semibold",children:[e.first_name," ",e.last_name]})]}),(0,o.jsx)("span",{className:"text-sm font-semibold",children:"Super User (Owner)"})]}),(0,o.jsxs)("div",{className:"w-full flex-col items-stretch",children:[r&&r[0]&&(0,o.jsxs)(c().Fragment,{children:[(0,o.jsx)("h4",{className:"m-0 text-sm font-semibold text-slate-400",children:"Accounts that Invited you"}),r.map((e,t)=>(0,o.jsx)(y.A,{userObject:e,setTargetUser:s,paradigm:"invited"},t+1))]}),i&&i[0]&&(0,o.jsxs)(c().Fragment,{children:[(0,o.jsx)("h4",{className:"m-0 text-sm font-semibold text-slate-400",children:"Accounts you Invited"}),i.map((e,t)=>(0,o.jsx)(y.A,{userObject:e,setTargetUser:s},t+1))]})]})]})})}var j=t(63715),g=t(32415);function b({invitationObject:e}){let[s,t]=c().useState(!1);return(0,o.jsxs)("div",{className:"bg-slate-100 px-4 py-2 rounded w-full justify-between relative",children:[s&&(0,o.jsx)(g.A,{width:"20px"}),(0,o.jsxs)("span",{className:"text-sm font-semibold",children:[e.first_name," ",e.last_name," (",e.email,")"]}),(0,o.jsx)("button",{className:"py-1.5 px-3 text-sm secondary",onClick:s=>{t(!0),(0,j.A)("/api/acceptUserInvitation",{method:"post",body:{...e}},!0).then(e=>{e.success&&(window.alert("Invitation Accepted!"),window.location.reload()),setTimeout(()=>{t(!1)},500)})},children:"Accept Invitation"})]},e.id)}function A(e){let{user:s,databases:t,pendingInvitations:i,pendingInvitationsReceived:r,adminUsers:a,invitedAccounts:l,setTargetUser:n}=c().useContext(w),[u,d]=c().useState(!1);return(0,o.jsxs)(c().Fragment,{children:[(0,o.jsxs)("div",{className:"flex-col items-start gap-0 w-full",children:[(0,o.jsxs)("div",{className:"w-full justify-between flex-wrap",children:[(0,o.jsx)("h1",{className:"text-3xl m-0",children:"Users"}),(0,o.jsxs)("a",{href:`/admin/${s?.id}/users/add-user`,className:"flex items-center gap-2 whitespace-normal button",children:[(0,o.jsx)("span",{className:"symbol",children:"+"}),(0,o.jsx)("span",{children:"Add New User"})]})]}),(0,o.jsx)(v.A,{user:s})]}),(0,o.jsxs)("div",{className:"w-full grid grid-cols-1 items-start justify-start",children:[(0,o.jsx)("div",{className:"flex-col items-stretch justify-start",children:(0,o.jsx)(f,{setTargetUser:n,user:s,adminUsers:a,invitedAccounts:l})}),(0,o.jsxs)("div",{className:"flex-col items-stretch justify-start",children:[i&&i[0]&&(0,o.jsx)(c().Fragment,{children:(0,o.jsx)("section",{className:"p-4 items-start gap-4 overflow-visible",children:(0,o.jsxs)("div",{className:"flex-col w-full items-start",children:[(0,o.jsx)("h2",{className:"text-xl m-0",children:"Invitations Sent"}),i.map((e,s)=>(0,o.jsxs)("div",{className:"bg-slate-100 px-4 py-2 rounded w-full justify-between",children:[(0,o.jsx)("span",{className:"text-sm font-semibold",children:e.invited_user_email}),(0,o.jsxs)("div",{children:[(0,o.jsx)("span",{className:"text-sm text-slate-400",children:"Pending"}),(0,o.jsx)("span",{className:"text-sm text-orange-600 hover:opacity-50 cursor-pointer",onClick:s=>{window.confirm("Delete this invitation?")&&(0,j.A)("/api/deleteInvitation",{method:"POST",body:{id:e.id}},!0).finally(()=>{window.location.reload()})},children:"Delete Invitation"})]})]},e.id))]})})}),r&&r[0]&&(0,o.jsx)(c().Fragment,{children:(0,o.jsx)("section",{className:"p-4 items-start gap-4 overflow-visible",children:(0,o.jsxs)("div",{className:"flex-col w-full items-start",children:[(0,o.jsx)("h2",{className:"text-xl m-0",children:"Pending Invitations Received"}),r.map((e,s)=>(0,o.jsx)(b,{invitationObject:e},s+1))]})})})]})]})]})}var N=t(67216),_=t.n(N);let w=c().createContext({});function q({user:e,users:s,databases:t,pendingInvitations:i,pendingInvitationsReceived:r,adminUsers:a,invitedAccounts:l}){let n=(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("title",{children:"Users | Datasquirel"}),(0,o.jsx)("meta",{name:"description",content:"Welcome to your data app"})]}),[u,d]=c().useState(null),[p,x]=c().useState(null),[v,y]=c().useState(null);return(0,o.jsx)(m.A,{head:n,user:e,children:(0,o.jsxs)(w.Provider,{value:{user:e,users:s,targetUser:p,setTargetUser:x,databases:t,pendingInvitations:i,pendingInvitationsReceived:r,adminUsers:a,invitedAccounts:l},children:[(0,o.jsx)(A,{}),(0,o.jsx)(h.A,{targetUser:p,user:e,setTargetUser:x})]})})}async function S({req:e,res:s,query:t}){let i=await x()(e,s);if(!i?.logged_in_status)return{redirect:{destination:"/logout",permanent:!1}};let r=await _()(`SELECT * FROM delegated_users WHERE user_id='${i.id}'`),a=await _()(`SELECT db_name,db_slug,db_image FROM user_databases WHERE user_id='${i.id}'`),l=await _()(`SELECT * FROM invitations WHERE inviting_user_id='${i.id}' AND invitation_status='Pending'`),n=await _()(`SELECT invitations.*,users.first_name,users.last_name,users.email FROM invitations JOIN users ON users.id=invitations.inviting_user_id WHERE invited_user_email='${i.email}' AND invitation_status='Pending'`),u=await _()(`SELECT * FROM user_users WHERE user_id='${i.id}' AND user_type='admin'`),o=await _()(`SELECT user_users.*,users.first_name AS inviteeFirstName,users.last_name AS inviteeLastName,users.email AS inviteeEmail, users.image_thumbnail AS inviteeImage FROM user_users JOIN users ON users.id=user_users.user_id WHERE user_users.email='${i.email}' AND user_users.user_type='admin'`);return{props:{user:i,users:r,databases:a,pendingInvitations:l,pendingInvitationsReceived:n,adminUsers:u,invitedAccounts:o}}}let M=(0,l.M)(i,"default"),P=(0,l.M)(i,"getStaticProps"),k=(0,l.M)(i,"getStaticPaths"),E=(0,l.M)(i,"getServerSideProps"),C=(0,l.M)(i,"config"),F=(0,l.M)(i,"reportWebVitals"),U=(0,l.M)(i,"unstable_getStaticProps"),I=(0,l.M)(i,"unstable_getStaticPaths"),O=(0,l.M)(i,"unstable_getStaticParams"),T=(0,l.M)(i,"unstable_getServerProps"),R=(0,l.M)(i,"unstable_getServerSideProps"),H=new r.PagesRouteModule({definition:{kind:a.A.PAGES,page:"/admin/[user_id]/users",pathname:"/admin/[user_id]/users",bundlePath:"",filename:""},components:{App:u.default,Document:n.default},userland:i})},21347:(e,s,t)=>{t.d(s,{A:()=>d});var i=t(8732),r=t(82015),a=t.n(r),l=t(55158),n=t(63715),u=t(32415),o=t(62506);function d({userObject:e,setTargetUser:s,paradigm:t}){let r=t?.match(/invited/)?`${e.inviteeFirstName} ${e.inviteeLastName} (${e.inviteeEmail})`:`${e.first_name} ${e.last_name} (${e.email})`,d=t?.match(/invited/)?`${e.inviteeImage}`:`${e.image_thumbnail}`,[c,m]=a().useState(!1);return(0,i.jsxs)("div",{className:"card no-hover items-center "+(t?.match(/invited/)?" green green-bg":" primary"),children:[c&&(0,i.jsx)(u.A,{}),(0,i.jsxs)("div",{className:"w-full",children:[(0,i.jsx)("img",{src:d,className:"w-8 h-8 rounded-full object-cover bg-slate-200",onError:e=>{e.target.src="/images/user-preset-thumbnail.png"}}),(0,i.jsx)("span",{className:"text-sm font-semibold",children:r}),e?.user_priviledge?.match(/./)&&(0,i.jsxs)("span",{className:"text-sm ml-auto text-slate-900/50",children:["Priviledges:"," ",(0,i.jsx)("span",{className:"text-slate-600 font-semibold",children:e.user_priviledge.split("|").join(" | ")})]}),!t?.match(/invited/)&&(0,i.jsx)(a().Fragment,{children:(0,i.jsxs)(o.A,{children:[(0,i.jsx)("button",{className:"outlined text-xs px-3 py-1",onClick:t=>{s(e),setTimeout(()=>{(0,l.PB)("target-user-popup")},200)},children:"Edit User Access"}),(0,i.jsx)("button",{className:"outlined text-xs px-3 py-1",onClick:s=>{m(!0),window.confirm("Delete this user")&&(0,n.A)("/api/deleteUserUser",{method:"post",body:{...e}},!0).then(e=>{setTimeout(()=>{m(!1)},500),window.location.reload()})},children:"Delete User"})]})})]})]})}},55158:(e,s,t)=>{t.d(s,{Ay:()=>n,PB:()=>u,fs:()=>o});var i=t(8732),r=t(58150),a=t(82015),l=t.n(a);function n({children:e,title:s,data:t,fullPage:a,wrapperClasses:n,closePopupDispatch:u,wrapperStyle:d,noContainer:c}){return a?(0,i.jsxs)("div",{className:"popup-bg overflow-hidden "+(n||""),"data-popupid":s||null,style:d,children:[c?(0,i.jsx)(l().Fragment,{children:e}):(0,i.jsx)("div",{className:"relative w-full h-full z-50","data-data":t?JSON.stringify(t):"",children:e}),(0,i.jsx)("button",{className:"popup-cancel-button fixed outlined gray",onClick:e=>{o(),u&&u()},children:(0,i.jsx)(r.A,{color:"white",size:20})}),(0,i.jsx)("div",{className:"popup-canceller",onClick:e=>{o(),u&&u()}})]}):(0,i.jsxs)("div",{className:"popup-bg","data-popupid":s||null,children:[c?(0,i.jsx)(l().Fragment,{children:e}):(0,i.jsxs)("div",{className:"popup-content-container minimal-scrollbars","data-data":t?JSON.stringify(t):"",children:[e,(0,i.jsx)("button",{className:"outlined gray popup-cancel-button",onClick:e=>{o(),u&&u()},children:(0,i.jsx)("span",{className:"font-normal",children:"✖"})})]}),c&&(0,i.jsx)("button",{className:"gray popup-cancel-button",onClick:e=>{o(),u&&u()},children:(0,i.jsx)("span",{className:"font-normal",children:"✖"})}),(0,i.jsx)("div",{className:"popup-canceller",onClick:e=>{o(),u&&u()}})]})}function u(e,s){let t=document.querySelector(`[data-popupid='${e}']`);t&&(t.style.display="flex",s&&s(t))}function o(e){document.querySelectorAll("[data-popupid]").forEach(e=>{e.style.display="none"}),e&&e()}},26406:(e,s,t)=>{var i=t(24994);s.A=void 0;var r=i(t(30887)),a=t(8732);s.A=(0,r.default)([(0,a.jsx)("path",{d:"M22 15c0-1.66-1.34-3-3-3h-1.5v-.5C17.5 8.46 15.04 6 12 6c-.77 0-1.49.17-2.16.46L20.79 17.4c.73-.55 1.21-1.41 1.21-2.4M2 14c0 2.21 1.79 4 4 4h9.73l-8-8H6c-2.21 0-4 1.79-4 4",opacity:".3"},"0"),(0,a.jsx)("path",{d:"M19.35 10.04C18.67 6.59 15.64 4 12 4c-1.33 0-2.57.36-3.65.97l1.49 1.49C10.51 6.17 11.23 6 12 6c3.04 0 5.5 2.46 5.5 5.5v.5H19c1.66 0 3 1.34 3 3 0 .99-.48 1.85-1.21 2.4l1.41 1.41c1.09-.92 1.8-2.27 1.8-3.81 0-2.64-2.05-4.78-4.65-4.96M3 5.27l2.77 2.77h-.42C2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h11.73l2 2 1.41-1.41L4.41 3.86zM7.73 10l8 8H6c-2.21 0-4-1.79-4-4s1.79-4 4-4z"},"1")],"CloudOffTwoTone")},92441:(e,s,t)=>{t.d(s,{A:()=>i});let i=(0,t(82544).A)("BookText",[["path",{d:"M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H20v20H6.5a2.5 2.5 0 0 1 0-5H20",key:"t4utmx"}],["path",{d:"M8 7h6",key:"1f0q6e"}],["path",{d:"M8 11h8",key:"vwpz6n"}]])},34637:(e,s,t)=>{t.d(s,{A:()=>i});let i=(0,t(82544).A)("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]])},29743:(e,s,t)=>{t.d(s,{A:()=>i});let i=(0,t(82544).A)("FileKey2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v6",key:"rc0qvx"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["circle",{cx:"4",cy:"16",r:"2",key:"1ehqvc"}],["path",{d:"m10 10-4.5 4.5",key:"7fwrp6"}],["path",{d:"m9 11 1 1",key:"wa6s5q"}]])},10643:(e,s,t)=>{t.d(s,{A:()=>i});let i=(0,t(82544).A)("Globe",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]])},66916:(e,s,t)=>{t.d(s,{A:()=>i});let i=(0,t(82544).A)("HardDrive",[["line",{x1:"22",x2:"2",y1:"12",y2:"12",key:"1y58io"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}],["line",{x1:"6",x2:"6.01",y1:"16",y2:"16",key:"sgf278"}],["line",{x1:"10",x2:"10.01",y1:"16",y2:"16",key:"1l4acy"}]])},83158:(e,s,t)=>{t.d(s,{A:()=>i});let i=(0,t(82544).A)("Images",[["path",{d:"M18 22H4a2 2 0 0 1-2-2V6",key:"pblm9e"}],["path",{d:"m22 13-1.296-1.296a2.41 2.41 0 0 0-3.408 0L11 18",key:"nf6bnh"}],["circle",{cx:"12",cy:"8",r:"2",key:"1822b1"}],["rect",{width:"16",height:"16",x:"6",y:"2",rx:"2",key:"12espp"}]])},66918:(e,s,t)=>{t.d(s,{A:()=>i});let i=(0,t(82544).A)("RotateCw",[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]])},10321:(e,s,t)=>{t.d(s,{A:()=>i});let i=(0,t(82544).A)("ShieldEllipsis",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M8 12h.01",key:"czm47f"}],["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M16 12h.01",key:"1l6xoz"}]])},25294:(e,s,t)=>{t.d(s,{A:()=>i});let i=(0,t(82544).A)("Users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]])},58150:(e,s,t)=>{t.d(s,{A:()=>i});let i=(0,t(82544).A)("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]])},9455:(e,s)=>{var t;Object.defineProperty(s,"A",{enumerable:!0,get:function(){return t}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE"}(t||(t={}))},66099:e=>{e.exports=require("@mui/system")},37616:e=>{e.exports=require("@mui/system/DefaultPropsProvider")},24509:e=>{e.exports=require("@mui/system/InitColorSchemeScript")},84781:e=>{e.exports=require("@mui/system/colorManipulator")},18215:e=>{e.exports=require("@mui/system/createStyled")},59989:e=>{e.exports=require("@mui/system/createTheme")},16670:e=>{e.exports=require("@mui/system/styleFunctionSx")},88698:e=>{e.exports=require("@mui/system/useThemeProps")},76831:e=>{e.exports=require("@mui/utils")},28578:e=>{e.exports=require("@mui/utils/capitalize")},14036:e=>{e.exports=require("@mui/utils/composeClasses")},31112:e=>{e.exports=require("@mui/utils/createChainedFunction")},21763:e=>{e.exports=require("@mui/utils/debounce")},7546:e=>{e.exports=require("@mui/utils/deepmerge")},5928:e=>{e.exports=require("@mui/utils/deprecatedPropType")},20985:e=>{e.exports=require("@mui/utils/formatMuiErrorMessage")},61119:e=>{e.exports=require("@mui/utils/generateUtilityClass")},81699:e=>{e.exports=require("@mui/utils/generateUtilityClasses")},29823:e=>{e.exports=require("@mui/utils/isMuiElement")},55402:e=>{e.exports=require("@mui/utils/ownerDocument")},46875:e=>{e.exports=require("@mui/utils/ownerWindow")},48080:e=>{e.exports=require("@mui/utils/requirePropFactory")},39597:e=>{e.exports=require("@mui/utils/setRef")},88190:e=>{e.exports=require("@mui/utils/unsupportedProp")},83889:e=>{e.exports=require("@mui/utils/useControlled")},21956:e=>{e.exports=require("@mui/utils/useEnhancedEffect")},4926:e=>{e.exports=require("@mui/utils/useEventCallback")},7376:e=>{e.exports=require("@mui/utils/useForkRef")},63310:e=>{e.exports=require("@mui/utils/useId")},10977:e=>{e.exports=require("@mui/utils/useIsFocusVisible")},74956:e=>{e.exports=require("clsx")},40361:e=>{e.exports=require("next/dist/compiled/next-server/pages.runtime.prod.js")},27912:e=>{e.exports=require("next/head")},29825:e=>{e.exports=require("prop-types")},82015:e=>{e.exports=require("react")},22326:e=>{e.exports=require("react-dom")},8732:e=>{e.exports=require("react/jsx-runtime")},9973:e=>{e.exports=require("serverless-mysql")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},81630:e=>{e.exports=require("http")},33873:e=>{e.exports=require("path")}};var s=require("../../../webpack-runtime.js");s.C(e);var t=e=>s(s.s=e),i=s.X(0,[9764,883,8268,7070,4312],()=>t(67777));module.exports=i})(); |