1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01: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 {
inviteLink: string;
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 setError = () =>
setToastData({
type: 'error',
title: errorTitle,
});
const handleCopy = () => {
try {
return navigator.clipboard
@ -17,7 +30,7 @@ export const LinkField = ({ inviteLink, small }: ILinkFieldProps) => {
.then(() => {
setToastData({
type: 'success',
title: 'Successfully copied invite link.',
title: successTitle,
});
})
.catch(() => {
@ -28,12 +41,6 @@ export const LinkField = ({ inviteLink, small }: ILinkFieldProps) => {
}
};
const setError = () =>
setToastData({
type: 'error',
title: 'Could not copy invite link.',
});
return (
<Box
sx={{