Skip to content

Commit

Permalink
Feat(crm): Add a type for contact phone numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
arimet committed Jul 25, 2024
1 parent 717a638 commit ed38e78
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 23 deletions.
34 changes: 16 additions & 18 deletions examples/crm/src/contacts/ContactAside.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,33 +66,31 @@ export const ContactAside = ({ link = 'edit' }: { link?: 'edit' | 'show' }) => {
/>
</Stack>
)}
{record.phone_number1 && (
{record.phone_number1.number && (
<Stack direction="row" alignItems="center" gap={1}>
<PhoneIcon color="disabled" fontSize="small" />
<Box>
<TextField source="phone_number1" />{' '}
<Typography
variant="body2"
color="textSecondary"
component="span"
>
Work
</Typography>
<TextField source="phone_number1.number" />{' '}
{record.phone_number1.type !== 'Other' && (
<TextField
source="phone_number1.type"
color="textSecondary"
/>
)}
</Box>
</Stack>
)}
{record.phone_number2 && (
{record.phone_number2.number && (
<Stack direction="row" alignItems="center" gap={1}>
<PhoneIcon color="disabled" fontSize="small" />
<Box>
<TextField source="phone_number2" />{' '}
<Typography
variant="body2"
color="textSecondary"
component="span"
>
Home
</Typography>
<TextField source="phone_number2.number" />{' '}
{record.phone_number2.type !== 'Other' && (
<TextField
source="phone_number2.type"
color="textSecondary"
/>
)}
</Box>
</Stack>
)}
Expand Down
32 changes: 29 additions & 3 deletions examples/crm/src/contacts/ContactInputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const ContactInputs = () => {
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));

return (
<Stack gap={8} p={1}>
<Stack gap={4} p={1}>
<Stack gap={2}>
<Avatar />
<Stack gap={4} flexDirection={isMobile ? 'column' : 'row'}>
Expand Down Expand Up @@ -141,8 +141,34 @@ const ContactPersonalInformationInputs = () => {
<Stack gap={1} flex={1}>
<Typography variant="h6">Personal info</Typography>
<TextInput source="email" helperText={false} validate={email()} />
<TextInput source="phone_number1" helperText={false} />
<TextInput source="phone_number2" helperText={false} />
<Stack gap={1} flexDirection="row">
<TextInput
source="phone_number1.number"
label="Phone number 1"
helperText={false}
/>
<SelectInput
source="phone_number1.type"
label="Type"
helperText={false}
optionText={choice => choice.id}
choices={[{ id: 'Work' }, { id: 'Home' }, { id: 'Other' }]}
/>
</Stack>
<Stack gap={1} flexDirection="row">
<TextInput
source="phone_number2.number"
label="Phone number 2"
helperText={false}
/>
<SelectInput
source="phone_number2.type"
label="Type"
helperText={false}
optionText={choice => choice.id}
choices={[{ id: 'Work' }, { id: 'Home' }, { id: 'Other' }]}
/>
</Stack>
<TextInput
source="linkedin_url"
label="Linkedin URL"
Expand Down
10 changes: 8 additions & 2 deletions examples/crm/src/dataGenerator/contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,14 @@ export const generateContacts = (db: Db): Contact[] => {
company_id: company.id,
company_name: company.name,
email,
phone_number1: phone.phoneNumber(),
phone_number2: phone.phoneNumber(),
phone_number1: {
number: phone.phoneNumber(),
type: random.arrayElement(['Work', 'Home', 'Other']),
},
phone_number2: {
number: phone.phoneNumber(),
type: random.arrayElement(['Work', 'Home', 'Other']),
},
background: lorem.sentence(),
acquisition: random.arrayElement(['inbound', 'outbound']),
avatar,
Expand Down
2 changes: 2 additions & 0 deletions examples/crm/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export interface Contact extends RaRecord {
nb_notes: number;
status: string;
background: string;
phone_number1: { number: string; type: 'Work' | 'Home' | 'Other' };
phone_number2: { number: string; type: 'Work' | 'Home' | 'Other' };
}

export interface ContactNote extends RaRecord {
Expand Down

0 comments on commit ed38e78

Please sign in to comment.