Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

Fix company URL

François Zaninottoe357c767f029
diff --git a/src/companies/CompanyAside.tsx b/src/companies/CompanyAside.tsx
index cb628d5e..e056dc0d 100644
--- a/src/companies/CompanyAside.tsx
+++ b/src/companies/CompanyAside.tsx
@@ -62,7 +62,14 @@ const CompanyInfo = ({ record }: { record: Company }) => {
minHeight={24}
>
<PublicIcon color="disabled" fontSize="small" />
- <UrlField source="website" target="_blank" rel="noopener" />
+ <UrlField
+ source="website"
+ target="_blank"
+ rel="noopener"
+ content={record.website
+ .replace('http://', '')
+ .replace('https://', '')}
+ />
</Stack>
)}
{record.linkedin_url && (
diff --git a/src/companies/CompanyCreate.tsx b/src/companies/CompanyCreate.tsx
index 9f817841..0cc2e5f2 100644
--- a/src/companies/CompanyCreate.tsx
+++ b/src/companies/CompanyCreate.tsx
@@ -7,7 +7,17 @@ import { CompanyInputs } from './CompanyInputs';
export const CompanyCreate = () => {
const { identity } = useGetIdentity();
return (
- <Create actions={false} redirect="show">
+ <Create
+ actions={false}
+ redirect="show"
+ transform={values => {
+ // add https:// before website if not present
+ if (values.website && !values.website.startsWith('http')) {
+ values.website = `https://${values.website}`;
+ }
+ return values;
+ }}
+ >
<Form defaultValues={{ sales_id: identity?.id }}>
<CardContent>
<CompanyInputs />
diff --git a/src/companies/CompanyEdit.tsx b/src/companies/CompanyEdit.tsx
index 1e3f56c7..c26bd1bf 100644
--- a/src/companies/CompanyEdit.tsx
+++ b/src/companies/CompanyEdit.tsx
@@ -7,7 +7,18 @@ import { CompanyInputs } from './CompanyInputs';
import { CompanyAside } from './CompanyAside';
export const CompanyEdit = () => (
- <Edit aside={<CompanyAside link="show" />} actions={false} redirect="show">
+ <Edit
+ aside={<CompanyAside link="show" />}
+ actions={false}
+ redirect="show"
+ transform={values => {
+ // add https:// before website if not present
+ if (values.website && !values.website.startsWith('http')) {
+ values.website = `https://${values.website}`;
+ }
+ return values;
+ }}
+ >
<Form>
<CardContent>
<CompanyInputs />
diff --git a/src/companies/CompanyInputs.tsx b/src/companies/CompanyInputs.tsx
index 6b9ce980..94ad8512 100644
--- a/src/companies/CompanyInputs.tsx
+++ b/src/companies/CompanyInputs.tsx
@@ -22,11 +22,10 @@ import ImageEditorField from '../misc/ImageEditorField';
const isUrl = (url: string) => {
if (!url) return;
- try {
- // Parse the URL to ensure it is valid
- new URL(url);
- } catch (e) {
- // If URL parsing fails, return false
+ const UrlRegex = new RegExp(
+ /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/i
+ );
+ if (!UrlRegex.test(url)) {
return 'Must be a valid URL';
}
};