-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathConfirmationStep.tsx
135 lines (121 loc) · 5.74 KB
/
ConfirmationStep.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import React, {useEffect, useRef} from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import Button from '@components/Button';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import InteractiveStepSubHeader from '@components/InteractiveStepSubHeader';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import ScreenWrapper from '@components/ScreenWrapper';
import ScrollView from '@components/ScrollView';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
import {getTranslationKeyForLimitType} from '@libs/CardUtils';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
import Navigation from '@navigation/Navigation';
import * as Card from '@userActions/Card';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Route} from '@src/ROUTES';
import type {IssueNewCardStep} from '@src/types/onyx/Card';
type ConfirmationStepProps = {
/** ID of the policy that the card will be issued under */
policyID: string;
/** Route to navigate to */
backTo?: Route;
};
function ConfirmationStep({policyID, backTo}: ConfirmationStepProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const {isOffline} = useNetwork();
const [issueNewCard] = useOnyx(ONYXKEYS.ISSUE_NEW_EXPENSIFY_CARD);
const data = issueNewCard?.data;
const submitButton = useRef<View>(null);
useEffect(() => {
submitButton.current?.focus();
}, []);
const submit = () => {
Card.issueExpensifyCard(policyID, CONST.COUNTRY.US, data);
Navigation.navigate(backTo ?? ROUTES.WORKSPACE_EXPENSIFY_CARD.getRoute(policyID ?? '-1'));
Card.clearIssueNewCardFlow();
};
const editStep = (step: IssueNewCardStep) => {
Card.setIssueNewCardStepAndData({step, isEditing: true});
};
const handleBackButtonPress = () => {
Card.setIssueNewCardStepAndData({step: CONST.EXPENSIFY_CARD.STEP.CARD_NAME});
};
const translationForLimitType = getTranslationKeyForLimitType(data?.limitType);
return (
<ScreenWrapper
testID={ConfirmationStep.displayName}
includeSafeAreaPaddingBottom={false}
shouldEnablePickerAvoiding={false}
shouldEnableMaxHeight
>
<HeaderWithBackButton
title={translate('workspace.card.issueCard')}
onBackButtonPress={handleBackButtonPress}
/>
<View style={[styles.ph5, styles.mb5, styles.mt3, {height: CONST.BANK_ACCOUNT.STEPS_HEADER_HEIGHT}]}>
<InteractiveStepSubHeader
startStepIndex={5}
stepNames={CONST.EXPENSIFY_CARD.STEP_NAMES}
/>
</View>
<ScrollView
style={styles.pt0}
contentContainerStyle={styles.flexGrow1}
>
<Text style={[styles.textHeadlineLineHeightXXL, styles.ph5, styles.mt3]}>{translate('workspace.card.issueNewCard.letsDoubleCheck')}</Text>
<Text style={[styles.textSupporting, styles.ph5, styles.mv3]}>{translate('workspace.card.issueNewCard.willBeReady')}</Text>
<MenuItemWithTopDescription
description={translate('workspace.card.issueNewCard.cardholder')}
title={PersonalDetailsUtils.getUserNameByEmail(data?.assigneeEmail ?? '', 'displayName')}
shouldShowRightIcon
onPress={() => editStep(CONST.EXPENSIFY_CARD.STEP.ASSIGNEE)}
/>
<MenuItemWithTopDescription
description={translate('workspace.card.issueNewCard.cardType')}
title={data?.cardType ? translate(`workspace.card.issueNewCard.${data?.cardType}Card`) : ''}
shouldShowRightIcon
onPress={() => editStep(CONST.EXPENSIFY_CARD.STEP.CARD_TYPE)}
/>
<MenuItemWithTopDescription
description={translate('workspace.card.issueNewCard.limit')}
title={CurrencyUtils.convertToShortDisplayString(data?.limit)}
shouldShowRightIcon
onPress={() => editStep(CONST.EXPENSIFY_CARD.STEP.LIMIT)}
/>
<MenuItemWithTopDescription
description={translate('workspace.card.issueNewCard.limitType')}
title={translationForLimitType ? translate(translationForLimitType) : ''}
shouldShowRightIcon
onPress={() => editStep(CONST.EXPENSIFY_CARD.STEP.LIMIT_TYPE)}
/>
<MenuItemWithTopDescription
description={translate('workspace.card.issueNewCard.name')}
title={data?.cardTitle}
shouldShowRightIcon
onPress={() => editStep(CONST.EXPENSIFY_CARD.STEP.CARD_NAME)}
/>
<View style={[styles.mh5, styles.pb5, styles.mt3, styles.flexGrow1, styles.justifyContentEnd]}>
<Button
ref={submitButton}
isDisabled={isOffline}
success
large
style={[styles.w100]}
onPress={submit}
text={translate('workspace.card.issueCard')}
/>
</View>
</ScrollView>
</ScreenWrapper>
);
}
ConfirmationStep.displayName = 'ConfirmationStep';
export default ConfirmationStep;