// This file is part of Shadcn Admin Kit (https://github.com/marmelab/shadcn-admin-kit)
import {
Breadcrumb,
BreadcrumbItem,
BreadcrumbPage,
} from "@/components/admin/breadcrumb";
import type { CreateBaseProps } from "ra-core";
import {
CreateBase,
Translate,
useCreateContext,
useCreatePath,
useGetResourceLabel,
useHasDashboard,
useResourceContext,
} from "ra-core";
import type { ReactNode } from "react";
import { Link } from "react-router";
import { cn } from "@/lib/utils";
export type CreateProps = CreateViewProps & CreateBaseProps;
export const Create = ({
actions,
children,
className,
disableBreadcrumb,
title,
...rest
}: CreateProps) => (
{children}
);
export type CreateViewProps = {
actions?: ReactNode;
disableBreadcrumb?: boolean;
children: ReactNode;
className?: string;
title?: ReactNode | string | false;
};
export const CreateView = ({
actions,
disableBreadcrumb,
title,
children,
className,
}: CreateViewProps) => {
const context = useCreateContext();
const resource = useResourceContext();
if (!resource) {
throw new Error(
"The CreateView component must be used within a ResourceContextProvider",
);
}
const getResourceLabel = useGetResourceLabel();
const listLabel = getResourceLabel(resource, 2);
const createPath = useCreatePath();
const listLink = createPath({
resource,
type: "list",
});
const hasDashboard = useHasDashboard();
return (
<>
{!disableBreadcrumb && (
{hasDashboard && (
Home
)}
{listLabel}
Create
)}
{title !== undefined ? title : context.defaultTitle}
{actions}
{children}
>
);
};