1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-01 01:18:10 +02:00
unleash.unleash/frontend/src/component/admin/users/LinkField/LinkField.tsx
Tymoteusz Czech d35ae7827f
feat: insights share events (#6480)
Figure out how many people are using and sharing insights in Beta.


https://linear.app/unleash/issue/1-2145/track-number-of-opened-share-links

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
Co-authored-by: andreas-unleash <andreas@getunleash.ai>
2024-03-13 11:45:42 +02:00

83 lines
2.3 KiB
TypeScript

import { Box, IconButton, Tooltip } from '@mui/material';
import CopyIcon from '@mui/icons-material/FileCopy';
import useToast from 'hooks/useToast';
interface ILinkFieldProps {
inviteLink: string;
small?: boolean;
successTitle?: string;
errorTitle?: string;
onCopy?: () => void;
}
export const LinkField = ({
inviteLink,
small,
successTitle = 'Successfully copied invite link.',
errorTitle = 'Could not copy invite link.',
onCopy,
}: ILinkFieldProps) => {
const { setToastData } = useToast();
const setError = () =>
setToastData({
type: 'error',
title: errorTitle,
});
const handleCopy = () => {
try {
return navigator.clipboard
.writeText(inviteLink)
.then(() => {
setToastData({
type: 'success',
title: successTitle,
});
onCopy?.();
})
.catch(() => {
setError();
});
} catch (e) {
setError();
}
};
return (
<Box
sx={{
backgroundColor: (theme) => theme.palette.background.elevation2,
py: 4,
px: 4,
borderRadius: (theme) => `${theme.shape.borderRadius}px`,
mt: 2,
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
wordBreak: 'break-all',
...(small
? {
my: 0,
py: 0.5,
pl: 1.5,
pr: 0.5,
fontSize: (theme) => theme.typography.body2.fontSize,
}
: {}),
}}
>
{inviteLink}
<Tooltip title='Copy link' arrow>
<IconButton
onClick={handleCopy}
size={small ? 'small' : 'large'}
sx={small ? { ml: 0.5 } : {}}
>
<CopyIcon sx={{ fontSize: small ? 20 : undefined }} />
</IconButton>
</Tooltip>
</Box>
);
};