-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[QBD] [Import] Customers/projects page #50879
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
Merged
lakchote
merged 6 commits into
Expensify:main
from
hoangzinh:49705-qbd-import-customers
Oct 16, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d6b1c91
Implement Customers page
hoangzinh 72171e6
Update correct action to update customers displayed as
hoangzinh eaef547
Implement displayed as for QBD customers
hoangzinh 0d0eced
Fix wrong API command
hoangzinh 22873da
Merge branch 'main' into 49705-qbd-import-customers
hoangzinh 4922667
Run prettier
hoangzinh 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
81 changes: 81 additions & 0 deletions
81
src/pages/workspace/accounting/qbd/import/QuickbooksDesktopCustomersDisplayedAsPage.tsx
This file contains hidden or 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,81 @@ | ||
import React, {useCallback} from 'react'; | ||
import RadioListItem from '@components/SelectionList/RadioListItem'; | ||
import type {ListItem} from '@components/SelectionList/types'; | ||
import SelectionScreen from '@components/SelectionScreen'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import usePermissions from '@hooks/usePermissions'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import * as QuickbooksDesktop from '@libs/actions/connections/QuickbooksDesktop'; | ||
import * as ErrorUtils from '@libs/ErrorUtils'; | ||
import * as PolicyUtils from '@libs/PolicyUtils'; | ||
import Navigation from '@navigation/Navigation'; | ||
import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections'; | ||
import withPolicyConnections from '@pages/workspace/withPolicyConnections'; | ||
import {clearQBDErrorField} from '@userActions/Policy/Policy'; | ||
import CONST from '@src/CONST'; | ||
import ROUTES from '@src/ROUTES'; | ||
|
||
type CardListItem = ListItem & { | ||
value: keyof typeof CONST.INTEGRATION_ENTITY_MAP_TYPES; | ||
}; | ||
|
||
function QuickbooksDesktopCustomersDisplayedAsPage({policy}: WithPolicyConnectionsProps) { | ||
const {translate} = useLocalize(); | ||
const {canUseNewDotQBD} = usePermissions(); | ||
const styles = useThemeStyles(); | ||
const policyID = policy?.id ?? '-1'; | ||
const qbdConfig = policy?.connections?.quickbooksDesktop?.config; | ||
|
||
const data: CardListItem[] = [ | ||
{ | ||
value: CONST.INTEGRATION_ENTITY_MAP_TYPES.TAG, | ||
text: translate('workspace.common.tags'), | ||
alternateText: translate('workspace.qbd.tagsDisplayedAsDescription'), | ||
keyForList: CONST.INTEGRATION_ENTITY_MAP_TYPES.TAG, | ||
isSelected: qbdConfig?.mappings?.customers === CONST.INTEGRATION_ENTITY_MAP_TYPES.TAG, | ||
}, | ||
{ | ||
value: CONST.INTEGRATION_ENTITY_MAP_TYPES.REPORT_FIELD, | ||
text: translate('workspace.common.reportFields'), | ||
alternateText: translate('workspace.qbd.reportFieldsDisplayedAsDescription'), | ||
keyForList: CONST.INTEGRATION_ENTITY_MAP_TYPES.REPORT_FIELD, | ||
isSelected: qbdConfig?.mappings?.customers === CONST.INTEGRATION_ENTITY_MAP_TYPES.REPORT_FIELD, | ||
}, | ||
]; | ||
|
||
const selectDisplayedAs = useCallback( | ||
(row: CardListItem) => { | ||
if (row.value !== qbdConfig?.mappings?.customers) { | ||
QuickbooksDesktop.updateQuickbooksDesktopSyncCustomers(policyID, row.value, qbdConfig?.mappings?.customers); | ||
} | ||
Navigation.goBack(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_CUSTOMERS.getRoute(policyID)); | ||
}, | ||
[qbdConfig?.mappings?.customers, policyID], | ||
); | ||
|
||
return ( | ||
<SelectionScreen | ||
policyID={policyID} | ||
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]} | ||
featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} | ||
displayName={QuickbooksDesktopCustomersDisplayedAsPage.displayName} | ||
sections={data.length ? [{data}] : []} | ||
listItem={RadioListItem} | ||
onBackButtonPress={() => Navigation.goBack(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_CUSTOMERS.getRoute(policyID))} | ||
onSelectRow={selectDisplayedAs} | ||
initiallyFocusedOptionKey={data.find((mode) => mode.isSelected)?.keyForList} | ||
title="workspace.common.displayedAs" | ||
shouldBeBlocked={!canUseNewDotQBD} // TODO: [QBD] remove it once the QBD beta is done | ||
connectionName={CONST.POLICY.CONNECTIONS.NAME.QBD} | ||
pendingAction={PolicyUtils.settingsPendingAction([CONST.QUICKBOOKS_DESKTOP_CONFIG.MAPPINGS.CUSTOMERS], qbdConfig?.pendingFields)} | ||
errors={ErrorUtils.getLatestErrorField(qbdConfig, CONST.QUICKBOOKS_DESKTOP_CONFIG.MAPPINGS.CUSTOMERS)} | ||
errorRowStyles={[styles.ph5, styles.pv3]} | ||
onClose={() => clearQBDErrorField(policyID, CONST.QUICKBOOKS_DESKTOP_CONFIG.MAPPINGS.CUSTOMERS)} | ||
shouldSingleExecuteRowSelect | ||
/> | ||
); | ||
} | ||
|
||
QuickbooksDesktopCustomersDisplayedAsPage.displayName = 'QuickbooksDesktopCustomersDisplayedAsPage'; | ||
|
||
export default withPolicyConnections(QuickbooksDesktopCustomersDisplayedAsPage); |
78 changes: 78 additions & 0 deletions
78
src/pages/workspace/accounting/qbd/import/QuickbooksDesktopCustomersPage.tsx
This file contains hidden or 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,78 @@ | ||
import React from 'react'; | ||
import ConnectionLayout from '@components/ConnectionLayout'; | ||
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; | ||
import OfflineWithFeedback from '@components/OfflineWithFeedback'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import usePermissions from '@hooks/usePermissions'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import * as QuickbooksDesktop from '@libs/actions/connections/QuickbooksDesktop'; | ||
import * as ErrorUtils from '@libs/ErrorUtils'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import * as PolicyUtils from '@libs/PolicyUtils'; | ||
import type {WithPolicyProps} from '@pages/workspace/withPolicy'; | ||
import withPolicyConnections from '@pages/workspace/withPolicyConnections'; | ||
import ToggleSettingOptionRow from '@pages/workspace/workflows/ToggleSettingsOptionRow'; | ||
import {clearQBDErrorField} from '@userActions/Policy/Policy'; | ||
import CONST from '@src/CONST'; | ||
import ROUTES from '@src/ROUTES'; | ||
|
||
function QuickbooksDesktopCustomersPage({policy}: WithPolicyProps) { | ||
const {translate} = useLocalize(); | ||
const styles = useThemeStyles(); | ||
const {canUseNewDotQBD} = usePermissions(); | ||
const policyID = policy?.id ?? '-1'; | ||
const qbdConfig = policy?.connections?.quickbooksDesktop?.config; | ||
const isSwitchOn = !!(qbdConfig?.mappings?.customers && qbdConfig.mappings.customers !== CONST.INTEGRATION_ENTITY_MAP_TYPES.NONE); | ||
const isReportFieldsSelected = qbdConfig?.mappings?.customers === CONST.INTEGRATION_ENTITY_MAP_TYPES.REPORT_FIELD; | ||
|
||
return ( | ||
<ConnectionLayout | ||
displayName={QuickbooksDesktopCustomersPage.displayName} | ||
headerTitle="workspace.qbd.customers" | ||
title="workspace.qbd.customersDescription" | ||
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]} | ||
policyID={policyID} | ||
featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} | ||
contentContainerStyle={[styles.pb2, styles.ph5]} | ||
shouldBeBlocked={!canUseNewDotQBD} // TODO: [QBD] Will be removed when release | ||
connectionName={CONST.POLICY.CONNECTIONS.NAME.QBD} | ||
onBackButtonPress={() => Navigation.goBack(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_IMPORT.getRoute(policyID))} | ||
> | ||
<ToggleSettingOptionRow | ||
title={translate('workspace.accounting.import')} | ||
switchAccessibilityLabel={translate('workspace.qbd.customers')} | ||
isActive={isSwitchOn} | ||
onToggle={() => | ||
QuickbooksDesktop.updateQuickbooksDesktopSyncCustomers( | ||
policyID, | ||
isSwitchOn ? CONST.INTEGRATION_ENTITY_MAP_TYPES.NONE : CONST.INTEGRATION_ENTITY_MAP_TYPES.TAG, | ||
qbdConfig?.mappings?.classes, | ||
) | ||
} | ||
pendingAction={PolicyUtils.settingsPendingAction([CONST.QUICKBOOKS_DESKTOP_CONFIG.MAPPINGS.CUSTOMERS], qbdConfig?.pendingFields)} | ||
errors={ErrorUtils.getLatestErrorField(qbdConfig, CONST.QUICKBOOKS_DESKTOP_CONFIG.MAPPINGS.CUSTOMERS)} | ||
onCloseError={() => clearQBDErrorField(policyID, CONST.QUICKBOOKS_DESKTOP_CONFIG.MAPPINGS.CUSTOMERS)} | ||
/> | ||
{isSwitchOn && ( | ||
<OfflineWithFeedback pendingAction={PolicyUtils.settingsPendingAction([CONST.QUICKBOOKS_DESKTOP_CONFIG.MAPPINGS.CUSTOMERS], qbdConfig?.pendingFields)}> | ||
<MenuItemWithTopDescription | ||
title={isReportFieldsSelected ? translate('workspace.common.reportFields') : translate('workspace.common.tags')} | ||
description={translate('workspace.common.displayedAs')} | ||
wrapperStyle={[styles.sectionMenuItemTopDescription, styles.mt4]} | ||
shouldShowRightIcon | ||
onPress={() => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_CUSTOMERS_DISPLAYED_AS.getRoute(policyID))} | ||
brickRoadIndicator={ | ||
PolicyUtils.areSettingsInErrorFields([CONST.QUICKBOOKS_DESKTOP_CONFIG.MAPPINGS.CUSTOMERS], qbdConfig?.errorFields) | ||
? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR | ||
: undefined | ||
} | ||
/> | ||
</OfflineWithFeedback> | ||
)} | ||
</ConnectionLayout> | ||
); | ||
} | ||
|
||
QuickbooksDesktopCustomersPage.displayName = 'QuickbooksDesktopCustomersPage'; | ||
|
||
export default withPolicyConnections(QuickbooksDesktopCustomersPage); |
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.