430644448a
This PR was created by [GitStart](https://gitstart.com/) to address the requirements from this ticket: [TWNTY-7535](https://clients.gitstart.com/twenty/5449/tickets/TWNTY-7535). --- ### Description. Migrate link components to `twenty-ui` \ \ Fixes #7535 --------- Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com> Co-authored-by: gitstart-twenty <140154534+gitstart-twenty@users.noreply.github.com> Co-authored-by: Charles Bochet <charles@twenty.com>
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import { parsePhoneNumber, PhoneNumber } from 'libphonenumber-js';
|
|
import { MouseEvent } from 'react';
|
|
import { ContactLink } from 'twenty-ui';
|
|
|
|
import { isDefined } from '~/utils/isDefined';
|
|
|
|
type PhoneDisplayProps = {
|
|
value: string | null | undefined;
|
|
};
|
|
|
|
// TODO: see if we can find a faster way to format the phone number
|
|
export const PhoneDisplay = ({ value }: PhoneDisplayProps) => {
|
|
if (!isDefined(value)) {
|
|
return <ContactLink href="#">{value}</ContactLink>;
|
|
}
|
|
|
|
let parsedPhoneNumber: PhoneNumber | null = null;
|
|
|
|
try {
|
|
// TODO: parse according to locale not hard coded FR
|
|
parsedPhoneNumber = parsePhoneNumber(value, 'FR');
|
|
} catch (error) {
|
|
return <ContactLink href="#">{value}</ContactLink>;
|
|
}
|
|
|
|
const URI = parsedPhoneNumber.getURI();
|
|
const formatedPhoneNumber = parsedPhoneNumber.formatInternational();
|
|
|
|
return (
|
|
<ContactLink
|
|
href={URI}
|
|
onClick={(event: MouseEvent<HTMLElement>) => {
|
|
event.stopPropagation();
|
|
}}
|
|
>
|
|
{formatedPhoneNumber || value}
|
|
</ContactLink>
|
|
);
|
|
};
|