@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
82 lines (81 loc) • 4.04 kB
JavaScript
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import external_lodash_merge_default from "lodash.merge";
import { getSchemaForResource } from "../utils/jsonSchema.mjs";
import { getClientActionsComponents, getCustomInputs } from "../utils/options.mjs";
import external_Dashboard_mjs_default from "./Dashboard.mjs";
import external_Form_mjs_default from "./Form.mjs";
import external_List_mjs_default from "./List.mjs";
import { MainLayout } from "./MainLayout.mjs";
function NextAdmin({ basePath, apiBasePath, data, resource, schema, resources, slug, total, dashboard, validation, isAppDir, options, resourcesTitles, resourcesIdProperty, customInputs: customInputsProp, dialogComponents: dialogComponentsProp, customPages, actions, translations, locale, title, sidebar, resourcesIcons, user, externalLinks, pageLoader, rawData, relationshipsRawData, listFilterOptions }) {
if (!isAppDir && !options) throw new Error("You must provide the options prop when using next-admin with page router");
let mergedActions = external_lodash_merge_default(actions ?? [], resource ? options?.model?.[resource]?.actions : []);
const modelSchema = resource && schema ? getSchemaForResource(schema, resource) : void 0;
const resourceTitle = resourcesTitles?.[resource] ?? resource;
const resourceIcon = resourcesIcons?.[resource];
const dialogComponents = resource ? isAppDir ? dialogComponentsProp : getClientActionsComponents(resource, options) : void 0;
const renderMainComponent = ()=>{
if (Array.isArray(data) && resource && void 0 !== total) return /*#__PURE__*/ jsx(external_List_mjs_default, {
resource: resource,
data: data,
total: total,
title: resourceTitle,
resourcesIdProperty: resourcesIdProperty,
actions: mergedActions,
icon: resourceIcon,
schema: schema,
clientActionsComponents: dialogComponents,
rawData: rawData,
listFilterOptions: listFilterOptions
}, resource);
if (data && !Array.isArray(data) || modelSchema && !data) {
const customInputs = isAppDir ? customInputsProp : getCustomInputs(resource, options);
return /*#__PURE__*/ jsx(external_Form_mjs_default, {
data: data,
slug: slug,
schema: modelSchema,
resource: resource,
validation: validation,
title: resourceTitle,
customInputs: customInputs,
actions: mergedActions,
icon: resourceIcon,
resourcesIdProperty: resourcesIdProperty,
clientActionsComponents: dialogComponents,
relationshipsRawData: relationshipsRawData
});
}
if (resources) {
if (dashboard && "function" == typeof dashboard) return dashboard();
return dashboard || /*#__PURE__*/ jsx(external_Dashboard_mjs_default, {
resources: resources
});
}
};
const titleElement = isAppDir ? title : options?.title;
return /*#__PURE__*/ jsxs(Fragment, {
children: [
pageLoader,
/*#__PURE__*/ jsx(MainLayout, {
resource: resource,
resources: resources,
resourcesTitles: resourcesTitles,
customPages: customPages,
basePath: basePath,
apiBasePath: apiBasePath,
isAppDir: isAppDir,
translations: translations,
locale: locale,
title: titleElement,
sidebar: sidebar,
resourcesIcons: resourcesIcons,
user: user,
externalLinks: externalLinks,
options: options,
resourcesIdProperty: resourcesIdProperty,
schema: schema,
children: renderMainComponent()
})
]
});
}
export { NextAdmin };