Skip to content

Commit

Permalink
updated the phonedisplay adding a prop
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucifer4255 committed Dec 20, 2024
1 parent 2ceb1c8 commit 0ff225c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
import { useFieldFocus } from '@/object-record/record-field/hooks/useFieldFocus';
import { usePhonesFieldDisplay } from '@/object-record/record-field/meta-types/hooks/usePhonesFieldDisplay';
import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar';
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
import { PhonesDisplay } from '@/ui/field/display/components/PhonesDisplay';
import React from 'react';
import { useIcons } from 'twenty-ui';

export const PhonesFieldDisplay = () => {
const { fieldValue } = usePhonesFieldDisplay();

const { isFocused } = useFieldFocus();

return <PhonesDisplay value={fieldValue} isFocused={isFocused} />;
const {enqueueSnackBar} = useSnackBar();

const {getIcon} = useIcons();

const IconClipboard = getIcon('IconClipboard');

const handleClick = async(phoneNumber:string,event: React.MouseEvent<HTMLElement>) =>{
event.preventDefault();
try{
await navigator.clipboard.writeText(phoneNumber);
enqueueSnackBar('Phone number copied to clipboard', {
variant: SnackBarVariant.Success,
icon: <IconClipboard size={16} />,
duration: 2000
});
}catch(err){
enqueueSnackBar('Error copying to clipboard', {
variant: SnackBarVariant.Error,
icon: <IconClipboard size={16} />,
duration: 2000
});
}


}

return <PhonesDisplay value={fieldValue} isFocused={isFocused} onPhoneNumberClick={handleClick}/>;
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styled from '@emotion/styled';
import { useMemo } from 'react';
import React, { useMemo } from 'react';
import { RoundedLink, THEME_COMMON } from 'twenty-ui';

import { FieldPhonesValue } from '@/object-record/record-field/types/FieldMetadata';
Expand All @@ -12,6 +12,7 @@ import { logError } from '~/utils/logError';
type PhonesDisplayProps = {
value?: FieldPhonesValue;
isFocused?: boolean;
onPhoneNumberClick?: (phoneNumber: string,event : React.MouseEvent<HTMLElement>) => void;
};

const themeSpacing = THEME_COMMON.spacingMultiplicator;
Expand All @@ -29,7 +30,7 @@ const StyledContainer = styled.div`
width: 100%;
`;

export const PhonesDisplay = ({ value, isFocused }: PhonesDisplayProps) => {
export const PhonesDisplay = ({ value, isFocused, onPhoneNumberClick }: PhonesDisplayProps) => {
const phones = useMemo(
() =>
[
Expand Down Expand Up @@ -62,7 +63,11 @@ export const PhonesDisplay = ({ value, isFocused }: PhonesDisplayProps) => {
return { invalidPhone: number };
}
};

const handleClick = (number: string,event :React.MouseEvent<HTMLElement>) => {
if (onPhoneNumberClick) {
onPhoneNumberClick(number,event);
}
};
return isFocused ? (
<ExpandableList isChipCountDisplayed>
{phones.map(({ number, callingCode }, index) => {
Expand All @@ -76,6 +81,7 @@ export const PhonesDisplay = ({ value, isFocused }: PhonesDisplayProps) => {
label={
parsedPhone ? parsedPhone.formatInternational() : invalidPhone
}
onClick={(event) => handleClick(callingCode + number,event)}
/>
);
})}
Expand All @@ -93,6 +99,7 @@ export const PhonesDisplay = ({ value, isFocused }: PhonesDisplayProps) => {
label={
parsedPhone ? parsedPhone.formatInternational() : invalidPhone
}
onClick={(event) => handleClick(callingCode + number,event)}
/>
);
})}
Expand Down

0 comments on commit 0ff225c

Please sign in to comment.