A full-featured CRM built with React, shadcn/ui, and Supabase.
import {
Breadcrumb,
BreadcrumbItem,
BreadcrumbPage,
} from "@/components/admin/breadcrumb";
import type { CreateBaseProps } from "ra-core";
import {
LinkBase,
CreateBase,
Translate,
useCreateContext,
useCreatePath,
useGetResourceLabel,
useHasDashboard,
useResourceContext,
} from "ra-core";
import type { ReactNode } from "react";
import { cn } from "@/lib/utils";
export type CreateProps = CreateViewProps & CreateBaseProps;
/**
* A complete create page with breadcrumb, title, and actions.
*
* Combines data fetching, form context, and UI layout for creating new records. Renders breadcrumb
* navigation, page title, and wraps your form components.
*
* @see {@link https://marmelab.com/shadcn-admin-kit/docs/create/ Create documentation}
*
* @example
* import { Create, SimpleForm, TextInput } from '@/components/admin';
*
* export const PostCreate = () => (
* <Create>
* <SimpleForm>
* <TextInput source="title" />
* <TextInput source="body" />
* </SimpleForm>
* </Create>
* );
*/
export const Create = ({
actions,
children,
className,
disableBreadcrumb,
title,
...rest
}: CreateProps) => (
<CreateBase {...rest}>
<CreateView
actions={actions}
className={className}
disableBreadcrumb={disableBreadcrumb}
title={title}
>
{children}
</CreateView>
</CreateBase>
);
export type CreateViewProps = {
actions?: ReactNode;
disableBreadcrumb?: boolean;
children: ReactNode;
className?: string;
title?: ReactNode | string | false;
};
/**
* The view component for Create pages with layout and UI.
*
* @internal
*/
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 && (
<Breadcrumb>
{hasDashboard && (
<BreadcrumbItem>
<LinkBase to="/">
<Translate i18nKey="ra.page.dashboard">Home</Translate>
</LinkBase>
</BreadcrumbItem>
)}
<BreadcrumbItem>
<LinkBase to={listLink}>{listLabel}</LinkBase>
</BreadcrumbItem>
<BreadcrumbPage>
<Translate i18nKey="ra.action.create">Create</Translate>
</BreadcrumbPage>
</Breadcrumb>
)}
<div
className={cn(
"flex justify-between items-start flex-wrap gap-2 my-2",
className,
)}
>
<h2 className="text-2xl font-bold tracking-tight">
{title !== undefined ? title : context.defaultTitle}
</h2>
{actions}
</div>
<div className="my-2">{children}</div>
</>
);
};