-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathRulesMaxExpenseAmountPage.tsx
88 lines (81 loc) · 4.01 KB
/
RulesMaxExpenseAmountPage.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
import type {StackScreenProps} from '@react-navigation/stack';
import React from 'react';
import {View} from 'react-native';
import AmountForm from '@components/AmountForm';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import Text from '@components/Text';
import useAutoFocusInput from '@hooks/useAutoFocusInput';
import useLocalize from '@hooks/useLocalize';
import usePolicy from '@hooks/usePolicy';
import useThemeStyles from '@hooks/useThemeStyles';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import Navigation from '@libs/Navigation/Navigation';
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
import * as PolicyActions from '@userActions/Policy/Policy';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
import INPUT_IDS from '@src/types/form/RulesMaxExpenseAmountForm';
type RulesMaxExpenseAmountPageProps = StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.RULES_MAX_EXPENSE_AMOUNT>;
function RulesMaxExpenseAmountPage({
route: {
params: {policyID},
},
}: RulesMaxExpenseAmountPageProps) {
const policy = usePolicy(policyID);
const {inputCallbackRef} = useAutoFocusInput();
const {translate} = useLocalize();
const styles = useThemeStyles();
const defaultValue =
policy?.maxExpenseAmount === CONST.DISABLED_MAX_EXPENSE_VALUE || !policy?.maxExpenseAmount
? ''
: CurrencyUtils.convertToFrontendAmountAsString(policy?.maxExpenseAmount, policy?.outputCurrency);
return (
<AccessOrNotFoundWrapper
policyID={policyID}
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]}
featureName={CONST.POLICY.MORE_FEATURES.ARE_RULES_ENABLED}
>
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
shouldEnableMaxHeight
testID={RulesMaxExpenseAmountPage.displayName}
>
<HeaderWithBackButton
title={translate('workspace.rules.individualExpenseRules.maxExpenseAmount')}
onBackButtonPress={() => Navigation.goBack()}
/>
<FormProvider
style={[styles.flexGrow1, styles.pt3, styles.ph5]}
formID={ONYXKEYS.FORMS.RULES_MAX_EXPENSE_AMOUNT_FORM}
onSubmit={({maxExpenseAmount}) => {
PolicyActions.setPolicyMaxExpenseAmount(policyID, maxExpenseAmount);
Navigation.setNavigationActionToMicrotaskQueue(Navigation.goBack);
}}
submitButtonText={translate('workspace.editor.save')}
enabledWhenOffline
>
<View style={styles.mb4}>
<InputWrapper
label={translate('iou.amount')}
InputComponent={AmountForm}
inputID={INPUT_IDS.MAX_EXPENSE_AMOUNT}
currency={CurrencyUtils.getCurrencySymbol(policy?.outputCurrency ?? CONST.CURRENCY.USD)}
defaultValue={defaultValue}
isCurrencyPressable={false}
ref={inputCallbackRef}
displayAsTextInput
/>
<Text style={[styles.mutedTextLabel, styles.mt2]}>{translate('workspace.rules.individualExpenseRules.maxExpenseAmountDescription')}</Text>
</View>
</FormProvider>
</ScreenWrapper>
</AccessOrNotFoundWrapper>
);
}
RulesMaxExpenseAmountPage.displayName = 'RulesMaxExpenseAmountPage';
export default RulesMaxExpenseAmountPage;