|
1 | 1 | import React from 'react'; |
2 | | -import BlockingView from '@components/BlockingViews/BlockingView'; |
3 | | -import RadioListItem from '@components/SelectionList/ListItem/RadioListItem'; |
4 | | -import type {ListItem} from '@components/SelectionList/types'; |
5 | | -import SelectionScreen from '@components/SelectionScreen'; |
| 2 | +import type {SelectorType} from '@components/SelectionScreen'; |
6 | 3 | import useDynamicBackPath from '@hooks/useDynamicBackPath'; |
7 | | -import {useMemoizedLazyIllustrations} from '@hooks/useLazyAsset'; |
8 | | -import useLocalize from '@hooks/useLocalize'; |
9 | | -import useThemeStyles from '@hooks/useThemeStyles'; |
10 | 4 | import {updateXeroTravelInvoicingPayableAccount} from '@libs/actions/connections/Xero'; |
11 | 5 | import {getLatestErrorField} from '@libs/ErrorUtils'; |
12 | 6 | import {settingsPendingAction} from '@libs/PolicyUtils'; |
13 | 7 | import Navigation from '@navigation/Navigation'; |
| 8 | +import TravelInvoicingPayableAccountSelectPage from '@pages/workspace/accounting/common/TravelInvoicingPayableAccountSelectPage'; |
14 | 9 | import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections'; |
15 | 10 | import withPolicyConnections from '@pages/workspace/withPolicyConnections'; |
16 | | -import variables from '@styles/variables'; |
17 | 11 | import {clearXeroErrorField} from '@userActions/Policy/Policy'; |
18 | 12 | import CONST from '@src/CONST'; |
19 | 13 | import {DYNAMIC_ROUTES} from '@src/ROUTES'; |
20 | 14 |
|
21 | | -type PayableAccountListItem = ListItem & { |
22 | | - value: string; |
23 | | -}; |
24 | | - |
25 | 15 | function XeroTravelInvoicingPayableAccountSelectPage({policy}: WithPolicyConnectionsProps) { |
26 | | - const {translate} = useLocalize(); |
27 | | - const styles = useThemeStyles(); |
28 | | - const illustrations = useMemoizedLazyIllustrations(['Telescope']); |
29 | | - |
30 | 16 | const {bankAccounts} = policy?.connections?.xero?.data ?? {}; |
31 | 17 | const config = policy?.connections?.xero?.config; |
32 | 18 |
|
33 | 19 | const policyID = policy?.id ?? String(CONST.DEFAULT_NUMBER_ID); |
34 | 20 | const selectedAccountID = config?.export?.travelInvoicingPayableAccountID; |
35 | 21 | const backPath = useDynamicBackPath(DYNAMIC_ROUTES.POLICY_ACCOUNTING_XERO_TRAVEL_INVOICING_PAYABLE_ACCOUNT_SELECT.path); |
36 | | - const data: PayableAccountListItem[] = |
| 22 | + const data: Array<SelectorType<string>> = |
37 | 23 | bankAccounts?.map((account) => ({ |
38 | 24 | value: account.id, |
39 | 25 | text: account.name, |
40 | 26 | keyForList: account.id, |
41 | 27 | isSelected: account.id === selectedAccountID, |
42 | 28 | })) ?? []; |
43 | 29 |
|
44 | | - const selectAccount = (row: PayableAccountListItem) => { |
| 30 | + const selectAccount = (row: SelectorType<string>) => { |
45 | 31 | if (row.value !== selectedAccountID) { |
46 | 32 | updateXeroTravelInvoicingPayableAccount(policyID, row.value, selectedAccountID); |
47 | 33 | } |
48 | 34 | Navigation.goBack(backPath); |
49 | 35 | }; |
50 | 36 |
|
51 | | - const listEmptyContent = ( |
52 | | - <BlockingView |
53 | | - icon={illustrations.Telescope} |
54 | | - iconWidth={variables.emptyListIconWidth} |
55 | | - iconHeight={variables.emptyListIconHeight} |
56 | | - title={translate('workspace.xero.noAccountsFound')} |
57 | | - subtitle={translate('workspace.xero.noAccountsFoundDescription')} |
58 | | - containerStyle={styles.pb10} |
59 | | - /> |
60 | | - ); |
61 | | - |
62 | 37 | return ( |
63 | | - <SelectionScreen |
| 38 | + <TravelInvoicingPayableAccountSelectPage |
64 | 39 | policyID={policyID} |
65 | | - accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]} |
66 | | - featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} |
67 | 40 | displayName="XeroTravelInvoicingPayableAccountSelectPage" |
68 | | - title="workspace.common.travelInvoicingPayableAccount" |
69 | 41 | data={data} |
70 | | - listItem={RadioListItem} |
71 | | - onSelectRow={selectAccount} |
72 | | - shouldSingleExecuteRowSelect |
73 | | - initiallyFocusedOptionKey={data.find((option) => option.isSelected)?.keyForList} |
74 | | - listEmptyContent={listEmptyContent} |
75 | 42 | connectionName={CONST.POLICY.CONNECTIONS.NAME.XERO} |
76 | | - onBackButtonPress={() => Navigation.goBack(backPath)} |
| 43 | + emptyStateTitle="workspace.xero.noAccountsFound" |
| 44 | + emptyStateSubtitle="workspace.xero.noAccountsFoundDescription" |
| 45 | + onSelect={selectAccount} |
| 46 | + onBack={() => Navigation.goBack(backPath)} |
77 | 47 | pendingAction={settingsPendingAction([CONST.XERO_CONFIG.TRAVEL_INVOICING_PAYABLE_ACCOUNT], config?.pendingFields)} |
78 | 48 | errors={getLatestErrorField(config, CONST.XERO_CONFIG.TRAVEL_INVOICING_PAYABLE_ACCOUNT)} |
79 | | - errorRowStyles={[styles.ph5, styles.pv3]} |
80 | 49 | onClose={() => clearXeroErrorField(policyID, CONST.XERO_CONFIG.TRAVEL_INVOICING_PAYABLE_ACCOUNT)} |
81 | 50 | /> |
82 | 51 | ); |
|
0 commit comments