Skip to content

Commit

Permalink
fix: adding https in checkurltype (#6295)
Browse files Browse the repository at this point in the history
# 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 <[email protected]>
Co-authored-by: Félix Malfait <[email protected]>
  • Loading branch information
3 people authored Jul 16, 2024
1 parent 1bfc6ae commit 539251c
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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, '');
Expand All @@ -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} />;
};

0 comments on commit 539251c

Please sign in to comment.