-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Wave Collect] [Xero] [Export Flow] Create the Preferred exporter select page #41641
Merged
lakchote
merged 12 commits into
Expensify:xero-merge-freeze
from
hungvu193:feat/preferred-exporter-select-page
May 9, 2024
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
62e5472
merge with rus
hungvu193 cbecce7
xero preferred export select page
hungvu193 4c1546b
add PreferredExportedConfiguration screen
hungvu193 e53f3e2
update pendingFields
hungvu193 b32fd3d
update translation
hungvu193 09ead33
sync with latest parent branch
hungvu193 3e4d740
Merge remote-tracking branch 'origin/main' into feat/preferred-export…
hungvu193 fe34369
Merge remote-tracking branch 'origin/main' into feat/preferred-export…
hungvu193 f992572
remove unused code
hungvu193 ccda26a
resolve conflict
hungvu193 2fbf7c7
resolve conflicts
hungvu193 1822e23
update prettier
hungvu193 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
93 changes: 93 additions & 0 deletions
93
src/pages/workspace/accounting/xero/export/XeroPreferredExporterSelectPage.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,93 @@ | ||
import isEmpty from 'lodash/isEmpty'; | ||
import React, {useCallback, useMemo} from 'react'; | ||
import {View} from 'react-native'; | ||
import RadioListItem from '@components/SelectionList/RadioListItem'; | ||
import type {ListItem} from '@components/SelectionList/types'; | ||
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 {getAdminEmployees} from '@libs/PolicyUtils'; | ||
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 CardListItem = ListItem & { | ||
value: string; | ||
}; | ||
|
||
function XeroPreferredExporterSelectPage({policy}: WithPolicyConnectionsProps) { | ||
const {export: exportConfiguration} = policy?.connections?.xero?.config ?? {}; | ||
const {translate} = useLocalize(); | ||
const styles = useThemeStyles(); | ||
const policyOwner = policy?.owner ?? ''; | ||
const exporters = getAdminEmployees(policy); | ||
|
||
const policyID = policy?.id ?? ''; | ||
const data: CardListItem[] = useMemo(() => { | ||
if (!isEmpty(policyOwner) && isEmpty(exporters)) { | ||
return [ | ||
{ | ||
value: policyOwner, | ||
text: policyOwner, | ||
keyForList: policyOwner, | ||
isSelected: true, | ||
}, | ||
]; | ||
} | ||
return exporters?.reduce<CardListItem[]>((vendors, vendor) => { | ||
hungvu193 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (vendor.email) { | ||
vendors.push({ | ||
value: vendor.email, | ||
text: vendor.email, | ||
keyForList: vendor.email, | ||
isSelected: exportConfiguration?.exporter === vendor.email, | ||
}); | ||
} | ||
return vendors; | ||
}, []); | ||
}, [exportConfiguration, exporters, policyOwner]); | ||
|
||
const selectExporter = useCallback( | ||
(row: CardListItem) => { | ||
if (row.value !== exportConfiguration?.exporter) { | ||
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.XERO, CONST.XERO_CONFIG.EXPORT, {exporter: row.value}); | ||
} | ||
Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_EXPORT.getRoute(policyID)); | ||
}, | ||
[policyID, exportConfiguration], | ||
); | ||
|
||
const headerContent = useMemo( | ||
() => ( | ||
<View style={[styles.pb2, styles.ph5]}> | ||
<Text style={[styles.pb2, styles.textNormal]}>{translate('workspace.xero.exportPreferredExporterNote')}</Text> | ||
<Text style={[styles.pb5, styles.textNormal]}>{translate('workspace.xero.exportPreferredExporterSubNote')}</Text> | ||
</View> | ||
), | ||
[translate, styles.pb2, styles.ph5, styles.pb5, styles.textNormal], | ||
); | ||
|
||
return ( | ||
<SelectionScreen | ||
policyID={policyID} | ||
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]} | ||
featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} | ||
displayName={XeroPreferredExporterSelectPage.displayName} | ||
sections={[{data}]} | ||
listItem={RadioListItem} | ||
headerContent={headerContent} | ||
onSelectRow={selectExporter} | ||
initiallyFocusedOptionKey={data.find((mode) => mode.isSelected)?.keyForList} | ||
onBackButtonPress={() => Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_EXPORT.getRoute(policyID))} | ||
title="workspace.xero.preferredExporter" | ||
/> | ||
); | ||
} | ||
|
||
XeroPreferredExporterSelectPage.displayName = 'XeroPreferredExporterSelectPage'; | ||
|
||
export default withPolicyConnections(XeroPreferredExporterSelectPage); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hungvu193 @lakchote I am not sure how we're handling the pendingFields here. I can see it's tagged as
policy.pendingFields.xeroConfigPreferredExporter
in the document but I don't see it being used. Neither here nor in @lakchote's PR for Bill selector.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I didn't find any usage of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it shouldn't be
xeroConfigPreferredExporter
or anything like that. I previously wrote that before the implementation and I was wrong.The correct way to do this is would be here to use
pendingFields?.export
for the pending action.