dsql-admin/dsql-app/.local_dist/server/chunks/4187.js
2024-11-05 12:12:42 +01:00

166 lines
9.1 KiB
JavaScript

"use strict";
exports.id = 4187;
exports.ids = [4187];
exports.modules = {
/***/ 4187:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "Z": () => (/* binding */ SuDashboardContent)
/* harmony export */ });
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(997);
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6689);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _functions_frontend_fetchApi__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(6729);
/* harmony import */ var _general_LoadingBlock__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(5264);
/* harmony import */ var _components_UserCard__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(1336);
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* ==============================================================================
* Main Component { Functional }
* ==============================================================================
* @param {Object} props - Server props
* @param {any} props.data
*/ function SuDashboardContent({ data }) {
/**
* Get Contexts
*
* @abstract { React.useContext }
*/ ////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Javascript Variables
*
* @abstract Non hook variables and functions
*/ const userTitles = Object.keys(data.users[0]);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* React Hooks
*
* @abstract { useState, useEffect, useRef, etc ... }
*/ /** @type {[ errorLog: string | null, setErrorLog: React.Dispatch<React.SetStateAction<string | null>> ]} */ // @ts-ignore
const [errorLog, setErrorLog] = react__WEBPACK_IMPORTED_MODULE_1___default().useState(null);
const [refresh, setRefresh] = react__WEBPACK_IMPORTED_MODULE_1___default().useState(0);
const [clearErrorLogLoading, setClearErrorLogLoading] = react__WEBPACK_IMPORTED_MODULE_1___default().useState(false);
function fetchErrorLogs() {
(0,_functions_frontend_fetchApi__WEBPACK_IMPORTED_MODULE_4__/* ["default"] */ .Z)("/api/admin/grabErrorLogs").then((res)=>{
if (res?.log && typeof res.log === "string" && !res.log?.match(/./)) {
setErrorLog("No Logs Yet");
return;
} else if (res?.log) {
setErrorLog("No Logs");
}
setErrorLog(res.log.replace(/\n|\r|\n\r|\\n/gm, "<br/>"));
});
}
console.log(typeof errorLog);
react__WEBPACK_IMPORTED_MODULE_1___default().useEffect(()=>{
fetchErrorLogs();
if (refresh === 0) {
setInterval(()=>{
fetchErrorLogs();
}, 10000);
}
}, [
refresh
]);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Function Return
*
* @abstract Main Function Return
*/ return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx((react__WEBPACK_IMPORTED_MODULE_1___default().Fragment), {
children: /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
className: "items-stretch gap-10 w-full",
children: [
/*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("section", {
className: "paper w-full",
children: [
/*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("h2", {
className: "text-xl m-0 mb-6",
children: "Users"
}),
/*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
className: "flex-col items-stretch gap-10",
children: data.users.map((/** @type {any} */ userObject, /** @type {number} */ index)=>{
return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_UserCard__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z, {
userObject: userObject
}, index + 1);
})
})
]
}),
/*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("section", {
className: "paper",
children: [
/*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
className: "w-full justify-between",
children: [
/*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("h2", {
className: "text-xl m-0",
children: "Error Logs"
}),
/*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
children: /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("button", {
onClick: (e)=>{
if (window.confirm("Clear Error Logs?")) {
setClearErrorLogLoading(true);
(0,_functions_frontend_fetchApi__WEBPACK_IMPORTED_MODULE_4__/* ["default"] */ .Z)("/api/admin/clearErrorLogs", "post").then((res)=>{
setRefresh((prev)=>prev + 1);
});
setTimeout(()=>{
setClearErrorLogLoading(false);
}, 2000);
}
},
className: "outlined gray relative",
children: [
clearErrorLogLoading && /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_general_LoadingBlock__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .Z, {
width: "20px"
}),
"Clear Error Log"
]
})
})
]
}),
errorLog && /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("p", {
dangerouslySetInnerHTML: {
__html: errorLog ? errorLog : "No Log"
}
}),
typeof errorLog !== "string" && /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_general_LoadingBlock__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .Z, {
position: "relative",
width: "25px"
})
]
})
]
})
});
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */
/***/ })
};
;