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' ;
33import { useSetModal , useToastMessageDispatch , useUser , useMethod } from '@rocket.chat/ui-contexts' ;
44import type { ReactElement , ComponentPropsWithoutRef , FormEvent } from 'react' ;
55import { useState , useCallback , useEffect , useId } from 'react' ;
@@ -8,7 +8,6 @@ import { useTranslation } from 'react-i18next';
88import qrcode from 'yaqrcode' ;
99
1010import BackupCodesModal from './BackupCodesModal' ;
11- import TextCopy from '../../../components/TextCopy' ;
1211import TwoFactorTotpModal from '../../../components/TwoFactorModal/TwoFactorTotpModal' ;
1312
1413type 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