Skip to content

Commit

Permalink
Merge pull request #46667 from software-mansion-labs/war-in/offline-e…
Browse files Browse the repository at this point in the history
…rror-patterns-netsuite

Offline and error patterns in NetSuite integration
  • Loading branch information
deetergp authored Sep 4, 2024
2 parents aae4c2e + e95b465 commit 312a11c
Show file tree
Hide file tree
Showing 38 changed files with 881 additions and 478 deletions.
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,7 @@ const CONST = {
},
CUSTOM_SEGMENT_FIELDS: ['segmentName', 'internalID', 'scriptID', 'mapping'],
CUSTOM_LIST_FIELDS: ['listName', 'internalID', 'transactionFieldID', 'mapping'],
CUSTOM_FORM_ID_ENABLED: 'enabled',
CUSTOM_FORM_ID_TYPE: {
REIMBURSABLE: 'reimbursable',
NON_REIMBURSABLE: 'nonReimbursable',
Expand Down
26 changes: 25 additions & 1 deletion src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import type {
Transaction,
} from '@src/types/onyx';
import type {Errors} from '@src/types/onyx/OnyxCommon';
import type {Attributes, CompanyAddress, CustomUnit, Rate, TaxRate, Unit} from '@src/types/onyx/Policy';
import type {Attributes, CompanyAddress, CustomUnit, NetSuiteCustomList, NetSuiteCustomSegment, Rate, TaxRate, Unit} from '@src/types/onyx/Policy';
import type {OnyxData} from '@src/types/onyx/Request';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {buildOptimisticPolicyCategories} from './Category';
Expand Down Expand Up @@ -604,6 +604,28 @@ function clearNetSuiteErrorField(policyID: string, fieldName: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {connections: {netsuite: {options: {config: {errorFields: {[fieldName]: null}}}}}});
}

function clearNetSuitePendingField(policyID: string, fieldName: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {connections: {netsuite: {options: {config: {pendingFields: {[fieldName]: null}}}}}});
}

function removeNetSuiteCustomFieldByIndex(allRecords: NetSuiteCustomSegment[] | NetSuiteCustomList[], policyID: string, importCustomField: string, valueIndex: number) {
// We allow multiple custom list records with the same internalID. Hence it is safe to remove by index.
const filteredRecords = allRecords.filter((_, index) => index !== Number(valueIndex));
Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {
connections: {
netsuite: {
options: {
config: {
syncOptions: {
[importCustomField]: filteredRecords,
},
},
},
},
},
});
}

function clearSageIntacctErrorField(policyID: string, fieldName: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {connections: {intacct: {config: {errorFields: {[fieldName]: null}}}}});
}
Expand Down Expand Up @@ -3944,7 +3966,9 @@ export {
clearXeroErrorField,
clearSageIntacctErrorField,
clearNetSuiteErrorField,
clearNetSuitePendingField,
clearNetSuiteAutoSyncErrorField,
removeNetSuiteCustomFieldByIndex,
clearWorkspaceReimbursementErrors,
setWorkspaceCurrencyDefault,
setForeignCurrencyDefault,
Expand Down
161 changes: 98 additions & 63 deletions src/libs/actions/connections/NetSuiteCommands.ts

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/pages/workspace/accounting/PolicyAccountingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) {
const styles = useThemeStyles();
const {translate, datetimeToRelative: getDatetimeToRelative} = useLocalize();
const {isOffline} = useNetwork();
const {canUseNetSuiteUSATax} = usePermissions();
const {windowWidth} = useWindowDimensions();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const [threeDotsMenuPosition, setThreeDotsMenuPosition] = useState<AnchorPosition>({horizontal: 0, vertical: 0});
Expand Down Expand Up @@ -227,7 +228,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) {
}
const shouldShowSynchronizationError = !!synchronizationError;
const shouldHideConfigurationOptions = isConnectionUnverified(policy, connectedIntegration);
const integrationData = getAccountingIntegrationData(connectedIntegration, policyID, translate, policy);
const integrationData = getAccountingIntegrationData(connectedIntegration, policyID, translate, policy, undefined, canUseNetSuiteUSATax);
const iconProps = integrationData?.icon ? {icon: integrationData.icon, iconType: CONST.ICON_TYPE_AVATAR} : {};

const configurationOptions = [
Expand Down Expand Up @@ -338,6 +339,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) {
isOffline,
startIntegrationFlow,
popoverAnchorRefs,
canUseNetSuiteUSATax,
]);

const otherIntegrationsItems = useMemo(() => {
Expand Down Expand Up @@ -425,6 +427,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) {
<OfflineWithFeedback
pendingAction={menuItem.pendingAction}
key={menuItem.title}
shouldDisableStrikeThrough
>
<MenuItem
brickRoadIndicator={menuItem.brickRoadIndicator}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {useMemo} from 'react';
import {View} from 'react-native';
import BlockingView from '@components/BlockingViews/BlockingView';
import * as Illustrations from '@components/Icon/Illustrations';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import RadioListItem from '@components/SelectionList/RadioListItem';
import SelectionScreen from '@components/SelectionScreen';
import type {SelectorType} from '@components/SelectionScreen';
Expand All @@ -11,6 +11,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import {updateNetSuiteSubsidiary} from '@libs/actions/connections/NetSuiteCommands';
import * as ErrorUtils from '@libs/ErrorUtils';
import Navigation from '@libs/Navigation/Navigation';
import {settingsPendingAction} from '@libs/PolicyUtils';
import withPolicyConnections from '@pages/workspace/withPolicyConnections';
import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections';
import variables from '@styles/variables';
Expand Down Expand Up @@ -70,15 +71,11 @@ function NetSuiteSubsidiarySelector({policy}: WithPolicyConnectionsProps) {

const listHeaderComponent = useMemo(
() => (
<OfflineWithFeedback
errors={ErrorUtils.getLatestErrorField(netsuiteConfig ?? {}, CONST.NETSUITE_CONFIG.SUBSIDIARY)}
errorRowStyles={[styles.ph5, styles.mt2, styles.mb4]}
onClose={() => Policy.clearNetSuiteErrorField(policyID, CONST.NETSUITE_CONFIG.SUBSIDIARY)}
>
<Text style={[styles.ph5, styles.pb5]}>{translate('workspace.netsuite.subsidiarySelectDescription')}</Text>
</OfflineWithFeedback>
<View style={[styles.pb2, styles.ph5]}>
<Text style={[styles.pb2, styles.textNormal]}>{translate('workspace.netsuite.subsidiarySelectDescription')}</Text>
</View>
),
[netsuiteConfig, styles.ph5, styles.mt2, styles.pb5, styles.mb4, translate, policyID],
[styles.pb2, styles.ph5, styles.textNormal, translate],
);

return (
Expand All @@ -96,6 +93,10 @@ function NetSuiteSubsidiarySelector({policy}: WithPolicyConnectionsProps) {
onBackButtonPress={() => Navigation.goBack()}
title="workspace.netsuite.subsidiary"
listEmptyContent={listEmptyContent}
pendingAction={settingsPendingAction([CONST.NETSUITE_CONFIG.SUBSIDIARY], netsuiteConfig?.pendingFields)}
errors={ErrorUtils.getLatestErrorField(netsuiteConfig ?? {}, CONST.NETSUITE_CONFIG.SUBSIDIARY)}
errorRowStyles={[styles.ph5, styles.pv3]}
onClose={() => Policy.clearNetSuiteErrorField(policyID, CONST.NETSUITE_CONFIG.SUBSIDIARY)}
/>
);
}
Expand Down
Loading

0 comments on commit 312a11c

Please sign in to comment.