Skip to content

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

Fix(crm): Set phone number into split fields

Anthony Rimet7009b601861d
diff --git a/src/contacts/ContactAside.tsx b/src/contacts/ContactAside.tsx
index 88260b26..2b350292 100644
--- a/src/contacts/ContactAside.tsx
+++ b/src/contacts/ContactAside.tsx
@@ -73,21 +73,21 @@ export const ContactAside = ({ link = 'edit' }: { link?: 'edit' | 'show' }) => {
/>
</Stack>
)}
- {record.phone_number1?.number && (
+ {record.phone_1_number && (
<Stack direction="row" alignItems="center" gap={1}>
<PhoneIcon color="disabled" fontSize="small" />
<Box>
- <TextField source="phone_number1.number" />{' '}
- {record.phone_number1.type !== 'Other' && (
+ <TextField source="phone_1_number" />{' '}
+ {record.phone_1_type !== 'Other' && (
<TextField
- source="phone_number1.type"
+ source="phone_1_type"
color="textSecondary"
/>
)}
</Box>
</Stack>
)}
- {record.phone_number2?.number && (
+ {record.phone_2_number && (
<Stack
direction="row"
alignItems="center"
@@ -96,10 +96,10 @@ export const ContactAside = ({ link = 'edit' }: { link?: 'edit' | 'show' }) => {
>
<PhoneIcon color="disabled" fontSize="small" />
<Box>
- <TextField source="phone_number2.number" />{' '}
- {record.phone_number2.type !== 'Other' && (
+ <TextField source="phone_2_number" />{' '}
+ {record.phone_2_type !== 'Other' && (
<TextField
- source="phone_number2.type"
+ source="phone_2_type"
color="textSecondary"
/>
)}
diff --git a/src/contacts/ContactInputs.tsx b/src/contacts/ContactInputs.tsx
index 4ca40b9b..ab86635d 100644
--- a/src/contacts/ContactInputs.tsx
+++ b/src/contacts/ContactInputs.tsx
@@ -125,12 +125,12 @@ const ContactPersonalInformationInputs = () => {
<TextInput source="email" helperText={false} validate={email()} />
<Stack gap={1} flexDirection="row">
<TextInput
- source="phone_number1.number"
+ source="phone_1_number"
label="Phone number 1"
helperText={false}
/>
<SelectInput
- source="phone_number1.type"
+ source="phone_1_type"
label="Type"
helperText={false}
optionText={choice => choice.id}
@@ -140,12 +140,12 @@ const ContactPersonalInformationInputs = () => {
</Stack>
<Stack gap={1} flexDirection="row">
<TextInput
- source="phone_number2.number"
+ source="phone_2_number"
label="Phone number 2"
helperText={false}
/>
<SelectInput
- source="phone_number2.type"
+ source="phone_2_type"
label="Type"
helperText={false}
optionText={choice => choice.id}
diff --git a/src/contacts/ContactListFilter.tsx b/src/contacts/ContactListFilter.tsx
index b40ebdcf..33e622bd 100644
--- a/src/contacts/ContactListFilter.tsx
+++ b/src/contacts/ContactListFilter.tsx
@@ -103,7 +103,7 @@ export const ContactListFilter = () => {
}}
/>
}
- value={{ tags: [record.id] }}
+ value={{ 'tags@cs': `{${record.id}}` }}
/>
))}
</FilterList>
diff --git a/src/contacts/contacts_export.csv b/src/contacts/contacts_export.csv
index 8000d62d..5060f291 100644
--- a/src/contacts/contacts_export.csv
+++ b/src/contacts/contacts_export.csv
@@ -1,2 +1,2 @@
-first_name,last_name,gender,title,company,email,phone_number1.number,phone_number1.type,phone_number2.number,phone_number2.type,background,acquisition,first_seen,last_seen,has_newsletter,status,tags
+first_name,last_name,gender,title,company,email,phone_1_number,phone_1_type,phone_2_number,phone_2_type,background,acquisition,first_seen,last_seen,has_newsletter,status,tags
John,DOE,male,Developer,Marmelab,[email protected],659-980-2015,work,740.645.3807,home,,outbound,2024-07-01,2024-07-01T11:54:49.950Z,FALSE,in-contract,"influencer, developer"
\ No newline at end of file
diff --git a/src/contacts/useContactImport.tsx b/src/contacts/useContactImport.tsx
index 4d6d6c49..108dd26f 100644
--- a/src/contacts/useContactImport.tsx
+++ b/src/contacts/useContactImport.tsx
@@ -9,10 +9,10 @@ export type ContactImportSchema = {
title: string;
company: string;
email: string;
- 'phone_number1.number': string;
- 'phone_number1.type': string;
- 'phone_number2.number': string;
- 'phone_number2.type': string;
+ phone_1_number: string;
+ phone_1_type: string;
+ phone_2_number: string;
+ phone_2_type: string;
background: string;
acquisition: string;
avatar: string;
@@ -137,10 +137,10 @@ export function useContactImport() {
gender,
title,
email,
- 'phone_number1.type': phoneNumber1Type,
- 'phone_number1.number': phoneNumber1Number,
- 'phone_number2.type': phoneNumber2Type,
- 'phone_number2.number': phoneNumber2Number,
+ phone_1_number: phoneNumber1Type,
+ phone_1_type: phoneNumber1Number,
+ phone_2_number: phoneNumber2Type,
+ phone_2_type: phoneNumber2Number,
background,
acquisition,
first_seen,
@@ -168,14 +168,10 @@ export function useContactImport() {
gender,
title,
email,
- phone_number1: {
- number: phoneNumber1Number,
- type: phoneNumber1Type,
- },
- phone_number2: {
- number: phoneNumber2Number,
- type: phoneNumber2Type,
- },
+ phone_1_number: phoneNumber1Number,
+ phone_1_type: phoneNumber1Type,
+ phone_2_number: phoneNumber2Number,
+ phone_2_type: phoneNumber2Type,
background,
acquisition,
first_seen: new Date(first_seen),
diff --git a/src/dataProvider.ts b/src/dataProvider.ts
index 45443449..97946378 100644
--- a/src/dataProvider.ts
+++ b/src/dataProvider.ts
@@ -242,8 +242,8 @@ export const dataProvider = withLifecycleCallbacks(
'company_name',
'title',
'email',
- 'phone_number1',
- 'phone_number2',
+ 'phone_2_number',
+ 'phone_2_number',
'background',
])(params);
},
diff --git a/src/types.ts b/src/types.ts
index 6dd68a43..c628229c 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -76,8 +76,10 @@ export interface Contact extends RaRecord {
sales_id: Identifier;
status: string;
background: string;
- phone_number1: { number: string; type: 'Work' | 'Home' | 'Other' };
- phone_number2: { number: string; type: 'Work' | 'Home' | 'Other' };
+ phone_1_type: 'Work' | 'Home' | 'Other';
+ phone_1_number: string;
+ phone_2_type: 'Work' | 'Home' | 'Other';
+ phone_2_number: string;
}
export interface ContactNote extends RaRecord {
diff --git a/supabase/migrations/20240730075029_init_db.sql b/supabase/migrations/20240730075029_init_db.sql
index 4f42ebc6..bd243439 100644
--- a/supabase/migrations/20240730075029_init_db.sql
+++ b/supabase/migrations/20240730075029_init_db.sql
@@ -43,8 +43,10 @@ create table "public"."contacts" (
"gender" text,
"title" text,
"email" text,
- "phone_number1" text,
- "phone_number2" text,
+ "phone_1_number" text,
+ "phone_1_type" text,
+ "phone_2_number" text,
+ "phone_2_type" text,
"background" text,
"acquisition" text,
"avatar" jsonb,