Files
twenty/front/src/modules/ui/input/components/EmailInputDisplay.tsx
T
Lucas Bordeau a766c60aa5 Reafactor/UI input and displays (#1544)
* WIP

* Text field

* URL

* Finished PhoneInput

* Refactored input sub-folders

* Boolean

* Fix lint

* Fix lint

* Fix useOutsideClick

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
2023-09-11 17:11:20 -07:00

28 lines
631 B
TypeScript

import { MouseEvent } from 'react';
import { ContactLink } from '@/ui/link/components/ContactLink';
function validateEmail(email: string) {
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailPattern.test(email.trim());
}
type OwnProps = {
value: string | null;
};
export function EmailInputDisplay({ value }: OwnProps) {
return value && validateEmail(value) ? (
<ContactLink
href={`mailto:${value}`}
onClick={(event: MouseEvent<HTMLElement>) => {
event.stopPropagation();
}}
>
{value}
</ContactLink>
) : (
<ContactLink href="#">{value}</ContactLink>
);
}