-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41690 from mananjadhav/xero-advanced-bill-payment…
…-account [Wave Collect][Xero][Advanced] Bill Payment Account Selector
- Loading branch information
Showing
11 changed files
with
106 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/pages/workspace/accounting/xero/advanced/XeroBillPaymentAccountSelectorPage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React, {useCallback, useMemo} from 'react'; | ||
import {View} from 'react-native'; | ||
import RadioListItem from '@components/SelectionList/RadioListItem'; | ||
import type {SelectorType} from '@components/SelectionScreen'; | ||
import SelectionScreen from '@components/SelectionScreen'; | ||
import Text from '@components/Text'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import * as Connections from '@libs/actions/connections'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections'; | ||
import withPolicyConnections from '@pages/workspace/withPolicyConnections'; | ||
import CONST from '@src/CONST'; | ||
import ROUTES from '@src/ROUTES'; | ||
|
||
function XeroBillPaymentAccountSelectorPage({policy}: WithPolicyConnectionsProps) { | ||
const styles = useThemeStyles(); | ||
const {translate} = useLocalize(); | ||
|
||
const policyID = policy?.id ?? ''; | ||
const {bankAccounts} = policy?.connections?.xero?.data ?? {}; | ||
|
||
const {reimbursementAccountID, syncReimbursedReports} = policy?.connections?.xero?.config.sync ?? {}; | ||
|
||
const xeroSelectorOptions = useMemo<SelectorType[]>( | ||
() => | ||
(bankAccounts ?? []).map(({id, name}) => ({ | ||
value: id, | ||
text: name, | ||
keyForList: id, | ||
isSelected: reimbursementAccountID === id, | ||
})), | ||
[reimbursementAccountID, bankAccounts], | ||
); | ||
|
||
const listHeaderComponent = useMemo( | ||
() => ( | ||
<View style={[styles.pb2, styles.ph5]}> | ||
<Text style={[styles.pb5, styles.textNormal]}>{translate('workspace.xero.advancedConfig.xeroBillPaymentAccountDescription')}</Text> | ||
</View> | ||
), | ||
[translate, styles.pb2, styles.ph5, styles.pb5, styles.textNormal], | ||
); | ||
|
||
const initiallyFocusedOptionKey = useMemo(() => xeroSelectorOptions?.find((mode) => mode.isSelected)?.keyForList, [xeroSelectorOptions]); | ||
|
||
const updateMode = useCallback( | ||
({value}: SelectorType) => { | ||
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.XERO, CONST.XERO_CONFIG.SYNC, { | ||
reimbursementAccountID: value, | ||
}); | ||
Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_ADVANCED.getRoute(policyID)); | ||
}, | ||
[policyID], | ||
); | ||
|
||
return ( | ||
<SelectionScreen | ||
policyID={policyID} | ||
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]} | ||
featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} | ||
displayName={XeroBillPaymentAccountSelectorPage.displayName} | ||
sections={[{data: xeroSelectorOptions}]} | ||
listItem={RadioListItem} | ||
shouldBeBlocked={!syncReimbursedReports} | ||
onSelectRow={updateMode} | ||
initiallyFocusedOptionKey={initiallyFocusedOptionKey} | ||
headerContent={listHeaderComponent} | ||
onBackButtonPress={() => Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_ADVANCED.getRoute(policyID))} | ||
title="workspace.xero.advancedConfig.xeroBillPaymentAccount" | ||
/> | ||
); | ||
} | ||
|
||
XeroBillPaymentAccountSelectorPage.displayName = 'XeroBillPaymentAccountSelectorPage'; | ||
|
||
export default withPolicyConnections(XeroBillPaymentAccountSelectorPage); |