UNPKG

@premieroctet/next-admin

Version:

Next-Admin provides a customizable and turnkey admin dashboard for applications built with Next.js and powered by the Prisma ORM. It aims to simplify the development process by providing a turnkey admin system that can be easily integrated into your proje

88 lines (87 loc) 3.59 kB
"use strict"; var __webpack_require__ = {}; (()=>{ __webpack_require__.d = (exports1, definition)=>{ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, { enumerable: true, get: definition[key] }); }; })(); (()=>{ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop); })(); (()=>{ __webpack_require__.r = (exports1)=>{ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, { value: 'Module' }); Object.defineProperty(exports1, '__esModule', { value: true }); }; })(); var __webpack_exports__ = {}; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { SPECIFIC_IDS_TO_RUN_ACTION: ()=>SPECIFIC_IDS_TO_RUN_ACTION, useAction: ()=>useAction }); const ConfigContext_js_namespaceObject = require("../context/ConfigContext.js"); const I18nContext_js_namespaceObject = require("../context/I18nContext.js"); const MessageContext_js_namespaceObject = require("../context/MessageContext.js"); const external_useRouterInternal_js_namespaceObject = require("./useRouterInternal.js"); const SPECIFIC_IDS_TO_RUN_ACTION = { DELETE: "__admin-delete" }; const useAction = (resource, ids)=>{ const { t } = (0, I18nContext_js_namespaceObject.useI18n)(); const { apiBasePath } = (0, ConfigContext_js_namespaceObject.useConfig)(); const { showMessage } = (0, MessageContext_js_namespaceObject.useMessage)(); const { router } = (0, external_useRouterInternal_js_namespaceObject.useRouterInternal)(); const runAction = async (modelAction)=>{ try { if (Object.values(SPECIFIC_IDS_TO_RUN_ACTION).includes(modelAction.id) && "action" in modelAction) await modelAction.action(ids); else { const response = await fetch(`${apiBasePath}/${resource}/actions/${modelAction.id}`, { method: "POST", body: JSON.stringify(ids), headers: { "Content-Type": "application/json" } }); router.refresh(); const actionMessage = await response.json(); if (actionMessage && actionMessage.message) return void showMessage({ type: actionMessage.type, message: t(actionMessage.message), component: modelAction.component }); if (!response.ok) throw new Error(); } if (modelAction.successMessage) showMessage({ type: "success", message: t(modelAction.successMessage), component: modelAction.component }); } catch { if (modelAction.errorMessage) showMessage({ type: "error", message: t(modelAction.errorMessage), component: modelAction.component }); } }; return { runAction }; }; exports.SPECIFIC_IDS_TO_RUN_ACTION = __webpack_exports__.SPECIFIC_IDS_TO_RUN_ACTION; exports.useAction = __webpack_exports__.useAction; for(var __webpack_i__ in __webpack_exports__)if (-1 === [ "SPECIFIC_IDS_TO_RUN_ACTION", "useAction" ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__]; Object.defineProperty(exports, '__esModule', { value: true });