Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2122,7 +2122,12 @@ const ROUTES = {
},
POLICY_ACCOUNTING_XERO_TRACKING_CATEGORIES: {
route: 'workspaces/:policyID/accounting/xero/import/tracking-categories',
getRoute: (policyID: string) => `workspaces/${policyID}/accounting/xero/import/tracking-categories` as const,
getRoute: (policyID?: string) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_XERO_TRACKING_CATEGORIES route');
}
return `workspaces/${policyID}/accounting/xero/import/tracking-categories` as const;
},
},
POLICY_ACCOUNTING_XERO_TRACKING_CATEGORIES_MAP: {
route: 'workspaces/:policyID/accounting/xero/import/tracking-categories/mapping/:categoryId/:categoryName',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import SelectionScreen from '@components/SelectionScreen';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as Xero from '@libs/actions/connections/Xero';
import * as ErrorUtils from '@libs/ErrorUtils';
import {updateXeroMappings} from '@libs/actions/connections/Xero';
import {clearXeroErrorField, enablePolicyReportFields} from '@libs/actions/Policy/Policy';
import {getLatestErrorField} from '@libs/ErrorUtils';
import Navigation from '@libs/Navigation/Navigation';
import {isControlPolicy, settingsPendingAction} from '@libs/PolicyUtils';
import type {WithPolicyProps} from '@pages/workspace/withPolicy';
import withPolicyConnections from '@pages/workspace/withPolicyConnections';
import * as Policy from '@userActions/Policy/Policy';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ROUTES from '@src/ROUTES';
Expand All @@ -29,13 +29,16 @@ function XeroMapTrackingCategoryConfigurationPage({policy}: WithPolicyProps) {
const styles = useThemeStyles();
const categoryId = params?.categoryId ?? '';
const categoryName = decodeURIComponent(params?.categoryName ?? '');
const policyID = policy?.id ?? '-1';
const policyID = policy?.id;
const {config} = policy?.connections?.xero ?? {};
const {trackingCategories} = policy?.connections?.xero?.data ?? {};
const {mappings} = policy?.connections?.xero?.config ?? {};

const currentTrackingCategory = trackingCategories?.find((category) => category.id === categoryId);
const currentTrackingCategoryValue = currentTrackingCategory ? (mappings?.[`${CONST.XERO_CONFIG.TRACKING_CATEGORY_PREFIX}${currentTrackingCategory.id}`] ?? '') : '';
const reportFieldTrackingCategories = Object.entries(mappings ?? {}).filter(
([key, value]) => key.startsWith(CONST.XERO_CONFIG.TRACKING_CATEGORY_PREFIX) && value === CONST.XERO_CONFIG.TRACKING_CATEGORY_OPTIONS.REPORT_FIELD,
Comment on lines +39 to +40

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const reportFieldTrackingCategories = Object.entries(mappings ?? {}).filter(
([key, value]) => key.startsWith(CONST.XERO_CONFIG.TRACKING_CATEGORY_PREFIX) && value === CONST.XERO_CONFIG.TRACKING_CATEGORY_OPTIONS.REPORT_FIELD,
const reportFieldTrackingCategories = Object.entries(mappings ?? {}).filter(
([key, value]) => key.startsWith(CONST.XERO_CONFIG.TRACKING_CATEGORY_PREFIX) && value === CONST.XERO_CONFIG.TRACKING_CATEGORY_OPTIONS.REPORT_FIELD

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comma looks added by mistake

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahmedGaber93 I removed the comma, run prettier and it's added again, so maybe it's conventional? Not sure about this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, It also looks like that in many places.
CC @srikarparsi if you're familiar with this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it looks like it's for style, going to merge this

);

const optionsList = useMemo(
() =>
Expand Down Expand Up @@ -69,15 +72,24 @@ function XeroMapTrackingCategoryConfigurationPage({policy}: WithPolicyProps) {
Navigation.navigate(`${backToRoute}&categoryId=${categoryId}`);
return;
}
Xero.updateXeroMappings(
if (!policyID) {
return;
}
updateXeroMappings(
policyID,
categoryId ? {[`${CONST.XERO_CONFIG.TRACKING_CATEGORY_PREFIX}${categoryId}`]: option.value} : {},
categoryId ? {[`${CONST.XERO_CONFIG.TRACKING_CATEGORY_PREFIX}${categoryId}`]: currentTrackingCategoryValue} : {},
);
if (!reportFieldTrackingCategories.length && option.value === CONST.XERO_CONFIG.TRACKING_CATEGORY_OPTIONS.REPORT_FIELD) {
enablePolicyReportFields(policyID, true);
}
if (reportFieldTrackingCategories.length === 1 && currentTrackingCategoryValue === CONST.XERO_CONFIG.TRACKING_CATEGORY_OPTIONS.REPORT_FIELD) {
enablePolicyReportFields(policyID, false);
}
}
Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_TRACKING_CATEGORIES.getRoute(policyID));
},
[categoryId, currentTrackingCategoryValue, policy, policyID],
[categoryId, currentTrackingCategoryValue, reportFieldTrackingCategories, policy, policyID],
);

return (
Expand All @@ -95,9 +107,9 @@ function XeroMapTrackingCategoryConfigurationPage({policy}: WithPolicyProps) {
headerTitleAlreadyTranslated={translate('workspace.xero.mapTrackingCategoryTo', {categoryName})}
connectionName={CONST.POLICY.CONNECTIONS.NAME.XERO}
pendingAction={settingsPendingAction([`${CONST.XERO_CONFIG.TRACKING_CATEGORY_PREFIX}${categoryId}`], config?.pendingFields)}
errors={ErrorUtils.getLatestErrorField(config ?? {}, `${CONST.XERO_CONFIG.TRACKING_CATEGORY_PREFIX}${categoryId}`)}
errors={getLatestErrorField(config ?? {}, `${CONST.XERO_CONFIG.TRACKING_CATEGORY_PREFIX}${categoryId}`)}
errorRowStyles={[styles.ph5, styles.pv3]}
onClose={() => Policy.clearXeroErrorField(policyID, `${CONST.XERO_CONFIG.TRACKING_CATEGORY_PREFIX}${categoryId}`)}
onClose={() => clearXeroErrorField(policyID, `${CONST.XERO_CONFIG.TRACKING_CATEGORY_PREFIX}${categoryId}`)}
shouldSingleExecuteRowSelect
/>
);
Expand Down