From 9b132f4929c139a10922a78b92fea031eda8bde8 Mon Sep 17 00:00:00 2001 From: Jonathan ARNAULT Date: Fri, 26 Jul 2024 09:13:53 +0200 Subject: [PATCH 1/3] Fix(crm): Rename company.taxe_identifier to company.tax_identifier --- examples/crm/src/companies/CompanyAside.tsx | 19 +++++++++---------- examples/crm/src/companies/CompanyForm.tsx | 18 ++++++++---------- examples/crm/src/dataGenerator/companies.ts | 10 +++++----- examples/crm/src/types.ts | 2 +- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/examples/crm/src/companies/CompanyAside.tsx b/examples/crm/src/companies/CompanyAside.tsx index 6eaf3ee8c5..dba43d8479 100644 --- a/examples/crm/src/companies/CompanyAside.tsx +++ b/examples/crm/src/companies/CompanyAside.tsx @@ -1,18 +1,17 @@ -import * as React from 'react'; +import LinkedInIcon from '@mui/icons-material/LinkedIn'; +import PhoneIcon from '@mui/icons-material/Phone'; +import PublicIcon from '@mui/icons-material/Public'; +import { Divider, Link, Stack, Typography } from '@mui/material'; import { - TextField, DateField, + EditButton, FunctionField, ReferenceField, - UrlField, - EditButton, ShowButton, + TextField, + UrlField, useRecordContext, } from 'react-admin'; -import { Typography, Divider, Link, Stack } from '@mui/material'; -import PublicIcon from '@mui/icons-material/Public'; -import LinkedInIcon from '@mui/icons-material/LinkedIn'; -import PhoneIcon from '@mui/icons-material/Phone'; import { Company } from '../types'; @@ -116,14 +115,14 @@ const FinancialInfo = ({ record }: { record: Company }) => { Revenue: )} - {record.taxe_identifier && ( + {record.tax_identifier && ( Tax Identifier:{' '} - + )} diff --git a/examples/crm/src/companies/CompanyForm.tsx b/examples/crm/src/companies/CompanyForm.tsx index 56bf44b1f7..5681a78d9d 100644 --- a/examples/crm/src/companies/CompanyForm.tsx +++ b/examples/crm/src/companies/CompanyForm.tsx @@ -1,19 +1,17 @@ -import * as React from 'react'; - +import { Divider, Grid, Stack } from '@mui/material'; import { + ArrayInput, + ImageField, + ImageInput, ReferenceInput, - TextInput, SelectInput, - required, - ArrayInput, SimpleFormIterator, - ImageInput, - ImageField, + TextInput, + required, } from 'react-admin'; -import { Divider, Stack, Grid } from '@mui/material'; -import { sizes } from './sizes'; import { useConfigurationContext } from '../root/ConfigurationContext'; +import { sizes } from './sizes'; export const CompanyForm = () => { const { companySectors } = useConfigurationContext(); @@ -79,7 +77,7 @@ export const CompanyForm = () => { - + diff --git a/examples/crm/src/dataGenerator/companies.ts b/examples/crm/src/dataGenerator/companies.ts index d06960dd7c..f235462811 100644 --- a/examples/crm/src/dataGenerator/companies.ts +++ b/examples/crm/src/dataGenerator/companies.ts @@ -1,16 +1,16 @@ import { + address, company, internet, - address, + lorem, phone, random, - lorem, } from 'faker/locale/en_US'; import { randomDate } from './utils'; -import { Db } from './types'; -import { Company } from '../types'; import { defaultCompanySectors } from '../root/defaultConfiguration'; +import { Company } from '../types'; +import { Db } from './types'; const sizes = [1, 10, 50, 250, 500]; @@ -45,7 +45,7 @@ export const generateCompanies = (db: Db): Company[] => { created_at: randomDate().toISOString(), description: lorem.paragraph(), revenue: random.arrayElement(['$1M', '$10M', '$100M', '$1B']), - taxe_identifier: random.alphaNumeric(10), + tax_identifier: random.alphaNumeric(10), country: random.arrayElement(['USA', 'France', 'UK']), context_links: [], }; diff --git a/examples/crm/src/types.ts b/examples/crm/src/types.ts index 0fc65b9f81..e8bbf53aa6 100644 --- a/examples/crm/src/types.ts +++ b/examples/crm/src/types.ts @@ -33,7 +33,7 @@ export interface Company extends RaRecord { created_at: string; description: string; revenue: string; - taxe_identifier: string; + tax_identifier: string; country: string; context_links?: string[]; } From 71def36beaacaebf51ff571f422e08319ba2ef86 Mon Sep 17 00:00:00 2001 From: Jonathan ARNAULT Date: Fri, 26 Jul 2024 10:07:19 +0200 Subject: [PATCH 2/3] Fix(crm): It was not possible ta save a company or a contact due to linkedin URL --- examples/crm/src/commons/isLinkedInUrl.ts | 15 ++++++++ examples/crm/src/companies/CompanyAside.tsx | 1 + examples/crm/src/companies/CompanyInputs.tsx | 15 +------- examples/crm/src/contacts/ContactInputs.tsx | 40 +++++++------------- 4 files changed, 30 insertions(+), 41 deletions(-) create mode 100644 examples/crm/src/commons/isLinkedInUrl.ts diff --git a/examples/crm/src/commons/isLinkedInUrl.ts b/examples/crm/src/commons/isLinkedInUrl.ts new file mode 100644 index 0000000000..517b0734c8 --- /dev/null +++ b/examples/crm/src/commons/isLinkedInUrl.ts @@ -0,0 +1,15 @@ +const LINKEDIN_URL_REGEX = /^http(?:s)?:\/\/(?:www\.)?linkedin.com\//; + +export const isLinkedinUrl = (url: string) => { + if (!url) return; + try { + // Parse the URL to ensure it is valid + const parsedUrl = new URL(url); + if (!parsedUrl.href.match(LINKEDIN_URL_REGEX)) { + return 'URL must be from linkedin.com'; + } + } catch (e) { + // If URL parsing fails, return false + return 'Must be a valid URL'; + } +}; diff --git a/examples/crm/src/companies/CompanyAside.tsx b/examples/crm/src/companies/CompanyAside.tsx index dba43d8479..3eec5eb06f 100644 --- a/examples/crm/src/companies/CompanyAside.tsx +++ b/examples/crm/src/companies/CompanyAside.tsx @@ -79,6 +79,7 @@ const CompanyInfo = ({ record }: { record: Company }) => { content="LinkedIn" target="_blank" rel="noopener" + label="LinkedIn" /> )} diff --git a/examples/crm/src/companies/CompanyInputs.tsx b/examples/crm/src/companies/CompanyInputs.tsx index 19d4c4a14f..a0d674b296 100644 --- a/examples/crm/src/companies/CompanyInputs.tsx +++ b/examples/crm/src/companies/CompanyInputs.tsx @@ -13,25 +13,12 @@ import { TextInput, required, } from 'react-admin'; +import { isLinkedinUrl } from '../commons/isLinkedInUrl'; import { useConfigurationContext } from '../root/ConfigurationContext'; import { Sale } from '../types'; import { CompanyAvatar } from './CompanyAvatar'; import { sizes } from './sizes'; -const isLinkedinUrl = (url: string) => { - if (!url) return; - try { - // Parse the URL to ensure it is valid - const parsedUrl = new URL(url); - if (!parsedUrl.hostname.startsWith('https://linkedin.com/')) { - return 'URL must be from linkedin.com'; - } - } catch (e) { - // If URL parsing fails, return false - return 'Must be a valid URL'; - } -}; - export const CompanyInputs = () => { const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down('md')); diff --git a/examples/crm/src/contacts/ContactInputs.tsx b/examples/crm/src/contacts/ContactInputs.tsx index ccd0d9d7e7..544b77e681 100644 --- a/examples/crm/src/contacts/ContactInputs.tsx +++ b/examples/crm/src/contacts/ContactInputs.tsx @@ -1,41 +1,27 @@ -import * as React from 'react'; import { - TextInput, - ReferenceInput, + Divider, + Stack, + Typography, + useMediaQuery, + useTheme, +} from '@mui/material'; +import { AutocompleteInput, BooleanInput, + RadioButtonGroupInput, + ReferenceInput, SelectInput, - required, + TextInput, email, + required, useCreate, useGetIdentity, useNotify, - RadioButtonGroupInput, } from 'react-admin'; -import { - Divider, - Stack, - Typography, - useMediaQuery, - useTheme, -} from '@mui/material'; +import { isLinkedinUrl } from '../commons/isLinkedInUrl'; import { useConfigurationContext } from '../root/ConfigurationContext'; -import { Avatar } from './Avatar'; import { Sale } from '../types'; - -const isLinkedinUrl = (url: string) => { - if (!url) return; - try { - // Parse the URL to ensure it is valid - const parsedUrl = new URL(url); - if (!parsedUrl.hostname.startsWith('https://linkedin.com/')) { - return 'URL must be from linkedin.com'; - } - } catch (e) { - // If URL parsing fails, return false - return 'Must be a valid URL'; - } -}; +import { Avatar } from './Avatar'; export const ContactInputs = () => { const theme = useTheme(); From eaf7516776120b23aee0168159d6bb92694ca0a6 Mon Sep 17 00:00:00 2001 From: Jonathan ARNAULT Date: Fri, 26 Jul 2024 10:07:44 +0200 Subject: [PATCH 3/3] Fix(crm): It was not possible ta save a company or a contact due to linkedin URL --- examples/crm/src/contacts/ContactAside.tsx | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/crm/src/contacts/ContactAside.tsx b/examples/crm/src/contacts/ContactAside.tsx index f0ed014fad..7ef50138be 100644 --- a/examples/crm/src/contacts/ContactAside.tsx +++ b/examples/crm/src/contacts/ContactAside.tsx @@ -1,27 +1,26 @@ -import * as React from 'react'; +import EmailIcon from '@mui/icons-material/Email'; +import LinkedInIcon from '@mui/icons-material/LinkedIn'; +import PhoneIcon from '@mui/icons-material/Phone'; +import { Box, Divider, Stack, Typography } from '@mui/material'; import { - TextField, - EmailField, DateField, - ReferenceManyField, EditButton, - ShowButton, + EmailField, + FunctionField, ReferenceField, + ReferenceManyField, SelectField, - FunctionField, - useRecordContext, + ShowButton, + TextField, UrlField, + useRecordContext, } from 'react-admin'; -import { Box, Typography, Divider, Stack } from '@mui/material'; -import EmailIcon from '@mui/icons-material/Email'; -import LinkedInIcon from '@mui/icons-material/LinkedIn'; -import PhoneIcon from '@mui/icons-material/Phone'; -import { TagsListEdit } from './TagsListEdit'; import { AddTask } from '../tasks/AddTask'; import { TasksIterator } from '../tasks/TasksIterator'; +import { TagsListEdit } from './TagsListEdit'; -import { Contact, Sale } from '../types'; import { useConfigurationContext } from '../root/ConfigurationContext'; +import { Contact, Sale } from '../types'; export const ContactAside = ({ link = 'edit' }: { link?: 'edit' | 'show' }) => { const { contactGender } = useConfigurationContext(); @@ -63,6 +62,7 @@ export const ContactAside = ({ link = 'edit' }: { link?: 'edit' | 'show' }) => { content="linkedin_url" target="_blank" rel="noopener" + label="LinkedIn" /> )}