1 line
14 KiB
JavaScript
1 line
14 KiB
JavaScript
"use strict";(()=>{var e={};e.id=5662,e.ids=[5662],e.modules={30671:(e,t)=>{Object.defineProperty(t,"M",{enumerable:!0,get:function(){return function e(t,s){return s in t?t[s]:"then"in t&&"function"==typeof t.then?t.then(t=>e(t,s)):"function"==typeof t&&"default"===s?t:void 0}}})},67777:(e,t,s)=>{s.r(t),s.d(t,{config:()=>C,default:()=>P,getServerSideProps:()=>q,getStaticPaths:()=>E,getStaticProps:()=>M,reportWebVitals:()=>O,routeModule:()=>$,unstable_getServerProps:()=>R,unstable_getServerSideProps:()=>T,unstable_getStaticParams:()=>I,unstable_getStaticPaths:()=>F,unstable_getStaticProps:()=>U});var a={};s.r(a),s.d(a,{UsersContext:()=>w,default:()=>k,getServerSideProps:()=>S});var i=s(63865),r=s(9455),n=s(30671),l=s(49407),d=s(89600),c=s(8732),o=s(82015),u=s.n(o),m=s(95222),p=s(20048),x=s.n(p),h=s(84312),v=s(58548),f=s(21347);function y({user:e,setTargetUser:t,users:s,adminUsers:a,invitedAccounts:i}){return(0,c.jsx)(u().Fragment,{children:(0,c.jsxs)("section",{className:"paper",children:[(0,c.jsx)("h2",{className:"text-xl m-0",children:"Users List"}),(0,c.jsxs)("div",{className:"card no-hover items-center w-full justify-between",children:[(0,c.jsxs)("div",{className:"gap-2",children:[(0,c.jsx)("div",{className:"w-10 h-10 rounded-full overflow-hidden",children:(0,c.jsx)("img",{src:e.image_thumbnail,alt:"Main User Image",width:40,className:"w-full h-full object-cover"})}),(0,c.jsxs)("span",{className:"font-semibold",children:[e.first_name," ",e.last_name]})]}),(0,c.jsx)("span",{className:"text-sm font-semibold",children:"Super User (Owner)"})]}),(0,c.jsxs)("div",{className:"w-full flex-col items-stretch",children:[i&&i[0]&&(0,c.jsxs)(u().Fragment,{children:[(0,c.jsx)("h4",{className:"m-0 text-sm font-semibold text-slate-400",children:"Accounts that Invited you"}),i.map((e,s)=>(0,c.jsx)(f.A,{userObject:e,setTargetUser:t,paradigm:"invited"},s+1))]}),a&&a[0]&&(0,c.jsxs)(u().Fragment,{children:[(0,c.jsx)("h4",{className:"m-0 text-sm font-semibold text-slate-400",children:"Accounts you Invited"}),a.map((e,s)=>(0,c.jsx)(f.A,{userObject:e,setTargetUser:t},s+1))]})]})]})})}var j=s(63715),g=s(32415);function b({invitationObject:e}){let[t,s]=u().useState(!1);return(0,c.jsxs)("div",{className:"bg-slate-100 px-4 py-2 rounded w-full justify-between relative",children:[t&&(0,c.jsx)(g.A,{width:"20px"}),(0,c.jsxs)("span",{className:"text-sm font-semibold",children:[e.first_name," ",e.last_name," (",e.email,")"]}),(0,c.jsx)("button",{className:"py-1.5 px-3 text-sm secondary",onClick:t=>{s(!0),(0,j.A)("/api/acceptUserInvitation",{method:"post",body:{...e}},!0).then(e=>{e.success&&(window.alert("Invitation Accepted!"),window.location.reload()),setTimeout(()=>{s(!1)},500)})},children:"Accept Invitation"})]},e.id)}function A(e){let{user:t,databases:s,pendingInvitations:a,pendingInvitationsReceived:i,adminUsers:r,invitedAccounts:n,setTargetUser:l}=u().useContext(w),[d,o]=u().useState(!1);return(0,c.jsxs)(u().Fragment,{children:[(0,c.jsxs)("div",{className:"flex-col items-start gap-0 w-full",children:[(0,c.jsxs)("div",{className:"w-full justify-between flex-wrap",children:[(0,c.jsx)("h1",{className:"text-3xl m-0",children:"Users"}),(0,c.jsxs)("a",{href:`/admin/${t?.id}/users/add-user`,className:"flex items-center gap-2 whitespace-normal button",children:[(0,c.jsx)("span",{className:"symbol",children:"+"}),(0,c.jsx)("span",{children:"Add New User"})]})]}),(0,c.jsx)(v.A,{user:t})]}),(0,c.jsxs)("div",{className:"w-full grid grid-cols-1 items-start justify-start",children:[(0,c.jsx)("div",{className:"flex-col items-stretch justify-start",children:(0,c.jsx)(y,{setTargetUser:l,user:t,adminUsers:r,invitedAccounts:n})}),(0,c.jsxs)("div",{className:"flex-col items-stretch justify-start",children:[a&&a[0]&&(0,c.jsx)(u().Fragment,{children:(0,c.jsx)("section",{className:"p-4 items-start gap-4 overflow-visible",children:(0,c.jsxs)("div",{className:"flex-col w-full items-start",children:[(0,c.jsx)("h2",{className:"text-xl m-0",children:"Invitations Sent"}),a.map((e,t)=>(0,c.jsxs)("div",{className:"bg-slate-100 px-4 py-2 rounded w-full justify-between",children:[(0,c.jsx)("span",{className:"text-sm font-semibold",children:e.invited_user_email}),(0,c.jsxs)("div",{children:[(0,c.jsx)("span",{className:"text-sm text-slate-400",children:"Pending"}),(0,c.jsx)("span",{className:"text-sm text-orange-600 hover:opacity-50 cursor-pointer",onClick:t=>{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))]})})}),i&&i[0]&&(0,c.jsx)(u().Fragment,{children:(0,c.jsx)("section",{className:"p-4 items-start gap-4 overflow-visible",children:(0,c.jsxs)("div",{className:"flex-col w-full items-start",children:[(0,c.jsx)("h2",{className:"text-xl m-0",children:"Pending Invitations Received"}),i.map((e,t)=>(0,c.jsx)(b,{invitationObject:e},t+1))]})})})]})]})]})}var N=s(67216),_=s.n(N);let w=u().createContext({});function k({user:e,users:t,databases:s,pendingInvitations:a,pendingInvitationsReceived:i,adminUsers:r,invitedAccounts:n}){let l=(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("title",{children:"Users | Datasquirel"}),(0,c.jsx)("meta",{name:"description",content:"Welcome to your data app"})]}),[d,o]=u().useState(null),[p,x]=u().useState(null),[v,f]=u().useState(null);return(0,c.jsx)(m.A,{head:l,user:e,children:(0,c.jsxs)(w.Provider,{value:{user:e,users:t,targetUser:p,setTargetUser:x,databases:s,pendingInvitations:a,pendingInvitationsReceived:i,adminUsers:r,invitedAccounts:n},children:[(0,c.jsx)(A,{}),(0,c.jsx)(h.A,{targetUser:p,user:e,setTargetUser:x})]})})}async function S({req:e,res:t,query:s}){let a=await x()(e,t);if(!a?.logged_in_status)return{redirect:{destination:"/logout",permanent:!1}};let i=await _()(`SELECT * FROM delegated_users WHERE user_id='${a.id}'`),r=await _()(`SELECT db_name,db_slug,db_image FROM user_databases WHERE user_id='${a.id}'`),n=await _()(`SELECT * FROM invitations WHERE inviting_user_id='${a.id}' AND invitation_status='Pending'`),l=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='${a.email}' AND invitation_status='Pending'`),d=await _()(`SELECT * FROM user_users WHERE user_id='${a.id}' AND user_type='admin'`),c=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='${a.email}' AND user_users.user_type='admin'`);return{props:{user:a,users:i,databases:r,pendingInvitations:n,pendingInvitationsReceived:l,adminUsers:d,invitedAccounts:c}}}let P=(0,n.M)(a,"default"),M=(0,n.M)(a,"getStaticProps"),E=(0,n.M)(a,"getStaticPaths"),q=(0,n.M)(a,"getServerSideProps"),C=(0,n.M)(a,"config"),O=(0,n.M)(a,"reportWebVitals"),U=(0,n.M)(a,"unstable_getStaticProps"),F=(0,n.M)(a,"unstable_getStaticPaths"),I=(0,n.M)(a,"unstable_getStaticParams"),R=(0,n.M)(a,"unstable_getServerProps"),T=(0,n.M)(a,"unstable_getServerSideProps"),$=new i.PagesRouteModule({definition:{kind:r.A.PAGES,page:"/admin/[user_id]/users",pathname:"/admin/[user_id]/users",bundlePath:"",filename:""},components:{App:d.default,Document:l.default},userland:a})},21347:(e,t,s)=>{s.d(t,{A:()=>o});var a=s(8732),i=s(82015),r=s.n(i),n=s(55158),l=s(63715),d=s(32415),c=s(62506);function o({userObject:e,setTargetUser:t,paradigm:s}){let i=s?.match(/invited/)?`${e.inviteeFirstName} ${e.inviteeLastName} (${e.inviteeEmail})`:`${e.first_name} ${e.last_name} (${e.email})`,o=s?.match(/invited/)?`${e.inviteeImage}`:`${e.image_thumbnail}`,[u,m]=r().useState(!1);return(0,a.jsxs)("div",{className:"card no-hover items-center "+(s?.match(/invited/)?" green green-bg":" primary"),children:[u&&(0,a.jsx)(d.A,{}),(0,a.jsxs)("div",{className:"w-full",children:[(0,a.jsx)("img",{src:o,className:"w-8 h-8 rounded-full object-cover bg-slate-200",onError:e=>{e.target.src="/images/user-preset-thumbnail.png"}}),(0,a.jsx)("span",{className:"text-sm font-semibold",children:i}),e?.user_priviledge?.match(/./)&&(0,a.jsxs)("span",{className:"text-sm ml-auto text-slate-900/50",children:["Priviledges:"," ",(0,a.jsx)("span",{className:"text-slate-600 font-semibold",children:e.user_priviledge.split("|").join(" | ")})]}),!s?.match(/invited/)&&(0,a.jsx)(r().Fragment,{children:(0,a.jsxs)(c.A,{children:[(0,a.jsx)("button",{className:"outlined text-xs px-3 py-1",onClick:s=>{t(e),setTimeout(()=>{(0,n.PB)("target-user-popup")},200)},children:"Edit User Access"}),(0,a.jsx)("button",{className:"outlined text-xs px-3 py-1",onClick:t=>{m(!0),window.confirm("Delete this user")&&(0,l.A)("/api/deleteUserUser",{method:"post",body:{...e}},!0).then(e=>{setTimeout(()=>{m(!1)},500),window.location.reload()})},children:"Delete User"})]})})]})]})}},55158:(e,t,s)=>{s.d(t,{Ay:()=>l,PB:()=>d,fs:()=>c});var a=s(8732),i=s(58150),r=s(82015),n=s.n(r);function l({children:e,title:t,data:s,fullPage:r,wrapperClasses:l,closePopupDispatch:d,wrapperStyle:o,noContainer:u}){return r?(0,a.jsxs)("div",{className:"popup-bg overflow-hidden "+(l||""),"data-popupid":t||null,style:o,children:[u?(0,a.jsx)(n().Fragment,{children:e}):(0,a.jsx)("div",{className:"relative w-full h-full z-50","data-data":s?JSON.stringify(s):"",children:e}),(0,a.jsx)("button",{className:"popup-cancel-button fixed outlined gray",onClick:e=>{c(),d&&d()},children:(0,a.jsx)(i.A,{color:"white",size:20})}),(0,a.jsx)("div",{className:"popup-canceller",onClick:e=>{c(),d&&d()}})]}):(0,a.jsxs)("div",{className:"popup-bg","data-popupid":t||null,children:[u?(0,a.jsx)(n().Fragment,{children:e}):(0,a.jsxs)("div",{className:"popup-content-container minimal-scrollbars","data-data":s?JSON.stringify(s):"",children:[e,(0,a.jsx)("button",{className:"outlined gray popup-cancel-button",onClick:e=>{c(),d&&d()},children:(0,a.jsx)("span",{className:"font-normal",children:"✖"})})]}),u&&(0,a.jsx)("button",{className:"gray popup-cancel-button",onClick:e=>{c(),d&&d()},children:(0,a.jsx)("span",{className:"font-normal",children:"✖"})}),(0,a.jsx)("div",{className:"popup-canceller",onClick:e=>{c(),d&&d()}})]})}function d(e,t){let s=document.querySelector(`[data-popupid='${e}']`);s&&(s.style.display="flex",t&&t(s))}function c(e){document.querySelectorAll("[data-popupid]").forEach(e=>{e.style.display="none"}),e&&e()}},62506:(e,t,s)=>{s.d(t,{A:()=>n});var a=s(8732),i=s(82015),r=s.n(i);function n({children:e,column:t,className:s}){let i=r().useRef();return(0,a.jsx)("div",{className:"items-stretch gap-0"+(t?" flex-col":" flex-wrap xl:flex-nowrap")+(s?" "+s:""),ref:i,children:e})}},23293:(e,t,s)=>{s.d(t,{A:()=>a});let a=(0,s(82544).A)("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]])},92441:(e,t,s)=>{s.d(t,{A:()=>a});let a=(0,s(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,t,s)=>{s.d(t,{A:()=>a});let a=(0,s(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,t,s)=>{s.d(t,{A:()=>a});let a=(0,s(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,t,s)=>{s.d(t,{A:()=>a});let a=(0,s(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,t,s)=>{s.d(t,{A:()=>a});let a=(0,s(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,t,s)=>{s.d(t,{A:()=>a});let a=(0,s(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,t,s)=>{s.d(t,{A:()=>a});let a=(0,s(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,t,s)=>{s.d(t,{A:()=>a});let a=(0,s(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,t,s)=>{s.d(t,{A:()=>a});let a=(0,s(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,t,s)=>{s.d(t,{A:()=>a});let a=(0,s(82544).A)("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]])},9455:(e,t)=>{var s;Object.defineProperty(t,"A",{enumerable:!0,get:function(){return s}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE"}(s||(s={}))},40361:e=>{e.exports=require("next/dist/compiled/next-server/pages.runtime.prod.js")},27912:e=>{e.exports=require("next/head")},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 t=require("../../../webpack-runtime.js");t.C(e);var s=e=>t(t.s=e),a=t.X(0,[883,9821,9600,7070,4312],()=>s(67777));module.exports=a})(); |