-
Notifications
You must be signed in to change notification settings - Fork 3k
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] Import tracking categories #41441
Merged
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
7938e75
feat: basic screens and navigation setup
mananjadhav 5a12e04
feat: added more config pages
mananjadhav 605912d
refactor: update the regions to page
mananjadhav 7e4f15c
refactor: update translations
mananjadhav ee9beed
Merge branch 'main' of github.com:mananjadhav/App into xero-import-ca…
mananjadhav d20d27d
fix: added fields
mananjadhav 7596517
Merge branch 'main' of github.com:mananjadhav/App into xero-import-ca…
mananjadhav 9bf90d6
feat: added tracking categories logic
mananjadhav 0872f9c
feat: create views for cost centers and region
mananjadhav 1627c56
refactor: update category fetching logic
mananjadhav f1e8dbc
feat: update mapping
mananjadhav b24e875
feat: added api for regions
mananjadhav 5c7ef82
style: lint fixes
mananjadhav 3bd9023
style: lint fixes
mananjadhav 422eb13
refactor: use connection layout
mananjadhav 01eda9e
refactor: use connection layout
mananjadhav 91c0e39
Merge branch 'main' of github.com:mananjadhav/App into xero-import-ca…
mananjadhav b012ed6
refactor: remove unused importants
mananjadhav 8c410b9
Merge branch 'main' of github.com:mananjadhav/App into xero-import-ca…
mananjadhav aed9941
fix: update routes
mananjadhav 1b58ea4
refactor: rename keys
mananjadhav d01ecf7
style: lint fixes
mananjadhav ffd6e3c
fix: typo in url
mananjadhav 2fefa85
refactor: move api call to useCallback
mananjadhav 29014fe
Merge branch 'main' of github.com:mananjadhav/App into xero-import-ca…
mananjadhav cf0adbe
refactor: prettier fix
mananjadhav 90873d0
docs: added comments
mananjadhav ff4c4a3
Merge branch 'main' of github.com:mananjadhav/App into xero-import-ca…
mananjadhav dd38d83
refactor: connection layout alignment
mananjadhav 2df2388
style: lint fix
mananjadhav bc80102
Merge branch 'main' of github.com:mananjadhav/App into xero-import-ca…
mananjadhav 67630b4
refactor: remove unnecessary code
mananjadhav dd86c65
fix: added flex1 to container
mananjadhav 0f386d4
Merge branch 'main' of github.com:mananjadhav/App into xero-import-ca…
mananjadhav b118e8c
fix: use view for map field
mananjadhav fd5ccd6
Merge branch 'main' of github.com:mananjadhav/App into xero-import-ca…
mananjadhav 22527c7
fix: added isValidOption
mananjadhav 3dc105d
refactor: prettier fix
mananjadhav 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
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.
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.
These shouldn't be hardcoded, right?
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.
@lakchote I had asked if these will be hardcoded. Thread here.
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.
These will be hardcoded yes.