Skip to content

Commit

Permalink
refactor: improve link field customizability (#6402)
Browse files Browse the repository at this point in the history
Add ability to reuse "copy link" dialogue in other places
  • Loading branch information
Tymek committed Mar 1, 2024
1 parent d057703 commit 446b2b2
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions frontend/src/component/admin/users/LinkField/LinkField.tsx
Expand Up @@ -5,19 +5,32 @@ 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
.writeText(inviteLink)
.then(() => {
setToastData({
type: 'success',
title: 'Successfully copied invite link.',
title: successTitle,
});
})
.catch(() => {
Expand All @@ -28,12 +41,6 @@ export const LinkField = ({ inviteLink, small }: ILinkFieldProps) => {
}
};

const setError = () =>
setToastData({
type: 'error',
title: 'Could not copy invite link.',
});

return (
<Box
sx={{
Expand Down

0 comments on commit 446b2b2

Please sign in to comment.