Copy JSON values on click (#11382)
https://github.com/user-attachments/assets/1638c196-fb9c-4f2b-910c-6d8b0693a37a Closes https://github.com/twentyhq/core-team-issues/issues/568
This commit is contained in:
committed by
GitHub
parent
bb40bc9929
commit
9353e777ea
31
packages/twenty-front/src/hooks/useCopyToClipboard.tsx
Normal file
31
packages/twenty-front/src/hooks/useCopyToClipboard.tsx
Normal file
@ -0,0 +1,31 @@
|
||||
import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar';
|
||||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||
import { useTheme } from '@emotion/react';
|
||||
import { useLingui } from '@lingui/react/macro';
|
||||
import { IconCopy, IconExclamationCircle } from 'twenty-ui/display';
|
||||
|
||||
export const useCopyToClipboard = () => {
|
||||
const theme = useTheme();
|
||||
const { enqueueSnackBar } = useSnackBar();
|
||||
const { t } = useLingui();
|
||||
|
||||
const copyToClipboard = async (valueAsString: string) => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(valueAsString);
|
||||
|
||||
enqueueSnackBar(t`Copied to clipboard`, {
|
||||
variant: SnackBarVariant.Success,
|
||||
icon: <IconCopy size={theme.icon.size.md} />,
|
||||
duration: 2000,
|
||||
});
|
||||
} catch {
|
||||
enqueueSnackBar(t`Couldn't copy to clipboard`, {
|
||||
variant: SnackBarVariant.Error,
|
||||
icon: <IconExclamationCircle size={16} color="red" />,
|
||||
duration: 2000,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return { copyToClipboard };
|
||||
};
|
||||
Reference in New Issue
Block a user