1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-11-10 01:19:53 +01:00
unleash.unleash/frontend/src/component/common/ApiTokenTable/CopyApiTokenButton/CopyApiTokenButton.tsx
Thomas Heartman b2c58102dd
chore(unl-204): remove uses of toast text and confetti (#8941)
As of PR #8935, we no longer support both text and title, and confetti
has been removed.

This PR:
- removes `confetti` from the toast interface
- merges `text` and `title` into `text` and updates its uses across the
codebase.
- readjusts the text where necessary.
2024-12-10 13:38:04 +00:00

47 lines
1.2 KiB
TypeScript

import type { IApiToken } from 'hooks/api/getters/useApiTokens/useApiTokens';
import useToast from 'hooks/useToast';
import copy from 'copy-to-clipboard';
import FileCopy from '@mui/icons-material/FileCopy';
import PermissionIconButton from 'component/common/PermissionIconButton/PermissionIconButton';
interface ICopyApiTokenButtonProps {
token: IApiToken;
permission: string;
project?: string;
track?: () => void;
}
export const CopyApiTokenButton = ({
token,
project,
permission,
track,
}: ICopyApiTokenButtonProps) => {
const { setToastData } = useToast();
const copyToken = (value: string) => {
if (copy(value)) {
setToastData({
type: 'success',
text: 'Token copied to clipboard',
});
if (track && typeof track === 'function') {
track();
}
}
};
return (
<PermissionIconButton
permission={permission}
projectId={project}
tooltipProps={{ title: 'Copy token', arrow: true }}
onClick={() => copyToken(token.secret)}
size='large'
>
<FileCopy />
</PermissionIconButton>
);
};