A full-featured CRM built with React, shadcn/ui, and Supabase.
contact create sheet
Jean-Baptiste Kaiserb832b230c33b
diff --git a/registry.json b/registry.jsonindex 37e14d7b..26442350 100644--- a/registry.json+++ b/registry.json@@ -392,6 +392,10 @@"path": "src/components/atomic-crm/misc/EditButton.tsx","type": "registry:component"},+ {+ "path": "src/components/atomic-crm/misc/CreateSheet.tsx",+ "type": "registry:component"+ },{"path": "src/components/atomic-crm/misc/ContactOption.tsx","type": "registry:component"diff --git a/src/components/atomic-crm/contacts/ContactCreate.tsx b/src/components/atomic-crm/contacts/ContactCreate.tsxindex 26455613..f9c9a320 100644--- a/src/components/atomic-crm/contacts/ContactCreate.tsx+++ b/src/components/atomic-crm/contacts/ContactCreate.tsx@@ -1,17 +1,11 @@import { Card, CardContent } from "@/components/ui/card";import { CreateBase, Form, useGetIdentity } from "ra-core";-import { SaveButton } from "@/components/admin";-import { useIsMobile } from "@/hooks/use-mobile";-import { MobileContent } from "../layout/MobileContent";-import MobileHeader from "../layout/MobileHeader";-import { MobileBackButton } from "../misc/MobileBackButton";+import { FormToolbar } from "../layout/FormToolbar";import type { Contact } from "../types";import { ContactInputs } from "./ContactInputs";-import { FormToolbar } from "../layout/FormToolbar";export const ContactCreate = () => {- const isMobile = useIsMobile();return (<CreateBaseredirect="show"@@ -22,7 +16,7 @@ export const ContactCreate = () => {tags: [],})}>- {isMobile ? <ContactCreateContentMobile /> : <ContactCreateContent />}+ <ContactCreateContent /></CreateBase>);};@@ -44,23 +38,3 @@ const ContactCreateContent = () => {</div>);};--const ContactCreateContentMobile = () => {- const { identity } = useGetIdentity();- return (- <div>- <MobileHeader>- <MobileBackButton />- <div className="flex flex-1 text-xl font-semibold">Create Contact</div>- </MobileHeader>- <MobileContent>- <Form defaultValues={{ sales_id: identity?.id }}>- <ContactInputs />- <div className="flex flex-col gap-2 mt-4">- <SaveButton />- </div>- </Form>- </MobileContent>- </div>- );-};diff --git a/src/components/atomic-crm/layout/MobileNavigation.tsx b/src/components/atomic-crm/layout/MobileNavigation.tsxindex da4b9ddd..cf16cb49 100644--- a/src/components/atomic-crm/layout/MobileNavigation.tsx+++ b/src/components/atomic-crm/layout/MobileNavigation.tsx@@ -35,6 +35,10 @@ import {useMatch,useNavigate,} from "react-router";+import { CreateSheet } from "../misc/CreateSheet";+import { ContactInputs } from "../contacts/ContactInputs";+import { useState } from "react";+import { type Contact } from "../types";export const MobileNavigation = () => {const location = useLocation();@@ -118,66 +122,96 @@ const CreateButton = () => {const navigate = useNavigate();const createPath = useCreatePath();+ const [contactCreateOpen, setContactCreateOpen] = useState(false);+return (- <DropdownMenu>- <DropdownMenuTrigger asChild>- <Button- variant="default"- size="icon"- className="h-16 w-16 rounded-full -mt-3"- aria-label="Create"- >- <Plus className="size-10" />- </Button>- </DropdownMenuTrigger>- <DropdownMenuContent>- <DropdownMenuItem- className="h-12 px-4 text-base"- onSelect={() => {- navigate(- createPath({- resource: "contacts",- type: "create",- }),- );- }}- >- Contact- </DropdownMenuItem>- <DropdownMenuItem- className="h-12 px-4 text-base"- onSelect={() => {- navigate(- createPath({- resource: "contactNotes",- type: "create",- }),- {- state: contact_id ? { record: { contact_id } } : undefined,- },- );- }}- >- Note- </DropdownMenuItem>- <DropdownMenuItem- className="h-12 px-4 text-base"- onSelect={() => {- navigate(- createPath({- resource: "tasks",- type: "create",- }),- {- state: contact_id ? { record: { contact_id } } : undefined,- },- );- }}- >- Task- </DropdownMenuItem>- </DropdownMenuContent>- </DropdownMenu>+ <>+ <ContactCreateSheet+ open={contactCreateOpen}+ onOpenChange={setContactCreateOpen}+ />+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <Button+ variant="default"+ size="icon"+ className="h-16 w-16 rounded-full -mt-3"+ aria-label="Create"+ >+ <Plus className="size-10" />+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent>+ <DropdownMenuItem+ className="h-12 px-4 text-base"+ onSelect={() => {+ setContactCreateOpen(true);+ }}+ >+ Contact+ </DropdownMenuItem>+ <DropdownMenuItem+ className="h-12 px-4 text-base"+ onSelect={() => {+ navigate(+ createPath({+ resource: "contactNotes",+ type: "create",+ }),+ {+ state: contact_id ? { record: { contact_id } } : undefined,+ },+ );+ }}+ >+ Note+ </DropdownMenuItem>+ <DropdownMenuItem+ className="h-12 px-4 text-base"+ onSelect={() => {+ navigate(+ createPath({+ resource: "tasks",+ type: "create",+ }),+ {+ state: contact_id ? { record: { contact_id } } : undefined,+ },+ );+ }}+ >+ Task+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ </>+ );+};++const ContactCreateSheet = ({+ open,+ onOpenChange,+}: {+ open: boolean;+ onOpenChange: (open: boolean) => void;+}) => {+ const { identity } = useGetIdentity();+ return (+ <CreateSheet+ resource="contacts"+ title="Create Contact"+ defaultValues={{ sales_id: identity?.id }}+ transform={(data: Contact) => ({+ ...data,+ first_seen: new Date().toISOString(),+ last_seen: new Date().toISOString(),+ tags: [],+ })}+ open={open}+ onOpenChange={onOpenChange}+ >+ <ContactInputs />+ </CreateSheet>);};diff --git a/src/components/atomic-crm/misc/CreateSheet.tsx b/src/components/atomic-crm/misc/CreateSheet.tsxnew file mode 100644index 00000000..a0137d74--- /dev/null+++ b/src/components/atomic-crm/misc/CreateSheet.tsx@@ -0,0 +1,155 @@+import { SaveButton } from "@/components/admin/form";+import { Button } from "@/components/ui/button";+import {+ Sheet,+ SheetClose,+ SheetContent,+ SheetFooter,+ SheetHeader,+ SheetTitle,+} from "@/components/ui/sheet";+import {+ CreateBase,+ Form,+ useNotify,+ useRedirect,+ useResourceContext,+ useTranslate,+ type CreateBaseProps,+ type FormProps,+} from "ra-core";+import { type ReactNode } from "react";++export interface CreateSheetProps extends CreateBaseProps {+ /**+ * The children elements that will be rendered inside the sheet as form inputs+ */+ children: ReactNode;++ /**+ * Controls whether the sheet is open+ */+ open: boolean;++ /**+ * Callback fired when the sheet open state changes+ */+ onOpenChange: (open: boolean) => void;++ /**+ * The title displayed in the sheet header+ */+ title?: string;++ /**+ * Default values for the form+ */+ defaultValues?: FormProps["defaultValues"];+}++/**+ * A Sheet component that contains a create form with externally controlled open state.+ *+ * Renders a Sheet containing a CreateBase form. The sheet has a fixed footer with Save and Close buttons.+ * The open state is controlled externally via the open and onOpenChange props. The sheet will automatically+ * close itself on successful submission (if redirect is false) or when the Close button is clicked.+ *+ * @example+ * ```tsx+ * const [open, setOpen] = useState(false);+ *+ * return (+ * <>+ * <Button onClick={() => setOpen(true)}>Create Contact</Button>+ * <CreateSheet+ * resource="contacts"+ * title="Create Contact"+ * open={open}+ * onOpenChange={setOpen}+ * >+ * <TextInput source="first_name" />+ * <TextInput source="last_name" />+ * <TextInput source="email" />+ * </CreateSheet>+ * </>+ * );+ * ```+ */+export const CreateSheet = ({+ children,+ open,+ onOpenChange,+ title = "Create",+ redirect: redirectTo = "show",+ mutationOptions,+ defaultValues,+ ...createBaseProps+}: CreateSheetProps) => {+ const resource = useResourceContext(createBaseProps);+ const translate = useTranslate();+ const notify = useNotify();+ const redirect = useRedirect();++ // Handle success - close sheet if redirect is false+ const handleSuccess = (...args: any[]) => {+ if (mutationOptions?.onSuccess) {+ mutationOptions.onSuccess(+ ...(args as Parameters<typeof mutationOptions.onSuccess>),+ );+ }+ const [data] = args;+ notify(`resources.${resource}.notifications.created`, {+ type: "info",+ messageArgs: {+ smart_count: 1,+ _: translate(`ra.notification.created`, {+ smart_count: 1,+ }),+ },+ undoable: createBaseProps.mutationMode === "undoable",+ });+ redirect(redirectTo, resource, data.id, data);+ onOpenChange(false);+ };++ const enhancedMutationOptions = {+ ...mutationOptions,+ onSuccess: handleSuccess,+ };++ return (+ <Sheet open={open} onOpenChange={onOpenChange}>+ <SheetContent side="bottom" className="h-screen flex flex-col">+ <CreateBase+ {...createBaseProps}+ redirect={redirectTo}+ mutationOptions={enhancedMutationOptions}+ >+ <Form+ defaultValues={defaultValues}+ className="h-screen flex-1 flex flex-col"+ >+ <SheetHeader className="border-b">+ <SheetTitle>{title}</SheetTitle>+ </SheetHeader>++ <div className="flex-1 overflow-y-auto flex flex-col gap-3 p-4">+ {children}+ </div>++ <SheetFooter className="border-t">+ <div className="flex w-full gap-4">+ <SheetClose asChild>+ <Button variant="ghost" className="flex-1">+ Close+ </Button>+ </SheetClose>+ <SaveButton className="flex-1" />+ </div>+ </SheetFooter>+ </Form>+ </CreateBase>+ </SheetContent>+ </Sheet>+ );+};diff --git a/src/components/atomic-crm/root/CRM.tsx b/src/components/atomic-crm/root/CRM.tsxindex 593bc796..a8a43597 100644--- a/src/components/atomic-crm/root/CRM.tsx+++ b/src/components/atomic-crm/root/CRM.tsx@@ -49,6 +49,8 @@ import { MobileTaskEdit } from "../tasks/MobileTaskEdit.tsx";import { MobileTaskCreate } from "../tasks/MobileTaskCreate.tsx";import { MobileNoteEdit } from "../notes/MobileNoteEdit.tsx";import { MobileNoteCreate } from "../notes/MobileNoteCreate.tsx";+import { ContactList } from "../contacts/ContactList.tsx";+import { ContactShow } from "../contacts/ContactShow.tsx";export type CRMProps = {dataProvider?: DataProvider;@@ -216,7 +218,7 @@ const MobileAdmin = (props: CoreAdminProps) => {/><Route path={OAuthConsentPage.path} element={<OAuthConsentPage />} /></CustomRoutes>- <Resource name="contacts" {...contacts} />+ <Resource name="contacts" list={ContactList} show={ContactShow} /><Resourcename="contactNotes"edit={MobileNoteEdit}