Skip to content

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

Clean up mobile nav buttons and views

Jean-Baptiste Kaisercc19ee1ccf71
diff --git a/registry.json b/registry.json
index 2d3e5b5d..48c5cd5f 100644
--- a/registry.json
+++ b/registry.json
@@ -60,14 +60,6 @@
"path": "src/components/atomic-crm/tasks/MobileTasksList.tsx",
"type": "registry:component"
},
- {
- "path": "src/components/atomic-crm/tasks/MobileTaskEdit.tsx",
- "type": "registry:component"
- },
- {
- "path": "src/components/atomic-crm/tasks/MobileTaskCreate.tsx",
- "type": "registry:component"
- },
{
"path": "src/components/atomic-crm/tasks/AddTask.tsx",
"type": "registry:component"
@@ -352,14 +344,6 @@
"path": "src/components/atomic-crm/notes/Note.tsx",
"type": "registry:component"
},
- {
- "path": "src/components/atomic-crm/notes/MobileNoteEdit.tsx",
- "type": "registry:component"
- },
- {
- "path": "src/components/atomic-crm/notes/MobileNoteCreate.tsx",
- "type": "registry:component"
- },
{
"path": "src/components/atomic-crm/misc/usePapaParse.tsx",
"type": "registry:component"
@@ -408,10 +392,6 @@
"path": "src/components/atomic-crm/misc/EditSheet.tsx",
"type": "registry:component"
},
- {
- "path": "src/components/atomic-crm/misc/EditButton.tsx",
- "type": "registry:component"
- },
{
"path": "src/components/atomic-crm/misc/CreateSheet.tsx",
"type": "registry:component"
diff --git a/src/components/atomic-crm/misc/EditButton.tsx b/src/components/atomic-crm/misc/EditButton.tsx
deleted file mode 100644
index a481a9c8..00000000
--- a/src/components/atomic-crm/misc/EditButton.tsx
+++ /dev/null
@@ -1,33 +0,0 @@
-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>
- );
-};
diff --git a/src/components/atomic-crm/misc/MobileBackButton.tsx b/src/components/atomic-crm/misc/MobileBackButton.tsx
index a07b180d..c2e3b1de 100644
--- a/src/components/atomic-crm/misc/MobileBackButton.tsx
+++ b/src/components/atomic-crm/misc/MobileBackButton.tsx
@@ -1,25 +1,18 @@
-import {
- useResourceContext,
- useCreatePath,
- useRecordFromLocation,
-} from "ra-core";
+import { useResourceContext, useCreatePath } from "ra-core";
import { useNavigate } from "react-router";
import { ChevronLeft } from "lucide-react";
import { Button } from "@/components/ui/button";
export const MobileBackButton = (props: { resource?: string; to?: string }) => {
const resource = useResourceContext(props);
- const recordFromLocation = useRecordFromLocation();
- const contact_id = recordFromLocation?.contact_id;
const navigate = useNavigate();
const createPath = useCreatePath();
const { to } = props;
const finalTo =
to ??
createPath({
- resource: contact_id ? "contacts" : resource,
- type: contact_id ? "show" : "list",
- id: contact_id,
+ resource,
+ type: "list",
});
return (
@@ -34,7 +27,7 @@ export const MobileBackButton = (props: { resource?: string; to?: string }) => {
}}
>
<ChevronLeft className="size-6" />
- <span className="sr-only">Back to {contact_id ? "contact" : "list"}</span>
+ <span className="sr-only">Back{to ? "" : " to list"}</span>
</Button>
);
};
diff --git a/src/components/atomic-crm/notes/MobileNoteCreate.tsx b/src/components/atomic-crm/notes/MobileNoteCreate.tsx
deleted file mode 100644
index 7b1b4ae1..00000000
--- a/src/components/atomic-crm/notes/MobileNoteCreate.tsx
+++ /dev/null
@@ -1,59 +0,0 @@
-import {
- CreateBase,
- Form,
- RecordRepresentation,
- useCreatePath,
- useGetIdentity,
- useGetOne,
- useRecordFromLocation,
-} from "ra-core";
-
-import { MobileContent } from "../layout/MobileContent";
-import MobileHeader from "../layout/MobileHeader";
-import { MobileBackButton } from "../misc/MobileBackButton";
-import { NoteCreateButton } from "./NoteCreate";
-import { NoteInputs } from "./NoteInputs";
-
-export const MobileNoteCreate = () => {
- const { identity } = useGetIdentity();
- const createPath = useCreatePath();
- const recordFromLocation = useRecordFromLocation();
- const contact_id = recordFromLocation?.contact_id;
- const selectContact = contact_id == null;
-
- const { data: contact } = useGetOne(
- "contacts",
- { id: contact_id! },
- { enabled: !!contact_id },
- );
-
- if (!identity) return null;
-
- return (
- <CreateBase redirect={createPath({ resource: "contacts", type: "list" })}>
- <MobileHeader>
- <MobileBackButton resource="contacts" />
- <div className="flex flex-1">
- <h1 className="text-xl font-semibold text-ellipsis overflow-hidden whitespace-nowrap">
- {!selectContact ? "Create Note for " : "Create Note"}
- {!selectContact && (
- <RecordRepresentation record={contact} resource="contacts" />
- )}
- </h1>
- </div>
- </MobileHeader>
- <MobileContent>
- <Form>
- <div className="space-y-3">
- <NoteInputs
- showStatus
- reference="contacts"
- selectReference={selectContact}
- />
- <NoteCreateButton reference="contacts" record={contact} />
- </div>
- </Form>
- </MobileContent>
- </CreateBase>
- );
-};
diff --git a/src/components/atomic-crm/notes/MobileNoteEdit.tsx b/src/components/atomic-crm/notes/MobileNoteEdit.tsx
deleted file mode 100644
index 0bdfbc30..00000000
--- a/src/components/atomic-crm/notes/MobileNoteEdit.tsx
+++ /dev/null
@@ -1,67 +0,0 @@
-import type { Identifier, RaRecord } from "ra-core";
-import {
- EditBase,
- Form,
- RecordRepresentation,
- useCreatePath,
- useGetIdentity,
- WithRecord,
-} from "ra-core";
-
-import { DeleteButton, ReferenceField, SaveButton } from "@/components/admin";
-import { MobileContent } from "../layout/MobileContent";
-import MobileHeader from "../layout/MobileHeader";
-import { MobileBackButton } from "../misc/MobileBackButton";
-import { NoteInputs } from "./NoteInputs";
-
-export const MobileNoteEdit = () => {
- const { identity } = useGetIdentity();
- const createPath = useCreatePath();
- const getRedirectTo = (record: Partial<RaRecord<Identifier>> | undefined) =>
- createPath({ resource: "contacts", type: "show", id: record?.contact_id });
-
- if (!identity) return null;
-
- return (
- <EditBase redirect={(_resource, _id, record) => getRedirectTo(record)}>
- <MobileHeader>
- <WithRecord
- render={(record) => <MobileBackButton to={getRedirectTo(record)} />}
- />
- <div className="flex flex-1">
- <ReferenceField
- source="contact_id"
- reference="contacts"
- render={({ referenceRecord }) => (
- <h1 className="text-xl font-semibold text-ellipsis overflow-hidden whitespace-nowrap">
- Edit Note
- {referenceRecord ? (
- <>
- {" for "}
- <RecordRepresentation
- record={referenceRecord}
- resource="contacts"
- />
- </>
- ) : null}
- </h1>
- )}
- />
- </div>
- </MobileHeader>
- <MobileContent>
- <Form className="mt-1">
- <NoteInputs showStatus />
- <div className="flex flex-col gap-2 mt-6">
- <SaveButton />
- <WithRecord
- render={(record) => (
- <DeleteButton redirect={getRedirectTo(record)} />
- )}
- />
- </div>
- </Form>
- </MobileContent>
- </EditBase>
- );
-};
diff --git a/src/components/atomic-crm/tasks/MobileTaskCreate.tsx b/src/components/atomic-crm/tasks/MobileTaskCreate.tsx
deleted file mode 100644
index 29f94e11..00000000
--- a/src/components/atomic-crm/tasks/MobileTaskCreate.tsx
+++ /dev/null
@@ -1,96 +0,0 @@
-import { SaveButton } from "@/components/admin";
-import {
- CreateBase,
- Form,
- RecordRepresentation,
- useDataProvider,
- useGetIdentity,
- useGetOne,
- useNotify,
- useRecordFromLocation,
- useRedirect,
- useUpdate,
-} from "ra-core";
-import { MobileContent } from "../layout/MobileContent";
-import MobileHeader from "../layout/MobileHeader";
-import { MobileBackButton } from "../misc/MobileBackButton";
-import { TaskFormContent } from "./TaskFormContent";
-
-export const MobileTaskCreate = () => {
- const { identity } = useGetIdentity();
- const dataProvider = useDataProvider();
- const [update] = useUpdate();
- const notify = useNotify();
- const redirect = useRedirect();
- const recordFromLocation = useRecordFromLocation();
- const contact_id = recordFromLocation?.contact_id;
- const selectContact = contact_id == null;
-
- const { data: contact } = useGetOne(
- "contacts",
- { id: contact_id! },
- { enabled: !!contact_id },
- );
-
- const handleSuccess = async (data: any) => {
- const contact = await dataProvider.getOne("contacts", {
- id: data.contact_id,
- });
- if (!contact.data) return;
-
- await update("contacts", {
- id: contact.data.id,
- data: { last_seen: new Date().toISOString() },
- previousData: contact.data,
- });
-
- notify("Task added");
- redirect(
- selectContact ? "list" : "show",
- selectContact ? "tasks" : "contacts",
- selectContact ? undefined : contact_id,
- );
- };
-
- if (!identity) return null;
-
- return (
- <CreateBase
- record={{
- type: "None",
- contact_id: contact?.id,
- due_date: new Date().toISOString().slice(0, 10),
- sales_id: identity.id,
- }}
- transform={(data) => {
- const dueDate = new Date(data.due_date);
- dueDate.setHours(0, 0, 0, 0);
- return {
- ...data,
- due_date: dueDate.toISOString(),
- };
- }}
- mutationOptions={{ onSuccess: handleSuccess }}
- >
- <MobileHeader>
- <MobileBackButton />
- <div className="flex flex-1">
- <h1 className="text-xl font-semibold text-ellipsis overflow-hidden whitespace-nowrap">
- {!selectContact ? "Create Task for " : "Create Task"}
- {!selectContact && (
- <RecordRepresentation record={contact} resource="contacts" />
- )}
- </h1>
- </div>
- </MobileHeader>
- <MobileContent>
- <Form>
- <TaskFormContent selectContact={selectContact} />
- <div className="flex flex-col gap-2 mt-6">
- <SaveButton />
- </div>
- </Form>
- </MobileContent>
- </CreateBase>
- );
-};
diff --git a/src/components/atomic-crm/tasks/MobileTaskEdit.tsx b/src/components/atomic-crm/tasks/MobileTaskEdit.tsx
deleted file mode 100644
index e59e4504..00000000
--- a/src/components/atomic-crm/tasks/MobileTaskEdit.tsx
+++ /dev/null
@@ -1,49 +0,0 @@
-import { EditBase, Form, RecordRepresentation } from "ra-core";
-import MobileHeader from "../layout/MobileHeader";
-import { MobileContent } from "../layout/MobileContent";
-import { TaskFormContent } from "./TaskFormContent";
-import { DeleteButton, ReferenceField, SaveButton } from "@/components/admin";
-import { MobileBackButton } from "../misc/MobileBackButton";
-import { useLocation } from "react-router";
-
-export const MobileTaskEdit = () => {
- const location = useLocation();
- const from = location.state?.from as string | undefined;
-
- return (
- <EditBase redirect={from}>
- <MobileHeader>
- <MobileBackButton to={from} />
- <div className="flex flex-1">
- <ReferenceField
- source="contact_id"
- reference="contacts"
- render={({ referenceRecord: contact }) => (
- <h1 className="text-xl font-semibold text-ellipsis overflow-hidden whitespace-nowrap">
- Edit Task
- {contact ? (
- <>
- {" for "}
- <RecordRepresentation
- record={contact}
- resource="contacts"
- />
- </>
- ) : null}
- </h1>
- )}
- />
- </div>
- </MobileHeader>
- <MobileContent>
- <Form>
- <TaskFormContent />
- <div className="flex flex-col gap-2 mt-6">
- <SaveButton />
- <DeleteButton redirect={from} />
- </div>
- </Form>
- </MobileContent>
- </EditBase>
- );
-};