-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
Confirmation.tsx
86 lines (79 loc) · 3.93 KB
/
Confirmation.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
import React from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import Button from '@components/Button';
import FixedFooter from '@components/FixedFooter';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import type {SubStepProps} from '@hooks/useSubStep/types';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@navigation/Navigation';
import {formatSubscriptionEndDate, getNewSubscriptionRenewalDate} from '@pages/settings/Subscription/utils';
import * as FormActions from '@userActions/FormActions';
import ONYXKEYS from '@src/ONYXKEYS';
import INPUT_IDS from '@src/types/form/SubscriptionSizeForm';
type ConfirmationProps = SubStepProps;
function Confirmation({onNext, isEditing}: ConfirmationProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const [account] = useOnyx(ONYXKEYS.ACCOUNT);
const [privateSubscription] = useOnyx(ONYXKEYS.NVP_PRIVATE_SUBSCRIPTION);
const [subscriptionSizeFormDraft] = useOnyx(ONYXKEYS.FORMS.SUBSCRIPTION_SIZE_FORM_DRAFT);
const subscriptionRenewalDate = getNewSubscriptionRenewalDate();
const isTryingToIncreaseSubscriptionSize = (subscriptionSizeFormDraft ? Number(subscriptionSizeFormDraft[INPUT_IDS.SUBSCRIPTION_SIZE]) : 0) > (privateSubscription?.userCount ?? 0);
const canChangeSubscriptionSize = (account?.canDowngrade ?? false) || (isTryingToIncreaseSubscriptionSize && isEditing);
const formattedSubscriptionEndDate = formatSubscriptionEndDate(privateSubscription?.endDate);
const onClosePress = () => {
FormActions.clearDraftValues(ONYXKEYS.FORMS.SUBSCRIPTION_SIZE_FORM);
Navigation.goBack();
};
return (
<View style={[styles.flexGrow1]}>
{canChangeSubscriptionSize ? (
<>
<Text style={[styles.ph5, styles.pb3]}>{translate('subscription.subscriptionSize.confirmDetails')}</Text>
<MenuItemWithTopDescription
interactive={false}
description={translate('subscription.subscriptionSize.subscriptionSize')}
title={translate('subscription.subscriptionSize.activeMembers', {size: subscriptionSizeFormDraft ? subscriptionSizeFormDraft[INPUT_IDS.SUBSCRIPTION_SIZE] : 0})}
/>
<MenuItemWithTopDescription
interactive={false}
description={translate('subscription.subscriptionSize.subscriptionRenews')}
title={subscriptionRenewalDate}
/>
</>
) : (
<>
<Text style={[styles.ph5, styles.pb5, styles.textNormalThemeText]}>{translate('subscription.subscriptionSize.youCantDowngrade')}</Text>
<Text style={[styles.ph5, styles.textNormalThemeText]}>
{translate('subscription.subscriptionSize.youAlreadyCommitted', {
size: privateSubscription?.userCount ?? 0,
date: formattedSubscriptionEndDate,
})}
</Text>
</>
)}
<FixedFooter style={[styles.mtAuto]}>
{canChangeSubscriptionSize ? (
<Button
success
large
onPress={onNext}
text={translate('common.save')}
/>
) : (
<Button
success
large
onPress={onClosePress}
text={translate('common.close')}
/>
)}
</FixedFooter>
</View>
);
}
Confirmation.displayName = 'ConfirmationStep';
export default Confirmation;