dsql-admin/dsql-app/.local_dist/server/pages/admin/[user_id]/users.js

747 lines
33 KiB
JavaScript
Raw Normal View History

2024-11-05 11:12:42 +00:00
"use strict";
(() => {
var exports = {};
exports.id = 1838;
exports.ids = [1838];
exports.modules = {
/***/ 3931:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
"UsersContext": () => (/* binding */ UsersContext),
"default": () => (/* binding */ Dashboard),
"getServerSideProps": () => (/* binding */ getServerSideProps)
});
// EXTERNAL MODULE: external "react/jsx-runtime"
var jsx_runtime_ = __webpack_require__(997);
// EXTERNAL MODULE: external "react"
var external_react_ = __webpack_require__(6689);
var external_react_default = /*#__PURE__*/__webpack_require__.n(external_react_);
// EXTERNAL MODULE: ./layouts/AdminLayout.jsx + 2 modules
var AdminLayout = __webpack_require__(4858);
// EXTERNAL MODULE: ./functions/backend/userAuth.js
var userAuth = __webpack_require__(370);
var userAuth_default = /*#__PURE__*/__webpack_require__.n(userAuth);
// EXTERNAL MODULE: ./components/admin/users/TargetUserPreviewPopup.jsx
var TargetUserPreviewPopup = __webpack_require__(9417);
// EXTERNAL MODULE: ./components/general/Breadcrumbs.jsx
var Breadcrumbs = __webpack_require__(424);
// EXTERNAL MODULE: ./components/admin/users/UserListCard.jsx
var UserListCard = __webpack_require__(3863);
;// CONCATENATED MODULE: ./components/admin/users/UsersList.jsx
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* ==============================================================================
* Main Component { Functional }
* ==============================================================================
* @param {Object} props - Server props
* @param {import("@/package-shared/types").UserType} props.user
* @param {React.Dispatch<React.SetStateAction<import("@/package-shared/types").MYSQL_user_users_table_def | null>>} props.setTargetUser
* @param {import("@/package-shared/types").MYSQL_user_users_table_def[]} [props.users]
* @param {any[]} props.adminUsers
* @param {any[]} props.invitedAccounts
*/ function UsersList({ user , setTargetUser , users , adminUsers , invitedAccounts , }) {
/**
* Get Contexts
*
* @abstract { React.useContext }
*/ ////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Javascript Variables
*
* @abstract Non hook variables and functions
*/ ////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* React Hooks
*
* @abstract { useState, useEffect, useRef, etc ... }
*/ ////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Function Return
*
* @abstract Main Function Return
*/ return /*#__PURE__*/ jsx_runtime_.jsx((external_react_default()).Fragment, {
children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)("section", {
className: "paper",
children: [
/*#__PURE__*/ jsx_runtime_.jsx("h2", {
className: "text-xl m-0",
children: "Users List"
}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "card no-hover items-center w-full justify-between",
children: [
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "gap-2",
children: [
/*#__PURE__*/ jsx_runtime_.jsx("div", {
className: "w-10 h-10 rounded-full overflow-hidden",
children: /*#__PURE__*/ jsx_runtime_.jsx("img", {
src: user.image_thumbnail,
alt: "Main User Image",
width: 40,
className: "w-full h-full object-cover"
})
}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("span", {
className: "font-semibold",
children: [
user.first_name,
" ",
user.last_name
]
})
]
}),
/*#__PURE__*/ jsx_runtime_.jsx("span", {
className: "text-sm font-semibold",
children: "Super User (Owner)"
})
]
}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "w-full flex-col items-stretch",
children: [
invitedAccounts && invitedAccounts[0] && /*#__PURE__*/ (0,jsx_runtime_.jsxs)((external_react_default()).Fragment, {
children: [
/*#__PURE__*/ jsx_runtime_.jsx("h4", {
className: "m-0 text-sm font-semibold text-slate-400",
children: "Accounts that Invited you"
}),
invitedAccounts.map((userObject, index)=>{
return /*#__PURE__*/ jsx_runtime_.jsx(UserListCard/* default */.Z, {
userObject: userObject,
setTargetUser: setTargetUser,
paradigm: "invited"
}, index + 1);
})
]
}),
adminUsers && adminUsers[0] && /*#__PURE__*/ (0,jsx_runtime_.jsxs)((external_react_default()).Fragment, {
children: [
/*#__PURE__*/ jsx_runtime_.jsx("h4", {
className: "m-0 text-sm font-semibold text-slate-400",
children: "Accounts you Invited"
}),
adminUsers.map((userObject, index)=>{
return /*#__PURE__*/ jsx_runtime_.jsx(UserListCard/* default */.Z, {
userObject: userObject,
setTargetUser: setTargetUser
}, index + 1);
})
]
})
]
})
]
})
});
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */
// EXTERNAL MODULE: ./functions/frontend/fetchApi.js
var fetchApi = __webpack_require__(6729);
// EXTERNAL MODULE: ./components/general/LoadingBlock.jsx
var LoadingBlock = __webpack_require__(5264);
;// CONCATENATED MODULE: ./components/admin/users/InvitationReceivedCard.jsx
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* ==============================================================================
* Main Component { Functional }
* ==============================================================================
* @param {Object} props - Server props
* @param {any} props.invitationObject
*/ function InvitationReceivedCard({ invitationObject }) {
/**
* Get Contexts
*
* @abstract { React.useContext }
*/ ////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Javascript Variables
*
* @abstract Non hook variables and functions
*/ ////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* React Hooks
*
* @abstract { useState, useEffect, useRef, etc ... }
*/ const [loading, setLoading] = external_react_default().useState(false);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Function Return
*
* @abstract Main Function Return
*/ return /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "bg-slate-100 px-4 py-2 rounded w-full justify-between relative",
children: [
loading && /*#__PURE__*/ jsx_runtime_.jsx(LoadingBlock/* default */.Z, {
width: "20px"
}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("span", {
className: "text-sm font-semibold",
children: [
invitationObject.first_name,
" ",
invitationObject.last_name,
" (",
invitationObject.email,
")"
]
}),
/*#__PURE__*/ jsx_runtime_.jsx("button", {
className: "py-1.5 px-3 text-sm secondary",
onClick: (e)=>{
setLoading(true);
(0,fetchApi/* default */.Z)("/api/acceptUserInvitation", {
method: "post",
body: {
...invitationObject
}
}, true).then((res)=>{
if (res.success) {
window.alert("Invitation Accepted!");
window.location.reload();
}
setTimeout(()=>{
setLoading(false);
}, 500);
});
},
children: "Accept Invitation"
})
]
}, invitationObject.id);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */
;// CONCATENATED MODULE: ./components/admin/users/UsersContent.jsx
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* ==============================================================================
* Main Component { Functional }
* ==============================================================================
* @param {Object} props - Server props
*/ function UsersContent(props) {
/**
* Get Contexts
*
* @abstract { React.useContext }
*/ const { user , databases , pendingInvitations , pendingInvitationsReceived , adminUsers , invitedAccounts , setTargetUser , } = external_react_default().useContext(UsersContext);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Javascript Variables
*
* @abstract Non hook variables and functions
*/ ////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* React Hooks
*
* @abstract { useState, useEffect, useRef, etc ... }
*/ const [loading, setLoading] = external_react_default().useState(false);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Function Return
*
* @abstract Main Function Return
*/ return /*#__PURE__*/ (0,jsx_runtime_.jsxs)((external_react_default()).Fragment, {
children: [
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "flex-col items-start gap-0 w-full",
children: [
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "w-full justify-between flex-wrap",
children: [
/*#__PURE__*/ jsx_runtime_.jsx("h1", {
className: "text-3xl m-0",
children: "Users"
}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("a", {
href: `/admin/${user?.id}/users/add-user`,
className: "flex items-center gap-2 whitespace-normal button",
children: [
/*#__PURE__*/ jsx_runtime_.jsx("span", {
className: "symbol",
children: "+"
}),
/*#__PURE__*/ jsx_runtime_.jsx("span", {
children: "Add New User"
})
]
})
]
}),
/*#__PURE__*/ jsx_runtime_.jsx(Breadcrumbs/* default */.Z, {
user: user
})
]
}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "w-full grid grid-cols-1 items-start justify-start",
children: [
/*#__PURE__*/ jsx_runtime_.jsx("div", {
className: "flex-col items-stretch justify-start",
children: /*#__PURE__*/ jsx_runtime_.jsx(UsersList, {
setTargetUser: setTargetUser,
user: user,
adminUsers: adminUsers,
invitedAccounts: invitedAccounts
})
}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "flex-col items-stretch justify-start",
children: [
pendingInvitations && pendingInvitations[0] && /*#__PURE__*/ jsx_runtime_.jsx((external_react_default()).Fragment, {
children: /*#__PURE__*/ jsx_runtime_.jsx("section", {
className: "p-4 items-start gap-4 overflow-visible",
children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "flex-col w-full items-start",
children: [
/*#__PURE__*/ jsx_runtime_.jsx("h2", {
className: "text-xl m-0",
children: "Invitations Sent"
}),
pendingInvitations.map((invitationObject, index)=>{
return /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "bg-slate-100 px-4 py-2 rounded w-full justify-between",
children: [
/*#__PURE__*/ jsx_runtime_.jsx("span", {
className: "text-sm font-semibold",
children: invitationObject.invited_user_email
}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
children: [
/*#__PURE__*/ jsx_runtime_.jsx("span", {
className: "text-sm text-slate-400",
children: "Pending"
}),
/*#__PURE__*/ jsx_runtime_.jsx("span", {
className: "text-sm text-orange-600 hover:opacity-50 cursor-pointer",
onClick: (e)=>{
if (window.confirm("Delete this invitation?")) {
(0,fetchApi/* default */.Z)("/api/deleteInvitation", {
method: "POST",
body: {
id: invitationObject.id
}
}, true).finally(()=>{
window.location.reload();
});
}
},
children: "Delete Invitation"
})
]
})
]
}, invitationObject.id);
})
]
})
})
}),
pendingInvitationsReceived && pendingInvitationsReceived[0] && /*#__PURE__*/ jsx_runtime_.jsx((external_react_default()).Fragment, {
children: /*#__PURE__*/ jsx_runtime_.jsx("section", {
className: "p-4 items-start gap-4 overflow-visible",
children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "flex-col w-full items-start",
children: [
/*#__PURE__*/ jsx_runtime_.jsx("h2", {
className: "text-xl m-0",
children: "Pending Invitations Received"
}),
pendingInvitationsReceived.map((invitationObject, index)=>{
return /*#__PURE__*/ jsx_runtime_.jsx(InvitationReceivedCard, {
invitationObject: invitationObject
}, index + 1);
})
]
})
})
})
]
})
]
})
]
});
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */
// EXTERNAL MODULE: ./package-shared/utils/backend/global-db/DB_HANDLER.js
var DB_HANDLER = __webpack_require__(9395);
var DB_HANDLER_default = /*#__PURE__*/__webpack_require__.n(DB_HANDLER);
;// CONCATENATED MODULE: ./pages/admin/[user_id]/users/index.jsx
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/** ****************************************************************************** */ /** @type {import("@/package-shared/types").AllUserUsersContextType} */ // @ts-ignore
const init = {};
const UsersContext = /*#__PURE__*/ external_react_default().createContext(init);
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* ==============================================================================
* Main Component { Functional }
* ==============================================================================
* @param {Object} props - Server props
* @param {import("@/package-shared/types").UserType} props.user
* @param {import("@/package-shared/types").MYSQL_delegated_users_table_def[]} props.users
* @param {import("@/package-shared/types").DSQL_MYSQL_user_databases_Type[]} props.databases
* @param {import("@/package-shared/types").MYSQL_invitations_table_def[]} props.pendingInvitations
* @param {any[]} props.pendingInvitationsReceived
* @param {any[]} props.adminUsers
* @param {any[]} props.invitedAccounts
*/ function Dashboard({ user , users , databases , pendingInvitations , pendingInvitationsReceived , adminUsers , invitedAccounts , }) {
/**
* Get Contexts
*
* @abstract { React.useContext }
*/ ////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Javascript Variables
*
* @abstract Non hook variables and functions
*/ const pageTitle = "Users | Datasquirel";
const pageDescription = "Welcome to your data app";
let head = /*#__PURE__*/ (0,jsx_runtime_.jsxs)(jsx_runtime_.Fragment, {
children: [
/*#__PURE__*/ jsx_runtime_.jsx("title", {
children: pageTitle
}),
/*#__PURE__*/ jsx_runtime_.jsx("meta", {
name: "description",
content: pageDescription
})
]
});
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* React Hooks
*
* @abstract { useState, useEffect, useRef, etc ... }
*/ const [newUser, setNewUser] = external_react_default().useState(null);
/** @type {[ targetUser: import("@/package-shared/types").MYSQL_user_users_table_def | null, setTargetUser: React.Dispatch<React.SetStateAction<import("@/package-shared/types").MYSQL_user_users_table_def | null>> ]} */ // @ts-ignore
const [targetUser, setTargetUser] = external_react_default().useState(null);
/** @type {[ media: any, setTargetMedia: React.Dispatch<React.SetStateAction<any>> ]} */ // @ts-ignore
const [media, setTargetMedia] = external_react_default().useState(null);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Function Return
*
* @abstract Main Function Return
*/ return /*#__PURE__*/ jsx_runtime_.jsx(AdminLayout/* default */.Z, {
head: head,
user: user,
children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)(UsersContext.Provider, {
value: {
user,
users,
targetUser,
setTargetUser,
databases,
pendingInvitations,
pendingInvitationsReceived,
adminUsers,
invitedAccounts
},
children: [
/*#__PURE__*/ jsx_runtime_.jsx(UsersContent, {}),
/*#__PURE__*/ jsx_runtime_.jsx(TargetUserPreviewPopup/* default */.Z, {
targetUser: targetUser,
user: user,
setTargetUser: setTargetUser
})
]
})
});
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
}
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* ==============================================================================
* Server Side Props or Static Props
* ==============================================================================
* @type {import("next").GetServerSideProps}
*/ async function getServerSideProps({ req , res , query }) {
/**
* User Auth
*
* @description User Auth
*/ const user = await userAuth_default()(req, res);
if (!user?.logged_in_status) {
return {
redirect: {
destination: "/logout",
permanent: false
}
};
}
/**
* Page/Site Data Data Fetching
*
* @description Fetch data on the server before returning
*/ const users = await DB_HANDLER_default()(`SELECT * FROM delegated_users WHERE user_id='${user.id}'`);
const databases = await DB_HANDLER_default()(`SELECT db_name,db_slug,db_image FROM user_databases WHERE user_id='${user.id}'`);
const pendingInvitations = await DB_HANDLER_default()(`SELECT * FROM invitations WHERE inviting_user_id='${user.id}' AND invitation_status='Pending'`);
const pendingInvitationsReceived = await DB_HANDLER_default()(`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='${user.email}' AND invitation_status='Pending'`);
const adminUsers = await DB_HANDLER_default()(`SELECT * FROM user_users WHERE user_id='${user.id}' AND user_type='admin'`);
const invitedAccounts = await DB_HANDLER_default()(`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='${user.email}' AND user_users.user_type='admin'`);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Server props return
*
* @description Return data fetched on the server side
*/ return {
props: {
user: user,
users: users,
databases: databases,
pendingInvitations,
pendingInvitationsReceived,
adminUsers,
invitedAccounts
}
};
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
}
/***/ }),
/***/ 4003:
/***/ ((module) => {
module.exports = require("@mui/icons-material/AdminPanelSettingsTwoTone");
/***/ }),
/***/ 69:
/***/ ((module) => {
module.exports = require("@mui/icons-material/CloudOffTwoTone");
/***/ }),
/***/ 4008:
/***/ ((module) => {
module.exports = require("@mui/icons-material/CloudQueueRounded");
/***/ }),
/***/ 7306:
/***/ ((module) => {
module.exports = require("@mui/icons-material/CollectionsTwoTone");
/***/ }),
/***/ 386:
/***/ ((module) => {
module.exports = require("@mui/icons-material/CottageTwoTone");
/***/ }),
/***/ 8979:
/***/ ((module) => {
module.exports = require("@mui/icons-material/DynamicFormTwoTone");
/***/ }),
/***/ 300:
/***/ ((module) => {
module.exports = require("@mui/icons-material/LanguageOutlined");
/***/ }),
/***/ 2814:
/***/ ((module) => {
module.exports = require("@mui/icons-material/LockTwoTone");
/***/ }),
/***/ 5557:
/***/ ((module) => {
module.exports = require("@mui/icons-material/MenuBookTwoTone");
/***/ }),
/***/ 9806:
/***/ ((module) => {
module.exports = require("@mui/icons-material/PeopleOutlineTwoTone");
/***/ }),
/***/ 36:
/***/ ((module) => {
module.exports = require("@mui/icons-material/RefreshRounded");
/***/ }),
/***/ 1799:
/***/ ((module) => {
module.exports = require("@mui/icons-material/SchemaTwoTone");
/***/ }),
/***/ 2423:
/***/ ((module) => {
module.exports = require("lucide-react");
/***/ }),
/***/ 968:
/***/ ((module) => {
module.exports = require("next/head");
/***/ }),
/***/ 6689:
/***/ ((module) => {
module.exports = require("react");
/***/ }),
/***/ 997:
/***/ ((module) => {
module.exports = require("react/jsx-runtime");
/***/ }),
/***/ 2261:
/***/ ((module) => {
module.exports = require("serverless-mysql");
/***/ }),
/***/ 4300:
/***/ ((module) => {
module.exports = require("buffer");
/***/ }),
/***/ 6113:
/***/ ((module) => {
module.exports = require("crypto");
/***/ }),
/***/ 7147:
/***/ ((module) => {
module.exports = require("fs");
/***/ }),
/***/ 3685:
/***/ ((module) => {
module.exports = require("http");
/***/ })
};
;
// load runtime
var __webpack_require__ = require("../../../webpack-runtime.js");
__webpack_require__.C(exports);
var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
2024-11-05 14:18:40 +00:00
var __webpack_exports__ = __webpack_require__.X(0, [4017,8313,5264,6729,5449,913,4480,370,424,4858,5472,4114,9486,9417,3863], () => (__webpack_exec__(3931)));
2024-11-05 11:12:42 +00:00
module.exports = __webpack_exports__;
})();