Skip to content

Commit

Permalink
Merge pull request #10082 from marmelab/fix/crm-tax-identifier
Browse files Browse the repository at this point in the history
Fix(crm): Rename company.taxe_identifier to company.tax_identifier
  • Loading branch information
arnault-dev authored Jul 26, 2024
2 parents f52c583 + eaf7516 commit 3690327
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 81 deletions.
15 changes: 15 additions & 0 deletions examples/crm/src/commons/isLinkedInUrl.ts
Original file line number Diff line number Diff line change
@@ -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';
}
};
20 changes: 10 additions & 10 deletions examples/crm/src/companies/CompanyAside.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -80,6 +79,7 @@ const CompanyInfo = ({ record }: { record: Company }) => {
content="LinkedIn"
target="_blank"
rel="noopener"
label="LinkedIn"
/>
</Stack>
)}
Expand Down Expand Up @@ -116,14 +116,14 @@ const FinancialInfo = ({ record }: { record: Company }) => {
Revenue: <TextField source="revenue" color="textPrimary" />
</Typography>
)}
{record.taxe_identifier && (
{record.tax_identifier && (
<Typography
component="span"
variant="body2"
color="textSecondary"
>
Tax Identifier:{' '}
<TextField source="taxe_identifier" color="textPrimary" />
<TextField source="tax_identifier" color="textPrimary" />
</Typography>
)}
</Stack>
Expand Down
36 changes: 11 additions & 25 deletions examples/crm/src/companies/CompanyInputs.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
import * as React from 'react';
import {
TextInput,
ReferenceInput,
SelectInput,
required,
ArrayInput,
SimpleFormIterator,
} from 'react-admin';
import {
Divider,
Stack,
Typography,
useMediaQuery,
useTheme,
} from '@mui/material';
import {
ArrayInput,
ReferenceInput,
SelectInput,
SimpleFormIterator,
TextInput,
required,
} from 'react-admin';
import { isLinkedinUrl } from '../commons/isLinkedInUrl';
import { useConfigurationContext } from '../root/ConfigurationContext';
import { Sale } from '../types';
import { sizes } from './sizes';
import { CompanyAvatar } from './CompanyAvatar';

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 { sizes } from './sizes';

export const CompanyInputs = () => {
const theme = useTheme();
Expand Down Expand Up @@ -103,7 +89,7 @@ const CompanyContextInputs = () => {
/>
<SelectInput source="size" choices={sizes} helperText={false} />
<TextInput source="revenue" helperText={false} />
<TextInput source="taxe_identifier" helperText={false} />
<TextInput source="tax_identifier" helperText={false} />
</Stack>
);
};
Expand Down
26 changes: 13 additions & 13 deletions examples/crm/src/contacts/ContactAside.tsx
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -63,6 +62,7 @@ export const ContactAside = ({ link = 'edit' }: { link?: 'edit' | 'show' }) => {
content="linkedin_url"
target="_blank"
rel="noopener"
label="LinkedIn"
/>
</Stack>
)}
Expand Down
40 changes: 13 additions & 27 deletions examples/crm/src/contacts/ContactInputs.tsx
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
10 changes: 5 additions & 5 deletions examples/crm/src/dataGenerator/companies.ts
Original file line number Diff line number Diff line change
@@ -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];

Expand Down Expand Up @@ -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: [],
};
Expand Down
2 changes: 1 addition & 1 deletion examples/crm/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}
Expand Down

0 comments on commit 3690327

Please sign in to comment.