forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
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 Expensify#41441 from mananjadhav/xero-import-categ…
…ories [Wave Collect][Xero] Import tracking categories
- Loading branch information
Showing
17 changed files
with
350 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,37 @@ | ||
import type {OnyxEntry} from 'react-native-onyx'; | ||
import type {ConnectPolicyToAccountingIntegrationParams} from '@libs/API/parameters'; | ||
import {READ_COMMANDS} from '@libs/API/types'; | ||
import {getCommandURL} from '@libs/ApiUtils'; | ||
import CONST from '@src/CONST'; | ||
import type * as OnyxTypes from '@src/types/onyx'; | ||
import type {XeroTrackingCategory} from '@src/types/onyx/Policy'; | ||
|
||
const getXeroSetupLink = (policyID: string) => { | ||
const params: ConnectPolicyToAccountingIntegrationParams = {policyID}; | ||
const commandURL = getCommandURL({command: READ_COMMANDS.CONNECT_POLICY_TO_XERO, shouldSkipWebProxy: true}); | ||
return commandURL + new URLSearchParams(params).toString(); | ||
}; | ||
|
||
export default getXeroSetupLink; | ||
/** | ||
* Fetches the category object from the xero.data.trackingCategories based on the category name. | ||
* This is required to get Xero category object with current value stored in the xero.config.mappings | ||
* @param policy | ||
* @param key | ||
* @returns Filtered category matching the category name or undefined. | ||
*/ | ||
const getTrackingCategory = (policy: OnyxEntry<OnyxTypes.Policy>, categoryName: string): (XeroTrackingCategory & {value: string}) | undefined => { | ||
const {trackingCategories} = policy?.connections?.xero?.data ?? {}; | ||
const {mappings} = policy?.connections?.xero?.config ?? {}; | ||
|
||
const category = trackingCategories?.find((currentCategory) => currentCategory.name.toLowerCase() === categoryName.toLowerCase()); | ||
if (!category) { | ||
return undefined; | ||
} | ||
|
||
return { | ||
...category, | ||
value: mappings?.[`${CONST.XERO_CONFIG.TRACKING_CATEGORY_PREFIX}${category.id}`] ?? '', | ||
}; | ||
}; | ||
|
||
export {getXeroSetupLink, getTrackingCategory}; |
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
70 changes: 70 additions & 0 deletions
70
src/pages/workspace/accounting/xero/XeroMapCostCentersToConfigurationPage.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,70 @@ | ||
import React, {useCallback, useMemo} from 'react'; | ||
import ConnectionLayout from '@components/ConnectionLayout'; | ||
import SelectionList from '@components/SelectionList'; | ||
import RadioListItem from '@components/SelectionList/RadioListItem'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import * as Connections from '@libs/actions/connections'; | ||
import {getTrackingCategory} from '@libs/actions/connections/ConnectToXero'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import type {WithPolicyProps} from '@pages/workspace/withPolicy'; | ||
import withPolicyConnections from '@pages/workspace/withPolicyConnections'; | ||
import CONST from '@src/CONST'; | ||
import type {TranslationPaths} from '@src/languages/types'; | ||
import ROUTES from '@src/ROUTES'; | ||
|
||
function XeroMapCostCentersToConfigurationPage({policy}: WithPolicyProps) { | ||
const {translate} = useLocalize(); | ||
const styles = useThemeStyles(); | ||
|
||
const policyID = policy?.id ?? ''; | ||
|
||
const category = getTrackingCategory(policy, CONST.XERO_CONFIG.TRACKING_CATEGORY_FIELDS.COST_CENTERS); | ||
|
||
const optionsList = useMemo( | ||
() => | ||
Object.values(CONST.XERO_CONFIG.TRACKING_CATEGORY_OPTIONS).map((option) => ({ | ||
value: option, | ||
text: translate(`workspace.xero.trackingCategoriesOptions.${option.toLowerCase()}` as TranslationPaths), | ||
keyForList: option, | ||
isSelected: option.toLowerCase() === category?.value?.toLowerCase(), | ||
})), | ||
[translate, category], | ||
); | ||
|
||
const updateMapping = useCallback( | ||
(option: {value: string}) => { | ||
if (option.value !== category?.value) { | ||
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.XERO, CONST.XERO_CONFIG.MAPPINGS, { | ||
...(policy?.connections?.xero?.config?.mappings ?? {}), | ||
...(category?.id ? {[`${CONST.XERO_CONFIG.TRACKING_CATEGORY_PREFIX}${category.id}`]: option.value} : {}), | ||
}); | ||
} | ||
Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_TRACKING_CATEGORIES.getRoute(policyID)); | ||
}, | ||
[category, policyID, policy?.connections?.xero?.config?.mappings], | ||
); | ||
|
||
return ( | ||
<ConnectionLayout | ||
displayName={XeroMapCostCentersToConfigurationPage.displayName} | ||
headerTitle="workspace.xero.mapXeroCostCentersTo" | ||
title="workspace.xero.mapXeroCostCentersToDescription" | ||
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]} | ||
policyID={policyID && category?.id ? policyID : ''} | ||
featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} | ||
titleStyle={[styles.pb2, styles.ph5]} | ||
contentContainerStyle={[styles.flex1]} | ||
shouldUseScrollView={false} | ||
> | ||
<SelectionList | ||
sections={[{data: optionsList}]} | ||
ListItem={RadioListItem} | ||
onSelectRow={updateMapping} | ||
/> | ||
</ConnectionLayout> | ||
); | ||
} | ||
|
||
XeroMapCostCentersToConfigurationPage.displayName = 'XeroMapCostCentersToConfigurationPage'; | ||
export default withPolicyConnections(XeroMapCostCentersToConfigurationPage); |
69 changes: 69 additions & 0 deletions
69
src/pages/workspace/accounting/xero/XeroMapRegionsToConfigurationPage.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,69 @@ | ||
import React, {useCallback, useMemo} from 'react'; | ||
import ConnectionLayout from '@components/ConnectionLayout'; | ||
import SelectionList from '@components/SelectionList'; | ||
import RadioListItem from '@components/SelectionList/RadioListItem'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import * as Connections from '@libs/actions/connections'; | ||
import {getTrackingCategory} from '@libs/actions/connections/ConnectToXero'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import type {WithPolicyProps} from '@pages/workspace/withPolicy'; | ||
import withPolicyConnections from '@pages/workspace/withPolicyConnections'; | ||
import CONST from '@src/CONST'; | ||
import type {TranslationPaths} from '@src/languages/types'; | ||
import ROUTES from '@src/ROUTES'; | ||
|
||
function XeroMapRegionsToConfigurationPage({policy}: WithPolicyProps) { | ||
const {translate} = useLocalize(); | ||
const styles = useThemeStyles(); | ||
|
||
const policyID = policy?.id ?? ''; | ||
const category = getTrackingCategory(policy, CONST.XERO_CONFIG.TRACKING_CATEGORY_FIELDS.REGION); | ||
|
||
const optionsList = useMemo( | ||
() => | ||
Object.values(CONST.XERO_CONFIG.TRACKING_CATEGORY_OPTIONS).map((option) => ({ | ||
value: option, | ||
text: translate(`workspace.xero.trackingCategoriesOptions.${option.toLowerCase()}` as TranslationPaths), | ||
keyForList: option, | ||
isSelected: option.toLowerCase() === category?.value?.toLowerCase(), | ||
})), | ||
[translate, category], | ||
); | ||
|
||
const updateMapping = useCallback( | ||
(option: {value: string}) => { | ||
if (option.value !== category?.value) { | ||
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.XERO, CONST.XERO_CONFIG.MAPPINGS, { | ||
...(policy?.connections?.xero?.config?.mappings ?? {}), | ||
...(category?.id ? {[`${CONST.XERO_CONFIG.TRACKING_CATEGORY_PREFIX}${category.id}`]: option.value} : {}), | ||
}); | ||
} | ||
Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_TRACKING_CATEGORIES.getRoute(policyID)); | ||
}, | ||
[category, policyID, policy?.connections?.xero?.config?.mappings], | ||
); | ||
|
||
return ( | ||
<ConnectionLayout | ||
displayName={XeroMapRegionsToConfigurationPage.displayName} | ||
headerTitle="workspace.xero.mapXeroRegionsTo" | ||
title="workspace.xero.mapXeroRegionsToDescription" | ||
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]} | ||
policyID={policyID && category?.id ? policyID : ''} | ||
featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} | ||
titleStyle={[styles.pb2, styles.ph5]} | ||
contentContainerStyle={[styles.flex1]} | ||
shouldUseScrollView={false} | ||
> | ||
<SelectionList | ||
sections={[{data: optionsList}]} | ||
ListItem={RadioListItem} | ||
onSelectRow={updateMapping} | ||
/> | ||
</ConnectionLayout> | ||
); | ||
} | ||
|
||
XeroMapRegionsToConfigurationPage.displayName = 'XeroMapRegionsToConfigurationPage'; | ||
export default withPolicyConnections(XeroMapRegionsToConfigurationPage); |
Oops, something went wrong.