fix: adding https in checkurltype (#6295)

# Fix URL handling for LinkedIn and Twitter links

Fixes #6287 

## Solution
Updated `checkUrlType` function to prepend "https://" to URLs if
missing, ensuring proper handling of social media links.

## Changes
- Modified `/packages/twenty-front/src/utils/checkUrlType.ts`
- Added a check to prepend "https://" if URL doesn't start with a
protocol

---------

Co-authored-by: Prince Yadav <prince1.yadav@tataaig.com>
Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
This commit is contained in:
Prince Yadav
2024-07-17 02:13:44 +05:30
committed by GitHub
parent 1bfc6aeba0
commit 539251c7ad

View File

@ -18,6 +18,12 @@ export const LinkDisplay = ({ value }: LinkDisplayProps) => {
return <></>;
}
const absoluteUrl = url
? url.startsWith('http')
? url
: 'https://' + url
: '';
const displayedValue = isNonEmptyString(value?.label)
? value?.label
: url?.replace(/^http[s]?:\/\/(?:[w]+\.)?/gm, '').replace(/^[w]+\./gm, '');
@ -29,8 +35,8 @@ export const LinkDisplay = ({ value }: LinkDisplayProps) => {
: LinkType.Url;
if (type === LinkType.LinkedIn || type === LinkType.Twitter) {
return <SocialLink href={url} type={type} label={displayedValue} />;
return <SocialLink href={absoluteUrl} type={type} label={displayedValue} />;
}
return <RoundedLink href={url} label={displayedValue} />;
return <RoundedLink href={absoluteUrl} label={displayedValue} />;
};