1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-24 01:18:01 +02:00

refactor: improve link field customizability (#6402)

Add ability to reuse "copy link" dialogue in other places
This commit is contained in:
Tymoteusz Czech 2024-03-01 11:01:58 +01:00 committed by GitHub
parent d057703b2f
commit 446b2b2a2d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,11 +5,24 @@ import useToast from 'hooks/useToast';
interface ILinkFieldProps { interface ILinkFieldProps {
inviteLink: string; inviteLink: string;
small?: boolean; small?: boolean;
successTitle?: string;
errorTitle?: string;
} }
export const LinkField = ({ inviteLink, small }: ILinkFieldProps) => { export const LinkField = ({
inviteLink,
small,
successTitle = 'Successfully copied invite link.',
errorTitle = 'Could not copy invite link.',
}: ILinkFieldProps) => {
const { setToastData } = useToast(); const { setToastData } = useToast();
const setError = () =>
setToastData({
type: 'error',
title: errorTitle,
});
const handleCopy = () => { const handleCopy = () => {
try { try {
return navigator.clipboard return navigator.clipboard
@ -17,7 +30,7 @@ export const LinkField = ({ inviteLink, small }: ILinkFieldProps) => {
.then(() => { .then(() => {
setToastData({ setToastData({
type: 'success', type: 'success',
title: 'Successfully copied invite link.', title: successTitle,
}); });
}) })
.catch(() => { .catch(() => {
@ -28,12 +41,6 @@ export const LinkField = ({ inviteLink, small }: ILinkFieldProps) => {
} }
}; };
const setError = () =>
setToastData({
type: 'error',
title: 'Could not copy invite link.',
});
return ( return (
<Box <Box
sx={{ sx={{