Skip to content

Commit

Permalink
Merge pull request Expensify#52407 from mkzie2/mkzie2-issue/52124
Browse files Browse the repository at this point in the history
  • Loading branch information
dangrous authored Nov 15, 2024
2 parents a312ab4 + 5ab2011 commit a54f913
Showing 1 changed file with 48 additions and 43 deletions.
91 changes: 48 additions & 43 deletions src/components/ValidateCode/ValidateCodeModal.tsx
Original file line number Diff line number Diff line change
@@ -1,78 +1,83 @@
import React, {useCallback} from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import * as Illustrations from '@components/Icon/Illustrations';
import Text from '@components/Text';
import TextLink from '@components/TextLink';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import * as ValidationUtils from '@libs/ValidationUtils';
import variables from '@styles/variables';
import * as Session from '@userActions/Session';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Session as SessionType} from '@src/types/onyx';

type ValidateCodeModalOnyxProps = {
/** Session of currently logged in user */
session: OnyxEntry<SessionType>;
};

type ValidateCodeModalProps = ValidateCodeModalOnyxProps & {
type ValidateCodeModalProps = {
/** Code to display. */
code: string;
/** The ID of the account to which the code belongs. */
accountID: number;
};

function ValidateCodeModal({code, accountID, session = {}}: ValidateCodeModalProps) {
function ValidateCodeModal({code, accountID}: ValidateCodeModalProps) {
const theme = useTheme();
const styles = useThemeStyles();
const [session] = useOnyx(ONYXKEYS.SESSION);
const signInHere = useCallback(() => Session.signInWithValidateCode(accountID, code), [accountID, code]);
const {translate} = useLocalize();
const {shouldUseNarrowLayout} = useResponsiveLayout();

return (
<View style={styles.deeplinkWrapperContainer}>
<View style={styles.deeplinkWrapperMessage}>
<View style={styles.mb2}>
<FullPageNotFoundView
shouldShow={!ValidationUtils.isValidValidateCode(code)}
shouldShowBackButton={shouldUseNarrowLayout}
onLinkPress={() => {
Navigation.goBack();
}}
>
<View style={styles.deeplinkWrapperContainer}>
<View style={styles.deeplinkWrapperMessage}>
<View style={styles.mb2}>
<Icon
width={variables.modalTopIconWidth}
height={variables.modalTopIconHeight}
src={Illustrations.MagicCode}
/>
</View>
<Text style={[styles.textHeadline, styles.textXXLarge, styles.textAlignCenter]}>{translate('validateCodeModal.title')}</Text>
<View style={[styles.mt2, styles.mb2]}>
<Text style={styles.textAlignCenter}>
{translate('validateCodeModal.description')}
{!session?.authToken && (
<>
{translate('validateCodeModal.or')} <TextLink onPress={signInHere}>{translate('validateCodeModal.signInHere')}</TextLink>
</>
)}
.
</Text>
</View>
<View style={styles.mt6}>
<Text style={styles.validateCodeDigits}>{code}</Text>
</View>
</View>
<View style={styles.deeplinkWrapperFooter}>
<Icon
width={variables.modalTopIconWidth}
height={variables.modalTopIconHeight}
src={Illustrations.MagicCode}
width={variables.modalWordmarkWidth}
height={variables.modalWordmarkHeight}
fill={theme.success}
src={Expensicons.ExpensifyWordmark}
/>
</View>
<Text style={[styles.textHeadline, styles.textXXLarge, styles.textAlignCenter]}>{translate('validateCodeModal.title')}</Text>
<View style={[styles.mt2, styles.mb2]}>
<Text style={styles.textAlignCenter}>
{translate('validateCodeModal.description')}
{!session?.authToken && (
<>
{translate('validateCodeModal.or')} <TextLink onPress={signInHere}>{translate('validateCodeModal.signInHere')}</TextLink>
</>
)}
.
</Text>
</View>
<View style={styles.mt6}>
<Text style={styles.validateCodeDigits}>{code}</Text>
</View>
</View>
<View style={styles.deeplinkWrapperFooter}>
<Icon
width={variables.modalWordmarkWidth}
height={variables.modalWordmarkHeight}
fill={theme.success}
src={Expensicons.ExpensifyWordmark}
/>
</View>
</View>
</FullPageNotFoundView>
);
}

ValidateCodeModal.displayName = 'ValidateCodeModal';

export default withOnyx<ValidateCodeModalProps, ValidateCodeModalOnyxProps>({
session: {key: ONYXKEYS.SESSION},
})(ValidateCodeModal);
export default ValidateCodeModal;

0 comments on commit a54f913

Please sign in to comment.