Skip to content

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

fix record state pollutes submitted record

Jean-Baptiste Kaiserfb0f5eaa0ab2
diff --git a/src/components/atomic-crm/contacts/ContactShow.tsx b/src/components/atomic-crm/contacts/ContactShow.tsx
index 88afb56b..4994513e 100644
--- a/src/components/atomic-crm/contacts/ContactShow.tsx
+++ b/src/components/atomic-crm/contacts/ContactShow.tsx
@@ -103,11 +103,7 @@ const ContactShowContentMobile = () => {
<CreateButton
resource="contactNotes"
state={{
- record: {
- reference_id: record.id,
- reference: "contacts",
- showStatus: true,
- },
+ record: { contact_id: record.id },
}}
label="Add note"
/>
diff --git a/src/components/atomic-crm/layout/MobileNavigation.tsx b/src/components/atomic-crm/layout/MobileNavigation.tsx
index 0e638833..98bf053c 100644
--- a/src/components/atomic-crm/layout/MobileNavigation.tsx
+++ b/src/components/atomic-crm/layout/MobileNavigation.tsx
@@ -143,13 +143,7 @@ const CreateButton = () => {
type: "create",
}),
{
- state: {
- record: {
- reference_id: contact_id || undefined,
- reference: "contacts",
- showStatus: true,
- },
- },
+ state: contact_id ? { record: { contact_id } } : undefined,
},
);
}}
diff --git a/src/components/atomic-crm/notes/MobileNoteCreate.tsx b/src/components/atomic-crm/notes/MobileNoteCreate.tsx
index c97574d8..778d8fbf 100644
--- a/src/components/atomic-crm/notes/MobileNoteCreate.tsx
+++ b/src/components/atomic-crm/notes/MobileNoteCreate.tsx
@@ -17,30 +17,27 @@ import { NoteInputs } from "./NoteInputs";
export const MobileNoteCreate = () => {
const { identity } = useGetIdentity();
const createPath = useCreatePath();
- const recordFromLocation = useRecordFromLocation() || {};
- const { reference_id, reference, showStatus } = recordFromLocation;
- const selectReference = reference_id == null;
+ const recordFromLocation = useRecordFromLocation();
+ const contact_id = recordFromLocation?.contact_id;
+ const selectContact = contact_id == null;
- const { data: referenceRecord } = useGetOne(
- reference,
- { id: reference_id! },
- { enabled: !!reference_id && !!reference },
+ const { data: contact } = useGetOne(
+ "contacts",
+ { id: contact_id! },
+ { enabled: !!contact_id },
);
- if (!reference || !identity) return null;
+ if (!identity) return null;
return (
- <CreateBase redirect={createPath({ resource: reference, type: "list" })}>
+ <CreateBase redirect={createPath({ resource: "contacts", type: "list" })}>
<MobileHeader>
- <ListButton resource={reference} />
+ <ListButton resource="contacts" />
<div className="flex flex-1">
<h1 className="text-xl font-semibold text-ellipsis overflow-hidden whitespace-nowrap">
- {!selectReference ? "Create Note for " : "Create Note"}
- {!selectReference && (
- <RecordRepresentation
- record={referenceRecord}
- resource={reference}
- />
+ {!selectContact ? "Create Note for " : "Create Note"}
+ {!selectContact && (
+ <RecordRepresentation record={contact} resource="contacts" />
)}
</h1>
</div>
@@ -49,11 +46,11 @@ export const MobileNoteCreate = () => {
<Form>
<div className="space-y-3">
<NoteInputs
- showStatus={showStatus}
- selectReference={selectReference}
- reference={reference}
+ showStatus
+ reference="contacts"
+ selectReference={selectContact}
/>
- <NoteCreateButton reference={reference} record={referenceRecord} />
+ <NoteCreateButton reference="contacts" record={contact} />
</div>
</Form>
</MobileContent>
diff --git a/src/components/atomic-crm/notes/MobileNoteEdit.tsx b/src/components/atomic-crm/notes/MobileNoteEdit.tsx
index 7810c8eb..7134ecf2 100644
--- a/src/components/atomic-crm/notes/MobileNoteEdit.tsx
+++ b/src/components/atomic-crm/notes/MobileNoteEdit.tsx
@@ -4,7 +4,6 @@ import {
RecordRepresentation,
useCreatePath,
useGetIdentity,
- useRecordFromLocation,
} from "ra-core";
import { NoteInputs } from "./NoteInputs";
@@ -12,24 +11,21 @@ import { DeleteButton, ReferenceField, SaveButton } from "@/components/admin";
import MobileHeader from "../layout/MobileHeader";
import { ListButton } from "../misc/ListButton";
import { MobileContent } from "../layout/MobileContent";
-import { foreignKeyMapping } from "./foreignKeyMapping";
export const MobileNoteEdit = () => {
const { identity } = useGetIdentity();
const createPath = useCreatePath();
- const recordFromLocation = useRecordFromLocation() || {};
- const { reference, showStatus } = recordFromLocation;
- if (!identity || !reference) return null;
+ if (!identity) return null;
return (
- <EditBase redirect={createPath({ resource: reference, type: "list" })}>
+ <EditBase redirect={createPath({ resource: "contacts", type: "list" })}>
<MobileHeader>
- <ListButton resource={reference} />
+ <ListButton resource="contacts" />
<div className="flex flex-1">
<ReferenceField
- source={foreignKeyMapping[reference as "contacts" | "deals"]}
- reference={reference}
+ source="contact_id"
+ reference="contacts"
render={({ referenceRecord }) => (
<h1 className="text-xl font-semibold text-ellipsis overflow-hidden whitespace-nowrap">
Edit Note
@@ -38,7 +34,7 @@ export const MobileNoteEdit = () => {
{" for "}
<RecordRepresentation
record={referenceRecord}
- resource={reference}
+ resource="contacts"
/>
</>
) : null}
@@ -49,11 +45,11 @@ export const MobileNoteEdit = () => {
</MobileHeader>
<MobileContent>
<Form className="mt-1">
- <NoteInputs showStatus={showStatus} />
+ <NoteInputs showStatus />
<div className="flex flex-col gap-2 mt-6">
<SaveButton />
<DeleteButton
- redirect={createPath({ resource: reference, type: "list" })}
+ redirect={createPath({ resource: "contacts", type: "list" })}
/>
</div>
</Form>