Skip to content

Commit

Permalink
Fix(crm): It was not possible ta save a company or a contact due to l…
Browse files Browse the repository at this point in the history
…inkedin URL
  • Loading branch information
arnault-dev committed Jul 26, 2024
1 parent dba9e37 commit 71def36
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 41 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';
}
};
1 change: 1 addition & 0 deletions examples/crm/src/companies/CompanyAside.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const CompanyInfo = ({ record }: { record: Company }) => {
content="LinkedIn"
target="_blank"
rel="noopener"
label="LinkedIn"
/>
</Stack>
)}
Expand Down
15 changes: 1 addition & 14 deletions examples/crm/src/companies/CompanyInputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
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

0 comments on commit 71def36

Please sign in to comment.