A full-featured CRM built with React, shadcn/ui, and Supabase.
use phone_jsonb in CRM
Jean-Baptiste Kaisere3ded1c91ca5
diff --git a/src/contacts/ContactAside.tsx b/src/contacts/ContactAside.tsxindex 403f6cbb..4f99dc80 100644--- a/src/contacts/ContactAside.tsx+++ b/src/contacts/ContactAside.tsx@@ -90,39 +90,26 @@ export const ContactAside = ({ link = 'edit' }: { link?: 'edit' | 'show' }) => {/></Stack>)}- {record.phone_1_number && (- <Stack direction="row" alignItems="center" gap={1}>- <PhoneIcon color="disabled" fontSize="small" />- <Box>- <TextField source="phone_1_number" />{' '}- {record.phone_1_type !== 'Other' && (- <TextField- source="phone_1_type"- color="textSecondary"- />- )}- </Box>- </Stack>- )}- {record.phone_2_number && (- <Stack- direction="row"- alignItems="center"- gap={1}- minHeight={24}- >- <PhoneIcon color="disabled" fontSize="small" />- <Box>- <TextField source="phone_2_number" />{' '}- {record.phone_2_type !== 'Other' && (- <TextField- source="phone_2_type"- color="textSecondary"+ <ArrayField source="phone_jsonb">+ <SingleFieldList linkType={false} gap={0}>+ <Stack direction="row" alignItems="center" gap={1}>+ <PhoneIcon color="disabled" fontSize="small" />+ <Box>+ <TextField source="number" />{' '}+ <WithRecord+ render={row =>+ row.type !== 'Other' && (+ <TextField+ source="type"+ color="textSecondary"+ />+ )+ }/>- )}- </Box>- </Stack>- )}+ </Box>+ </Stack>+ </SingleFieldList>+ </ArrayField><SelectFieldsource="gender"choices={contactGender}diff --git a/src/contacts/ContactInputs.tsx b/src/contacts/ContactInputs.tsxindex c3d29d4a..6bb828ea 100644--- a/src/contacts/ContactInputs.tsx+++ b/src/contacts/ContactInputs.tsx@@ -178,40 +178,28 @@ const ContactPersonalInformationInputs = () => {/></SimpleFormIterator></ArrayInput>- <Stack gap={1} flexDirection="row">- <TextInput- source="phone_1_number"- label="Phone number 1"- helperText={false}- />- <SelectInput- source="phone_1_type"- label="Type"- helperText={false}- optionText="id"- choices={[{ id: 'Work' }, { id: 'Home' }, { id: 'Other' }]}- defaultValue="Work"- fullWidth={false}- sx={{ width: 130, minWidth: 130 }}- />- </Stack>- <Stack gap={1} flexDirection="row">- <TextInput- source="phone_2_number"- label="Phone number 2"- helperText={false}- />- <SelectInput- source="phone_2_type"- label="Type"- helperText={false}- optionText="id"- choices={[{ id: 'Work' }, { id: 'Home' }, { id: 'Other' }]}- defaultValue="Work"- fullWidth={false}- sx={{ width: 130, minWidth: 130 }}- />- </Stack>+ <ArrayInput+ source="phone_jsonb"+ label="Phone numbers"+ helperText={false}+ >+ <SimpleFormIterator inline disableReordering>+ <TextInput source="number" helperText={false} />+ <SelectInput+ source="type"+ helperText={false}+ optionText="id"+ choices={[+ { id: 'Work' },+ { id: 'Home' },+ { id: 'Other' },+ ]}+ defaultValue="Work"+ fullWidth={false}+ sx={{ width: 100, minWidth: 100 }}+ />+ </SimpleFormIterator>+ </ArrayInput><TextInputsource="linkedin_url"label="Linkedin URL"diff --git a/src/providers/fakerest/dataGenerator/contacts.ts b/src/providers/fakerest/dataGenerator/contacts.tsindex dbd51af2..11ec24da 100644--- a/src/providers/fakerest/dataGenerator/contacts.ts+++ b/src/providers/fakerest/dataGenerator/contacts.ts@@ -23,6 +23,9 @@ const maxContacts = {500: 50,};+const getRandomContactDetailsType = () =>+ random.arrayElement(['Work', 'Home', 'Other']) as 'Work' | 'Home' | 'Other';+export const generateContacts = (db: Db, size = 500): Required<Contact>[] => {const nbAvailblePictures = 223;let numberOfContacts = 0;@@ -33,10 +36,20 @@ export const generateContacts = (db: Db, size = 500): Required<Contact>[] => {const gender = random.arrayElement(defaultContactGender).value;const first_name = name.firstName(gender as any);const last_name = name.lastName();- const email = [+ const email_jsonb = [{email: internet.email(first_name, last_name),- type: 'Work' as const,+ type: getRandomContactDetailsType(),+ },+ ];+ const phone_jsonb = [+ {+ number: phone.phoneNumber(),+ type: getRandomContactDetailsType(),+ },+ {+ number: phone.phoneNumber(),+ type: getRandomContactDetailsType(),},];const avatar = {@@ -72,11 +85,8 @@ export const generateContacts = (db: Db, size = 500): Required<Contact>[] => {title: title.charAt(0).toUpperCase() + title.substr(1),company_id: company.id,company_name: company.name,- email_jsonb: email,- phone_1_number: phone.phoneNumber(),- phone_1_type: random.arrayElement(['Work', 'Home', 'Other']),- phone_2_number: phone.phoneNumber(),- phone_2_type: random.arrayElement(['Work', 'Home', 'Other']),+ email_jsonb,+ phone_jsonb,background: lorem.sentence(),acquisition: random.arrayElement(['inbound', 'outbound']),avatar,diff --git a/src/providers/supabase/dataProvider.ts b/src/providers/supabase/dataProvider.tsindex 57af8d61..6e77fa8d 100644--- a/src/providers/supabase/dataProvider.ts+++ b/src/providers/supabase/dataProvider.ts@@ -279,8 +279,7 @@ export const dataProvider = withLifecycleCallbacks('company_name','title','email',- 'phone_1_number',- 'phone_2_number',+ 'phone','background',])(params);},@@ -338,19 +337,23 @@ const applyFullTextSearch = (columns: string[]) => (params: GetListParams) => {...params,filter: {...filter,- '@or': columns.reduce(- (acc, column) =>- column === 'email'- ? {- ...acc,- [`email_fts@ilike`]: q,- }- : {- ...acc,- [`${column}@ilike`]: q,- },- {}- ),+ '@or': columns.reduce((acc, column) => {+ if (column === 'email')+ return {+ ...acc,+ [`email_fts@ilike`]: q,+ };+ if (column === 'phone')+ return {+ ...acc,+ [`phone_fts@ilike`]: q,+ };+ else+ return {+ ...acc,+ [`${column}@ilike`]: q,+ };+ }, {}),},};};diff --git a/src/types.ts b/src/types.tsindex bcd14dc7..3d80739d 100644--- a/src/types.ts+++ b/src/types.ts@@ -75,6 +75,11 @@ export type EmailAndType = {type: 'Work' | 'Home' | 'Other';};+export type PhoneNumberAndType = {+ number: string;+ type: 'Work' | 'Home' | 'Other';+};+export type Contact = {first_name: string;last_name: string;@@ -91,10 +96,7 @@ export type Contact = {sales_id: Identifier;status: string;background: string;- phone_1_type: 'Work' | 'Home' | 'Other';- phone_1_number: string;- phone_2_type: 'Work' | 'Home' | 'Other';- phone_2_number: string;+ phone_jsonb: PhoneNumberAndType[];nb_tasks?: number;company_name?: string;