Skip to content

Commit bf1f2fd

Browse files
committed
refactor(ui): replace obsolete TextCopy with CodeSnippet in TwoFactorTOTP
1 parent 4235cd9 commit bf1f2fd

File tree

2 files changed

+7
-49
lines changed

2 files changed

+7
-49
lines changed

apps/meteor/client/components/TextCopy.tsx

Lines changed: 0 additions & 45 deletions
This file was deleted.

apps/meteor/client/views/account/security/TwoFactorTOTP.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Box, Button, TextInput, Margins, Field, FieldRow, FieldLabel, ToggleSwitch } from '@rocket.chat/fuselage';
2-
import { useEffectEvent, useSafely } from '@rocket.chat/fuselage-hooks';
1+
import { Box, Button, TextInput, Margins, Field, FieldRow, FieldLabel, ToggleSwitch, CodeSnippet } from '@rocket.chat/fuselage';
2+
import { useEffectEvent, useSafely, useClipboard } from '@rocket.chat/fuselage-hooks';
33
import { useSetModal, useToastMessageDispatch, useUser, useMethod } from '@rocket.chat/ui-contexts';
44
import type { ReactElement, ComponentPropsWithoutRef, FormEvent } from 'react';
55
import { useState, useCallback, useEffect, useId } from 'react';
@@ -8,7 +8,6 @@ import { useTranslation } from 'react-i18next';
88
import qrcode from 'yaqrcode';
99

1010
import BackupCodesModal from './BackupCodesModal';
11-
import TextCopy from '../../../components/TextCopy';
1211
import TwoFactorTotpModal from '../../../components/TwoFactorModal/TwoFactorTotpModal';
1312

1413
type TwoFactorTOTPFormData = {
@@ -36,6 +35,8 @@ const TwoFactorTOTP = (props: TwoFactorTOTPProps): ReactElement => {
3635

3736
const { register, handleSubmit } = useForm<TwoFactorTOTPFormData>({ defaultValues: { authCode: '' } });
3837

38+
const { copy, hasCopied } = useClipboard(totpSecret || '');
39+
3940
const totpEnabled = user?.services?.totp?.enabled;
4041

4142
const closeModal = useCallback(() => setModal(null), [setModal]);
@@ -153,7 +154,9 @@ const TwoFactorTOTP = (props: TwoFactorTOTPProps): ReactElement => {
153154
<>
154155
<Box>{t('Scan_QR_code')}</Box>
155156
<Box>{t('Scan_QR_code_alternative_s')}</Box>
156-
<TextCopy text={totpSecret || ''} />
157+
<CodeSnippet buttonText={hasCopied ? t('Copied') : t('Copy')} buttonDisabled={hasCopied} onClick={() => copy()}>
158+
{totpSecret || ''}
159+
</CodeSnippet>
157160
<Box mis='-16px' mb='-16px' is='img' size='x200' src={qrCode} aria-hidden='true' />
158161
<Field>
159162
<FieldLabel htmlFor={totpCodeId}>{t('Enter_code_provided_by_authentication_app')}</FieldLabel>

0 commit comments

Comments
 (0)