Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

contact create and edit

Jean-Baptiste Kaiserba3b5cabb7d5
diff --git a/registry.json b/registry.json
index 8a1eee65..5fdf63ec 100644
--- a/registry.json
+++ b/registry.json
@@ -388,6 +388,10 @@
"path": "src/components/atomic-crm/misc/ImageEditorField.tsx",
"type": "registry:component"
},
+ {
+ "path": "src/components/atomic-crm/misc/EditButton.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.tsx
index c26031f8..96af9343 100644
--- a/src/components/atomic-crm/contacts/ContactCreate.tsx
+++ b/src/components/atomic-crm/contacts/ContactCreate.tsx
@@ -1,12 +1,17 @@
-import { CreateBase, Form, useGetIdentity } from "ra-core";
-import { FormToolbar } from "@/components/admin/simple-form";
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 { ListButton } from "../misc/ListButton";
import type { Contact } from "../types";
import { ContactInputs } from "./ContactInputs";
+import { FormToolbar } from "../layout/FormToolbar";
export const ContactCreate = () => {
- const { identity } = useGetIdentity();
+ const isMobile = useIsMobile();
return (
<CreateBase
redirect="show"
@@ -17,18 +22,45 @@ export const ContactCreate = () => {
tags: [],
})}
>
- <div className="mt-2 flex lg:mr-72">
- <div className="flex-1">
- <Form defaultValues={{ sales_id: identity?.id }}>
- <Card>
- <CardContent>
- <ContactInputs />
- <FormToolbar />
- </CardContent>
- </Card>
- </Form>
- </div>
- </div>
+ {isMobile ? <ContactCreateContentMobile /> : <ContactCreateContent />}
</CreateBase>
);
};
+
+const ContactCreateContent = () => {
+ const { identity } = useGetIdentity();
+ return (
+ <div className="mt-2 flex lg:mr-72">
+ <div className="flex-1">
+ <Form defaultValues={{ sales_id: identity?.id }}>
+ <Card>
+ <CardContent>
+ <ContactInputs />
+ <FormToolbar />
+ </CardContent>
+ </Card>
+ </Form>
+ </div>
+ </div>
+ );
+};
+
+const ContactCreateContentMobile = () => {
+ const { identity } = useGetIdentity();
+ return (
+ <div>
+ <MobileHeader>
+ <ListButton />
+ <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/contacts/ContactEdit.tsx b/src/components/atomic-crm/contacts/ContactEdit.tsx
index fe5e4d0d..df897052 100644
--- a/src/components/atomic-crm/contacts/ContactEdit.tsx
+++ b/src/components/atomic-crm/contacts/ContactEdit.tsx
@@ -1,16 +1,24 @@
import { Card, CardContent } from "@/components/ui/card";
-import { EditBase, Form, useEditContext } from "ra-core";
+import { EditBase, Form, RecordRepresentation, useEditContext } from "ra-core";
+import { useIsMobile } from "@/hooks/use-mobile";
+import { FormToolbar } from "../layout/FormToolbar";
+import { MobileContent } from "../layout/MobileContent";
+import MobileHeader from "../layout/MobileHeader";
+import { ListButton } from "../misc/ListButton";
import type { Contact } from "../types";
import { ContactAside } from "./ContactAside";
import { ContactInputs } from "./ContactInputs";
-import { FormToolbar } from "../layout/FormToolbar";
+import { DeleteButton, SaveButton } from "@/components/admin";
-export const ContactEdit = () => (
- <EditBase redirect="show">
- <ContactEditContent />
- </EditBase>
-);
+export const ContactEdit = () => {
+ const isMobile = useIsMobile();
+ return (
+ <EditBase redirect="show">
+ {isMobile ? <ContactEditContentMobile /> : <ContactEditContent />}
+ </EditBase>
+ );
+};
const ContactEditContent = () => {
const { isPending, record } = useEditContext<Contact>();
@@ -30,3 +38,27 @@ const ContactEditContent = () => {
</div>
);
};
+
+const ContactEditContentMobile = () => {
+ const { isPending, record } = useEditContext<Contact>();
+ if (isPending || !record) return null;
+ return (
+ <div>
+ <MobileHeader>
+ <ListButton />
+ <div className="flex flex-1 text-xl font-semibold text-ellipsis overflow-hidden whitespace-nowrap">
+ Edit <RecordRepresentation />
+ </div>
+ </MobileHeader>
+ <MobileContent>
+ <Form className="flex flex-1 flex-col gap-4">
+ <ContactInputs />
+ <div className="flex flex-col gap-2 mt-4">
+ <SaveButton />
+ <DeleteButton />
+ </div>
+ </Form>
+ </MobileContent>
+ </div>
+ );
+};
diff --git a/src/components/atomic-crm/contacts/ContactInputs.tsx b/src/components/atomic-crm/contacts/ContactInputs.tsx
index 787f7808..7edb04ce 100644
--- a/src/components/atomic-crm/contacts/ContactInputs.tsx
+++ b/src/components/atomic-crm/contacts/ContactInputs.tsx
@@ -21,17 +21,18 @@ export const ContactInputs = () => {
const isMobile = useIsMobile();
return (
- <div className="flex flex-col gap-2 p-1">
- <Avatar />
- <div className={`flex gap-6 ${isMobile ? "flex-col" : "flex-row"}`}>
+ <div className="flex flex-col gap-2 p-1 relative md:static">
+ <div className="absolute top-0 right-1 md:static">
+ <Avatar />
+ </div>
+ <div className="flex gap-10 md:gap-6 flex-col md:flex-row">
<div className="flex flex-col gap-10 flex-1">
<ContactIdentityInputs />
<ContactPositionInputs />
</div>
- <Separator
- orientation={isMobile ? "horizontal" : "vertical"}
- className="flex-shrink-0"
- />
+ {isMobile ? null : (
+ <Separator orientation="vertical" className="flex-shrink-0" />
+ )}
<div className="flex flex-col gap-10 flex-1">
<ContactPersonalInformationInputs />
<ContactMiscInputs />
diff --git a/src/components/atomic-crm/contacts/ContactShow.tsx b/src/components/atomic-crm/contacts/ContactShow.tsx
index 4994513e..49267e4e 100644
--- a/src/components/atomic-crm/contacts/ContactShow.tsx
+++ b/src/components/atomic-crm/contacts/ContactShow.tsx
@@ -19,6 +19,7 @@ import type { Contact } from "../types";
import { Avatar } from "./Avatar";
import { ContactAside } from "./ContactAside";
import { ListButton } from "../misc/ListButton";
+import { EditButton } from "../misc/EditButton";
import { CreateButton } from "@/components/admin";
export const ContactShow = () => {
@@ -42,6 +43,7 @@ const ContactShowContentMobile = () => {
<div className="flex flex-1">
<h1 className="text-xl font-semibold">Contacts</h1>
</div>
+ <EditButton />
</MobileHeader>
<MobileContent>
<div className="mb-6">
diff --git a/src/components/atomic-crm/layout/MobileNavigation.tsx b/src/components/atomic-crm/layout/MobileNavigation.tsx
index 98bf053c..da4b9ddd 100644
--- a/src/components/atomic-crm/layout/MobileNavigation.tsx
+++ b/src/components/atomic-crm/layout/MobileNavigation.tsx
@@ -131,7 +131,17 @@ const CreateButton = () => {
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent>
- <DropdownMenuItem className="h-12 px-4 text-base">
+ <DropdownMenuItem
+ className="h-12 px-4 text-base"
+ onSelect={() => {
+ navigate(
+ createPath({
+ resource: "contacts",
+ type: "create",
+ }),
+ );
+ }}
+ >
Contact
</DropdownMenuItem>
<DropdownMenuItem
diff --git a/src/components/atomic-crm/misc/EditButton.tsx b/src/components/atomic-crm/misc/EditButton.tsx
new file mode 100644
index 00000000..a481a9c8
--- /dev/null
+++ b/src/components/atomic-crm/misc/EditButton.tsx
@@ -0,0 +1,33 @@
+import { Button } from "@/components/ui/button";
+import { Pencil } from "lucide-react";
+import type { RaRecord } from "ra-core";
+import { useCreatePath, useRecordContext, useResourceContext } from "ra-core";
+import { useNavigate } from "react-router";
+
+export const EditButton = (props: { resource?: string; record?: RaRecord }) => {
+ const resource = useResourceContext(props);
+ const record = useRecordContext(props);
+ const navigate = useNavigate();
+ const createPath = useCreatePath();
+ const to = createPath({
+ resource,
+ type: "edit",
+ id: record?.id,
+ });
+
+ return (
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon"
+ className="rounded-full"
+ onClick={(e) => {
+ e.preventDefault();
+ navigate(to);
+ }}
+ >
+ <Pencil className="size-6" />
+ <span className="sr-only">Edit record</span>
+ </Button>
+ );
+};