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

77 lines (76 loc) 3.47 kB
"use client"; import { jsx, jsxs } from "react/jsx-runtime"; import { PlusSmallIcon } from "@heroicons/react/24/outline"; import Link_mjs_default from "./common/Link.mjs"; import { useConfig } from "../context/ConfigContext.mjs"; import { useI18n } from "../context/I18nContext.mjs"; import { Permission } from "../types.mjs"; import { getSchemas } from "../utils/jsonSchema.mjs"; import { slugify } from "../utils/tools.mjs"; import external_ActionsDropdown_mjs_default from "./ActionsDropdown.mjs"; import external_Breadcrumb_mjs_default from "./Breadcrumb.mjs"; import { buttonVariants } from "./radix/Button.mjs"; function FormHeader({ title, slug, icon, actions, resource, data, schema }) { const { t } = useI18n(); const { basePath, options } = useConfig(); const modelOptions = options?.model?.[resource]; const canCreate = !modelOptions?.permissions || modelOptions?.permissions?.includes(Permission.CREATE); const { edit, id } = getSchemas(data, schema, modelOptions?.edit?.fields); const breadcrumItems = [ { label: t(`model.${resource}.plural`, {}, title), href: `${basePath}/${slugify(resource)}`, icon }, { label: edit ? t("actions.edit.label") : t("actions.create.label"), href: `${basePath}/${slugify(resource)}/${id}`, current: !edit } ]; if (edit && id) breadcrumItems.push({ label: slug ?? id.toString(), href: `${basePath}/${slugify(resource)}/${id}`, current: true }); return /*#__PURE__*/ jsxs("div", { className: "bg-nextadmin-background-default dark:bg-dark-nextadmin-background-default dark:border-b-dark-nextadmin-border-default border-b-nextadmin-border-default sticky top-14 z-20 flex flex-row flex-wrap items-center justify-between gap-3 gap-4 border-b px-4 py-3 shadow-sm lg:top-0", children: [ /*#__PURE__*/ jsx(external_Breadcrumb_mjs_default, { breadcrumbItems: breadcrumItems }), /*#__PURE__*/ jsxs("div", { className: "flex items-center gap-2", children: [ !!actions && actions.length > 0 && !!id && /*#__PURE__*/ jsx(external_ActionsDropdown_mjs_default, { actions: actions, resource: resource, selectedIds: [ id ], selectedCount: 1 }), canCreate && /*#__PURE__*/ jsxs(Link_mjs_default, { href: `${basePath}/${slugify(resource)}/new`, role: "button", "data-testid": "add-new-button", className: buttonVariants({ variant: "default", size: "sm" }), children: [ /*#__PURE__*/ jsx("span", { children: t("list.header.add.label") }), /*#__PURE__*/ jsx(PlusSmallIcon, { className: "ml-2 h-5 w-5", "aria-hidden": "true" }) ] }) ] }) ] }); } export { FormHeader as default };