-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clicking a phone number should copy its value (#9069)
https://github.com/user-attachments/assets/7ce595fa-be90-4ec7-81e5-075dafee6422 I have added the functionality of copying the phone number to clipboard according to the issue #8905 . If anything needed to change just comment in my PR --------- Co-authored-by: Lucas Bordeau <[email protected]>
- Loading branch information
1 parent
c52a492
commit 578ba97
Showing
4 changed files
with
62 additions
and
15 deletions.
There are no files selected for viewing
41 changes: 40 additions & 1 deletion
41
...c/modules/object-record/record-field/meta-types/display/components/PhonesFieldDisplay.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,50 @@ | ||
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 IconCircleCheck = getIcon('IconCircleCheck'); | ||
const IconExclamationCircle = getIcon('IconExclamationCircle'); | ||
|
||
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: <IconCircleCheck size={16} color="green" />, | ||
duration: 2000, | ||
}); | ||
} catch (err) { | ||
enqueueSnackBar('Error copying to clipboard', { | ||
variant: SnackBarVariant.Error, | ||
icon: <IconExclamationCircle size={16} color="red" />, | ||
duration: 2000, | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<PhonesDisplay | ||
value={fieldValue} | ||
isFocused={isFocused} | ||
onPhoneNumberClick={handleClick} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters