-
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 #41583 from Expensify/lucien/xero-purchase-bill-date
[Wave Collect] [Xero] [Export Flow] Create the Purchase bill date select page
- Loading branch information
Showing
14 changed files
with
159 additions
and
15 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
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
73 changes: 73 additions & 0 deletions
73
src/pages/workspace/accounting/xero/export/XeroPurchaseBillDateSelectPage.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,73 @@ | ||
import React, {useCallback, useMemo} from 'react'; | ||
import {View} from 'react-native'; | ||
import type {ValueOf} from 'type-fest'; | ||
import RadioListItem from '@components/SelectionList/RadioListItem'; | ||
import type {ListItem} from '@components/SelectionList/types'; | ||
import SelectionScreen from '@components/SelectionScreen'; | ||
import type {SelectorType} 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 '@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'; | ||
|
||
type MenuListItem = ListItem & { | ||
value: ValueOf<typeof CONST.XERO_EXPORT_DATE>; | ||
}; | ||
|
||
function XeroPurchaseBillDateSelectPage({policy}: WithPolicyConnectionsProps) { | ||
const {translate} = useLocalize(); | ||
const policyID = policy?.id ?? ''; | ||
const styles = useThemeStyles(); | ||
const {billDate} = policy?.connections?.xero?.config?.export ?? {}; | ||
const data: MenuListItem[] = Object.values(CONST.XERO_EXPORT_DATE).map((dateType) => ({ | ||
value: dateType, | ||
text: translate(`workspace.xero.exportDate.values.${dateType}.label`), | ||
alternateText: translate(`workspace.xero.exportDate.values.${dateType}.description`), | ||
keyForList: dateType, | ||
isSelected: billDate === dateType, | ||
})); | ||
|
||
const headerContent = useMemo( | ||
() => ( | ||
<View> | ||
<Text style={[styles.ph5, styles.pb5]}>{translate('workspace.xero.exportDate.description')}</Text> | ||
</View> | ||
), | ||
[translate, styles.pb5, styles.ph5], | ||
); | ||
|
||
const selectExportDate = useCallback( | ||
(row: MenuListItem) => { | ||
if (row.value !== billDate) { | ||
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.XERO, CONST.XERO_CONFIG.EXPORT, {billDate: row.value}); | ||
} | ||
Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_EXPORT_PURCHASE_BILL_DATE_SELECT.getRoute(policyID)); | ||
}, | ||
[billDate, policyID], | ||
); | ||
|
||
return ( | ||
<SelectionScreen | ||
displayName={XeroPurchaseBillDateSelectPage.displayName} | ||
title="workspace.xero.exportDate.label" | ||
headerContent={headerContent} | ||
sections={[{data}]} | ||
listItem={RadioListItem} | ||
onSelectRow={(selection: SelectorType) => selectExportDate(selection as MenuListItem)} | ||
initiallyFocusedOptionKey={data.find((mode) => mode.isSelected)?.keyForList} | ||
policyID={policyID} | ||
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]} | ||
featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} | ||
onBackButtonPress={() => Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_EXPORT.getRoute(policyID))} | ||
/> | ||
); | ||
} | ||
|
||
XeroPurchaseBillDateSelectPage.displayName = 'XeroPurchaseBillDateSelectPage'; | ||
|
||
export default withPolicyConnections(XeroPurchaseBillDateSelectPage); |