@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
91 lines (90 loc) • 3.38 kB
JavaScript
;
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__, {
useDeleteAction: ()=>useDeleteAction
});
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 tools_js_namespaceObject = require("../utils/tools.js");
const external_useRouterInternal_js_namespaceObject = require("./useRouterInternal.js");
const useDeleteAction = (resource)=>{
const { apiBasePath } = (0, ConfigContext_js_namespaceObject.useConfig)();
const { router } = (0, external_useRouterInternal_js_namespaceObject.useRouterInternal)();
const { t } = (0, I18nContext_js_namespaceObject.useI18n)();
const { showMessage } = (0, MessageContext_js_namespaceObject.useMessage)();
const runDeletion = async (ids)=>{
const response = await fetch(`${apiBasePath}/${(0, tools_js_namespaceObject.slugify)(resource)}`, {
method: "DELETE",
body: JSON.stringify(ids),
headers: {
"Content-Type": "application/json"
}
});
if (!response.ok) {
const result = await response.json();
throw new Error(result.error);
}
};
const runSingleDeletion = async (id)=>{
const response = await fetch(`${apiBasePath}/${(0, tools_js_namespaceObject.slugify)(resource)}/${id}`, {
method: "DELETE"
});
if (!response.ok) {
const result = await response.json();
throw new Error(result.error);
}
};
const deleteItems = async (ids)=>{
if (window.confirm(t("list.row.actions.delete.alert", {
count: ids.length
}))) try {
await runDeletion(ids);
showMessage({
type: "success",
message: t("list.row.actions.delete.success")
});
router.refresh();
} catch {
showMessage({
type: "error",
message: t("list.row.actions.delete.error")
});
}
};
return {
deleteItems,
runDeletion,
runSingleDeletion
};
};
exports.useDeleteAction = __webpack_exports__.useDeleteAction;
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
"useDeleteAction"
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
Object.defineProperty(exports, '__esModule', {
value: true
});