Skip to content

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

Fix fakerest deal note attachment previews

Anibal Svarcas56576f1cb3f0
diff --git a/src/components/atomic-crm/providers/fakerest/dataProvider.ts b/src/components/atomic-crm/providers/fakerest/dataProvider.ts
index a95875bb..91631e4f 100644
--- a/src/components/atomic-crm/providers/fakerest/dataProvider.ts
+++ b/src/components/atomic-crm/providers/fakerest/dataProvider.ts
@@ -13,6 +13,7 @@ import type {
Contact,
ContactNote,
Deal,
+ DealNote,
Sale,
SalesFormData,
SignUpData,
@@ -244,6 +245,18 @@ async function updateCompany(
});
}
+const preserveAttachmentMimeType = <
+ NoteType extends { attachments?: Array<{ rawFile?: File; type?: string }> },
+>(
+ note: NoteType,
+): NoteType => ({
+ ...note,
+ attachments: (note.attachments ?? []).map((attachment) => ({
+ ...attachment,
+ type: attachment.rawFile?.type ?? attachment.type,
+ })),
+});
+
export const dataProvider = withLifecycleCallbacks(
withSupabaseFilterAdapter(dataProviderWithCustomMethod),
[
@@ -502,16 +515,12 @@ export const dataProvider = withLifecycleCallbacks(
} satisfies ResourceCallbacks<Deal>,
{
resource: "contact_notes",
- beforeSave: async (params) => {
- return {
- ...params,
- attachments: (params.attachments ?? []).map((attachment) => ({
- ...attachment,
- type: attachment.rawFile.type ?? attachment.type,
- })),
- };
- },
+ beforeSave: async (params) => preserveAttachmentMimeType(params),
} satisfies ResourceCallbacks<ContactNote>,
+ {
+ resource: "deal_notes",
+ beforeSave: async (params) => preserveAttachmentMimeType(params),
+ } satisfies ResourceCallbacks<DealNote>,
],
);