Skip to content

Commit

Permalink
Clicking a phone number should copy its value
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucifer4255 committed Dec 13, 2024
1 parent afd3252 commit c30e720
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ import { RoundedLink, THEME_COMMON } from 'twenty-ui';
import { FieldPhonesValue } from '@/object-record/record-field/types/FieldMetadata';
import { ExpandableList } from '@/ui/layout/expandable-list/components/ExpandableList';

import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar';
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
import { IconClipboard } from '@tabler/icons-react';
import { parsePhoneNumber } from 'libphonenumber-js';
import { isDefined } from '~/utils/isDefined';
import { logError } from '~/utils/logError';




type PhonesDisplayProps = {
value?: FieldPhonesValue;
isFocused?: boolean;
Expand All @@ -30,6 +36,23 @@ const StyledContainer = styled.div`
`;

export const PhonesDisplay = ({ value, isFocused }: PhonesDisplayProps) => {
const { enqueueSnackBar } = useSnackBar();
const handlePhoneClick = async (event: React.MouseEvent, phoneNumber: string | undefined) => {
event.preventDefault(); // Prevent default link behavior

try {
if(phoneNumber != undefined){
await navigator.clipboard.writeText(phoneNumber);
enqueueSnackBar('Phone number copied to clipboard', {
variant: SnackBarVariant.Success,
icon: <IconClipboard size={16} />,
duration: 2000
});
}
} catch (error) {
console.error('Failed to copy phone number:', error);
}
};
const phones = useMemo(
() =>
[
Expand Down Expand Up @@ -76,6 +99,7 @@ export const PhonesDisplay = ({ value, isFocused }: PhonesDisplayProps) => {
label={
parsedPhone ? parsedPhone.formatInternational() : invalidPhone
}
onClick={(event) => handlePhoneClick(event,URI)}
/>
);
})}
Expand Down

0 comments on commit c30e720

Please sign in to comment.