A full-featured CRM built with React, shadcn/ui, and Supabase.
[Breaking change] Ensure all tables and their fields are named in snake case
Gildas Garcia461c718f07c8
diff --git a/src/components/atomic-crm/companies/CompanyAside.tsx b/src/components/atomic-crm/companies/CompanyAside.tsxindex 0125abe8..e33cc4c8 100644--- a/src/components/atomic-crm/companies/CompanyAside.tsx+++ b/src/components/atomic-crm/companies/CompanyAside.tsx@@ -128,7 +128,12 @@ const ContextInfo = ({ record }: { record: Company }) => {};const AddressInfo = ({ record }: { record: Company }) => {- if (!record.address && !record.city && !record.zipcode && !record.stateAbbr) {+ if (+ !record.address &&+ !record.city &&+ !record.zipcode &&+ !record.state_abbr+ ) {return null;}@@ -137,7 +142,7 @@ const AddressInfo = ({ record }: { record: Company }) => {<TextField source="address" /><TextField source="city" /><TextField source="zipcode" />- <TextField source="stateAbbr" />+ <TextField source="state_abbr" /><TextField source="country" /></AsideSection>);diff --git a/src/components/atomic-crm/companies/CompanyInputs.tsx b/src/components/atomic-crm/companies/CompanyInputs.tsxindex a478af9b..4867b1cb 100644--- a/src/components/atomic-crm/companies/CompanyInputs.tsx+++ b/src/components/atomic-crm/companies/CompanyInputs.tsx@@ -110,7 +110,7 @@ const CompanyAddressInputs = () => {<TextInput source="address" helperText={false} /><TextInput source="city" helperText={false} /><TextInput source="zipcode" helperText={false} />- <TextInput source="stateAbbr" helperText={false} />+ <TextInput source="state_abbr" helperText={false} /><TextInput source="country" helperText={false} /></div>);diff --git a/src/components/atomic-crm/contacts/ContactMergeButton.tsx b/src/components/atomic-crm/contacts/ContactMergeButton.tsxindex 4110c431..0c908d63 100644--- a/src/components/atomic-crm/contacts/ContactMergeButton.tsx+++ b/src/components/atomic-crm/contacts/ContactMergeButton.tsx@@ -97,7 +97,7 @@ const ContactMergeDialog = ({ open, onClose }: ContactMergeDialogProps) => {);const { total: notesCount } = useGetManyReference(- "contactNotes",+ "contact_notes",{target: "contact_id",id: loserContact?.id,diff --git a/src/components/atomic-crm/contacts/ContactShow.tsx b/src/components/atomic-crm/contacts/ContactShow.tsxindex 67b3ec1a..d895991a 100644--- a/src/components/atomic-crm/contacts/ContactShow.tsx+++ b/src/components/atomic-crm/contacts/ContactShow.tsx@@ -59,7 +59,7 @@ const ContactShowContent = () => {</div><ReferenceManyFieldtarget="contact_id"- reference="contactNotes"+ reference="contact_notes"sort={{ field: "date", order: "DESC" }}empty={<NoteCreate reference="contacts" showStatus className="mt-4" />diff --git a/src/components/atomic-crm/dashboard/Dashboard.tsx b/src/components/atomic-crm/dashboard/Dashboard.tsxindex a529b7f5..a944c5fa 100644--- a/src/components/atomic-crm/dashboard/Dashboard.tsx+++ b/src/components/atomic-crm/dashboard/Dashboard.tsx@@ -18,7 +18,7 @@ export const Dashboard = () => {});const { total: totalContactNotes, isPending: isPendingContactNotes } =- useGetList<ContactNote>("contactNotes", {+ useGetList<ContactNote>("contact_notes", {pagination: { page: 1, perPage: 1 },});diff --git a/src/components/atomic-crm/dashboard/LatestNotes.tsx b/src/components/atomic-crm/dashboard/LatestNotes.tsxindex 76bca61e..7a273f3b 100644--- a/src/components/atomic-crm/dashboard/LatestNotes.tsx+++ b/src/components/atomic-crm/dashboard/LatestNotes.tsx@@ -10,7 +10,7 @@ import type { Contact, ContactNote } from "../types";export const LatestNotes = () => {const { identity } = useGetIdentity();const { data: contactNotesData, isPending: contactNotesLoading } = useGetList(- "contactNotes",+ "contact_notes",{pagination: { page: 1, perPage: 5 },sort: { field: "date", order: "DESC" },@@ -19,7 +19,7 @@ export const LatestNotes = () => {{ enabled: Number.isInteger(identity?.id) },);const { data: dealNotesData, isPending: dealNotesLoading } = useGetList(- "dealNotes",+ "deal_notes",{pagination: { page: 1, perPage: 5 },sort: { field: "date", order: "DESC" },diff --git a/src/components/atomic-crm/deals/DealShow.tsx b/src/components/atomic-crm/deals/DealShow.tsxindex 7c0f02fc..a1fb504c 100644--- a/src/components/atomic-crm/deals/DealShow.tsx+++ b/src/components/atomic-crm/deals/DealShow.tsx@@ -163,7 +163,7 @@ const DealShowContent = () => {<Separator className="mb-4" /><ReferenceManyFieldtarget="deal_id"- reference="dealNotes"+ reference="deal_notes"sort={{ field: "date", order: "DESC" }}empty={<NoteCreate reference={"deals"} />}>diff --git a/src/components/atomic-crm/notes/NoteCreate.tsx b/src/components/atomic-crm/notes/NoteCreate.tsxindex b73fde30..c844b5ca 100644--- a/src/components/atomic-crm/notes/NoteCreate.tsx+++ b/src/components/atomic-crm/notes/NoteCreate.tsx@@ -84,7 +84,11 @@ const NoteCreateButton = ({refetch();update(reference, {id: (record && record.id) as unknown as Identifier,- data: { last_seen: new Date().toISOString(), status: data.status },+ data: {+ last_seen:+ reference === "contacts" ? new Date().toISOString() : undefined,+ status: data.status,+ },previousData: record,});notify("Note added");diff --git a/src/components/atomic-crm/providers/commons/activity.ts b/src/components/atomic-crm/providers/commons/activity.tsindex 0fd59eca..734bb5d8 100644--- a/src/components/atomic-crm/providers/commons/activity.ts+++ b/src/components/atomic-crm/providers/commons/activity.ts@@ -95,7 +95,7 @@ async function getNewContactsAndNotes(}const { data: contactNotes } = await dataProvider.getList<ContactNote>(- "contactNotes",+ "contact_notes",{filter: recentContactNotesFilter,pagination: { page: 1, perPage: 250 },@@ -145,7 +145,7 @@ async function getNewDealsAndNotes(}const { data: dealNotes } = await dataProvider.getList<DealNote>(- "dealNotes",+ "deal_notes",{filter: recentDealNotesFilter,pagination: { page: 1, perPage: 250 },diff --git a/src/components/atomic-crm/providers/commons/mergeContacts.ts b/src/components/atomic-crm/providers/commons/mergeContacts.tsindex 727494a0..5de5b535 100644--- a/src/components/atomic-crm/providers/commons/mergeContacts.ts+++ b/src/components/atomic-crm/providers/commons/mergeContacts.ts@@ -51,7 +51,7 @@ export const mergeContacts = async (// 2. Reassign all notes from loser to winnerconst { data: loserNotes } = await dataProvider.getManyReference<ContactNote>(- "contactNotes",+ "contact_notes",{target: "contact_id",id: loserId,@@ -63,7 +63,7 @@ export const mergeContacts = async (const noteUpdates =loserNotes?.map((note) =>- dataProvider.update<ContactNote>("contactNotes", {+ dataProvider.update<ContactNote>("contact_notes", {id: note.id,data: { contact_id: winnerId },previousData: note,diff --git a/src/components/atomic-crm/providers/fakerest/dataGenerator/companies.ts b/src/components/atomic-crm/providers/fakerest/dataGenerator/companies.tsindex c73524e2..3f2bcfcc 100644--- a/src/components/atomic-crm/providers/fakerest/dataGenerator/companies.ts+++ b/src/components/atomic-crm/providers/fakerest/dataGenerator/companies.ts@@ -37,7 +37,7 @@ export const generateCompanies = (db: Db, size = 55): Required<Company>[] => {address: address.streetAddress(),zipcode: address.zipCode(),city: address.city(),- stateAbbr: address.stateAbbr(),+ state_abbr: address.state_abbr(),nb_contacts: 0,nb_deals: 0,// at least 1/3rd of companies for Jane Doediff --git a/src/components/atomic-crm/providers/fakerest/dataProvider.ts b/src/components/atomic-crm/providers/fakerest/dataProvider.tsindex e60a74a3..6f5930ee 100644--- a/src/components/atomic-crm/providers/fakerest/dataProvider.ts+++ b/src/components/atomic-crm/providers/fakerest/dataProvider.ts@@ -291,7 +291,7 @@ export const dataProvider = withLifecycleCallbacks(},sort: { field: "id", order: "ASC" },}),- dataProvider.getList("contactNotes", {+ dataProvider.getList("contact_notes", {filter: { sales_id: params.id },pagination: {page: 1,@@ -322,7 +322,7 @@ export const dataProvider = withLifecycleCallbacks(sales_id: newSaleId,},}),- dataProvider.updateMany("contactNotes", {+ dataProvider.updateMany("contact_notes", {ids: contactNotes.data.map((company) => company.id),data: {sales_id: newSaleId,diff --git a/src/components/atomic-crm/providers/supabase/dataProvider.ts b/src/components/atomic-crm/providers/supabase/dataProvider.tsindex 6e4d7fd8..45943807 100644--- a/src/components/atomic-crm/providers/supabase/dataProvider.ts+++ b/src/components/atomic-crm/providers/supabase/dataProvider.ts@@ -239,7 +239,7 @@ export const dataProvider = withLifecycleCallbacks(dataProviderWithCustomMethods,[{- resource: "contactNotes",+ resource: "contact_notes",beforeSave: async (data: ContactNote, _, __) => {if (data.attachments) {for (const fi of data.attachments) {@@ -250,7 +250,7 @@ export const dataProvider = withLifecycleCallbacks(},},{- resource: "dealNotes",+ resource: "deal_notes",beforeSave: async (data: DealNote, _, __) => {if (data.attachments) {for (const fi of data.attachments) {@@ -298,7 +298,7 @@ export const dataProvider = withLifecycleCallbacks("website","zipcode","city",- "stateAbbr",+ "state_abbr",])(params);},beforeCreate: async (params) => {diff --git a/src/components/atomic-crm/root/CRM.tsx b/src/components/atomic-crm/root/CRM.tsxindex ed6076a2..fe3a6687 100644--- a/src/components/atomic-crm/root/CRM.tsx+++ b/src/components/atomic-crm/root/CRM.tsx@@ -158,8 +158,8 @@ export const CRM = ({<Resource name="deals" {...deals} /><Resource name="contacts" {...contacts} /><Resource name="companies" {...companies} />- <Resource name="contactNotes" />- <Resource name="dealNotes" />+ <Resource name="contact_notes" />+ <Resource name="deal_notes" /><Resource name="tasks" /><Resource name="sales" {...sales} /><Resource name="tags" />diff --git a/src/components/atomic-crm/types.ts b/src/components/atomic-crm/types.tsindex 0055e127..831c0b25 100644--- a/src/components/atomic-crm/types.ts+++ b/src/components/atomic-crm/types.ts@@ -59,7 +59,7 @@ export type Company = {address: string;zipcode: string;city: string;- stateAbbr: string;+ state_abbr: string;sales_id: Identifier;created_at: string;description: string;diff --git a/supabase/functions/mergeContacts/index.ts b/supabase/functions/mergeContacts/index.tsindex 7b1bad03..bace4688 100644--- a/supabase/functions/mergeContacts/index.ts+++ b/supabase/functions/mergeContacts/index.ts@@ -113,7 +113,7 @@ async function mergeContacts(// 3. Reassign notes from loser to winnerawait trx- .updateTable("contactNotes")+ .updateTable("contact_notes").set({ contact_id: winnerId }).where("contact_id", "=", loserId).execute();diff --git a/supabase/functions/postmark/addNoteToContact.ts b/supabase/functions/postmark/addNoteToContact.tsindex f82a7dd1..b9cf77c1 100644--- a/supabase/functions/postmark/addNoteToContact.ts+++ b/supabase/functions/postmark/addNoteToContact.ts@@ -110,7 +110,7 @@ export const addNoteToContact = async ({// Add note to contactconst { error: createNoteError } = await supabaseAdmin- .from("contactNotes")+ .from("contact_notes").insert({contact_id: contact.id,text: noteContent,diff --git a/supabase/migrations/20260115150819_snake_case_renaming.sql b/supabase/migrations/20260115150819_snake_case_renaming.sqlnew file mode 100644index 00000000..91503281--- /dev/null+++ b/supabase/migrations/20260115150819_snake_case_renaming.sql@@ -0,0 +1,4 @@+alter table "public"."companies" rename column "stateAbbr" TO "state_abbr";+alter view "public"."companies_summary" rename column "stateAbbr" TO "state_abbr";+alter table "public"."contactNotes" rename to "contact_notes";+alter table "public"."dealNotes" rename to "deal_notes";