|
| 1 | +import React, {useRef} from 'react'; |
| 2 | +import {View} from 'react-native'; |
| 3 | +import {withOnyx} from 'react-native-onyx'; |
| 4 | +import Button from '@components/Button'; |
| 5 | +import FixedFooter from '@components/FixedFooter'; |
| 6 | +import ScrollView from '@components/ScrollView'; |
| 7 | +import Text from '@components/Text'; |
| 8 | +import useLocalize from '@hooks/useLocalize'; |
| 9 | +import useThemeStyles from '@hooks/useThemeStyles'; |
| 10 | +import type {BackToParams} from '@libs/Navigation/types'; |
| 11 | +import StepWrapper from '@pages/settings/Security/TwoFactorAuth/StepWrapper/StepWrapper'; |
| 12 | +import useTwoFactorAuthContext from '@pages/settings/Security/TwoFactorAuth/TwoFactorAuthContext/useTwoFactorAuth'; |
| 13 | +import TwoFactorAuthForm from '@pages/settings/Security/TwoFactorAuth/TwoFactorAuthForm'; |
| 14 | +import type {BaseTwoFactorAuthFormOnyxProps, BaseTwoFactorAuthFormRef} from '@pages/settings/Security/TwoFactorAuth/TwoFactorAuthForm/types'; |
| 15 | +import CONST from '@src/CONST'; |
| 16 | +import ONYXKEYS from '@src/ONYXKEYS'; |
| 17 | + |
| 18 | +type GetCodeProps = BaseTwoFactorAuthFormOnyxProps & BackToParams; |
| 19 | + |
| 20 | +function GetCode({account}: GetCodeProps) { |
| 21 | + const styles = useThemeStyles(); |
| 22 | + const {translate} = useLocalize(); |
| 23 | + |
| 24 | + const formRef = useRef<BaseTwoFactorAuthFormRef>(null); |
| 25 | + |
| 26 | + const {setStep} = useTwoFactorAuthContext(); |
| 27 | + |
| 28 | + return ( |
| 29 | + <StepWrapper |
| 30 | + title={translate('twoFactorAuth.disableTwoFactorAuth')} |
| 31 | + shouldEnableKeyboardAvoidingView={false} |
| 32 | + onBackButtonPress={() => setStep(CONST.TWO_FACTOR_AUTH_STEPS.ENABLED, CONST.ANIMATION_DIRECTION.OUT)} |
| 33 | + onEntryTransitionEnd={() => formRef.current && formRef.current.focus()} |
| 34 | + > |
| 35 | + <ScrollView contentContainerStyle={styles.flexGrow1}> |
| 36 | + <View style={[styles.ph5, styles.mt3]}> |
| 37 | + <Text>{translate('twoFactorAuth.explainProcessToRemove')}</Text> |
| 38 | + </View> |
| 39 | + </ScrollView> |
| 40 | + <FixedFooter style={[styles.mt2, styles.pt2]}> |
| 41 | + <View style={[styles.mh5, styles.mb4]}> |
| 42 | + <TwoFactorAuthForm |
| 43 | + innerRef={formRef} |
| 44 | + validateInsteadOfDisable={false} |
| 45 | + /> |
| 46 | + </View> |
| 47 | + <Button |
| 48 | + success |
| 49 | + large |
| 50 | + text={translate('twoFactorAuth.disable')} |
| 51 | + isLoading={account?.isLoading} |
| 52 | + onPress={() => { |
| 53 | + if (!formRef.current) { |
| 54 | + return; |
| 55 | + } |
| 56 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-call |
| 57 | + formRef.current.validateAndSubmitForm(); |
| 58 | + }} |
| 59 | + /> |
| 60 | + </FixedFooter> |
| 61 | + </StepWrapper> |
| 62 | + ); |
| 63 | +} |
| 64 | + |
| 65 | +GetCode.displayName = 'GetCode'; |
| 66 | + |
| 67 | +export default withOnyx<GetCodeProps, BaseTwoFactorAuthFormOnyxProps>({ |
| 68 | + account: {key: ONYXKEYS.ACCOUNT}, |
| 69 | + user: { |
| 70 | + key: ONYXKEYS.USER, |
| 71 | + }, |
| 72 | +})(GetCode); |
0 commit comments