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
10 changes: 9 additions & 1 deletion src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2641,7 +2641,15 @@ const CONST = {
JOBS: 'jobs',
},
},
NETSUITE_ADD_CUSTOM_LIST_STEP_NAMES: ['1', '2,', '3', '4'],
NETSUITE_ADD_CUSTOM_LIST: {
STEP_INDEX_LIST: ['1', '2', '3', '4'],
Comment thread
bernhardoj marked this conversation as resolved.
PAGE_NAME: {
NAME: 'name',
FIELD_ID: 'field-id',
MAPPING_TITLE: 'mapping-title',
CONFIRM: 'confirm',
},
},
NETSUITE_ADD_CUSTOM_SEGMENT_STEP_NAMES: ['1', '2,', '3', '4', '5', '6,'],
},

Expand Down
12 changes: 10 additions & 2 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3449,8 +3449,16 @@ const ROUTES = {
},
},
POLICY_ACCOUNTING_NETSUITE_IMPORT_CUSTOM_LIST_ADD: {
route: 'workspaces/:policyID/accounting/netsuite/import/custom-list/new',
getRoute: (policyID: string) => `workspaces/${policyID}/accounting/netsuite/import/custom-list/new` as const,
route: 'workspaces/:policyID/accounting/netsuite/import/custom-list/new/:subPage?/:action?',
getRoute: (policyID: string | undefined, subPage?: string, action?: 'edit') => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_NETSUITE_IMPORT_CUSTOM_LIST_ADD route');
}
if (!subPage) {
return `workspaces/${policyID}/accounting/netsuite/import/custom-list/new` as const;
}
return `workspaces/${policyID}/accounting/netsuite/import/custom-list/new/${subPage}${action ? `/${action}` : ''}` as const;
},
},
POLICY_ACCOUNTING_NETSUITE_IMPORT_CUSTOM_SEGMENT_ADD: {
route: 'workspaces/:policyID/accounting/netsuite/import/custom-segment/new',
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useNetSuiteImportAddCustomListForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type {FormOnyxKeys} from '@components/Form/types';
import type {OnyxFormKey} from '@src/ONYXKEYS';
import ONYXKEYS from '@src/ONYXKEYS';
import useStepFormSubmit from './useStepFormSubmit';
import type {SubStepProps} from './useSubStep/types';
import type {SubPageProps} from './useSubPage/types';

type UseNetSuiteImportAddCustomListFormSubmitParams = Pick<SubStepProps, 'onNext'> & {
type UseNetSuiteImportAddCustomListFormSubmitParams = Pick<SubPageProps, 'onNext'> & {
formId?: OnyxFormKey;
fieldIds: Array<FormOnyxKeys<typeof ONYXKEYS.FORMS.NETSUITE_CUSTOM_LIST_ADD_FORM>>;
shouldSaveDraft: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ const OPTIONS_PER_SCREEN: Partial<Record<Screen, PlatformStackNavigationOptions>
[SCREENS.MISSING_PERSONAL_DETAILS]: {
animationTypeForReplace: 'push',
},
[SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_IMPORT_CUSTOM_LIST_ADD]: {
animationTypeForReplace: 'push',
},
[SCREENS.SETTINGS.ADD_BANK_ACCOUNT]: {
animationTypeForReplace: 'push',
},
Expand Down
2 changes: 2 additions & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,8 @@ type SettingsNavigatorParamList = {
};
[SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_IMPORT_CUSTOM_LIST_ADD]: {
policyID: string;
subPage?: string;
action?: 'edit';
};
[SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_IMPORT_CUSTOM_SEGMENT_ADD]: {
policyID: string;
Expand Down
18 changes: 16 additions & 2 deletions src/libs/actions/connections/NetSuiteCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,12 +583,16 @@ function updateNetSuiteCrossSubsidiaryCustomersConfiguration(policyID: string, i
}

function updateNetSuiteCustomSegments(
policyID: string,
policyID: string | undefined,
records: NetSuiteCustomSegment[],
oldRecords: NetSuiteCustomSegment[],
modifiedSegmentID: string,
pendingAction: OnyxCommon.PendingAction,
) {
if (!policyID) {
return;
}

const onyxData = updateNetSuiteSyncOptionsOnyxData(policyID, CONST.NETSUITE_CONFIG.IMPORT_CUSTOM_FIELDS.CUSTOM_SEGMENTS, records, oldRecords, modifiedSegmentID, pendingAction);

API.write(
Expand All @@ -601,7 +605,17 @@ function updateNetSuiteCustomSegments(
);
}

function updateNetSuiteCustomLists(policyID: string, records: NetSuiteCustomList[], oldRecords: NetSuiteCustomList[], modifiedListID: string, pendingAction: OnyxCommon.PendingAction) {
function updateNetSuiteCustomLists(
policyID: string | undefined,
records: NetSuiteCustomList[],
oldRecords: NetSuiteCustomList[],
modifiedListID: string,
pendingAction: OnyxCommon.PendingAction,
) {
if (!policyID) {
return;
}

const onyxData = updateNetSuiteSyncOptionsOnyxData(policyID, CONST.NETSUITE_CONFIG.IMPORT_CUSTOM_FIELDS.CUSTOM_LISTS, records, oldRecords, modifiedListID, pendingAction);
API.write(
WRITE_COMMANDS.UPDATE_NETSUITE_CUSTOM_LISTS,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, {useCallback, useMemo, useRef} from 'react';
import type {ForwardedRef} from 'react';
import {InteractionManager, View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import ConnectionLayout from '@components/ConnectionLayout';
import type {FormRef} from '@components/Form/types';
import InteractiveStepSubHeader from '@components/InteractiveStepSubHeader';
import type {InteractiveStepSubHeaderHandle} from '@components/InteractiveStepSubHeader';
import useSubStep from '@hooks/useSubStep';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import InteractiveStepSubPageHeader from '@components/InteractiveStepSubPageHeader';
import ScreenWrapper from '@components/ScreenWrapper';
import useSubPage from '@hooks/useSubPage';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import type {CustomFieldSubStepWithPolicy} from '@pages/workspace/accounting/netsuite/types';
import type {CustomFieldSubPageWithPolicy} from '@pages/workspace/accounting/netsuite/types';
import {updateNetSuiteCustomLists} from '@userActions/connections/NetSuiteCommands';
import {clearDraftValues} from '@userActions/FormActions';
import CONST from '@src/CONST';
Expand All @@ -19,22 +19,27 @@ import INPUT_IDS from '@src/types/form/NetSuiteCustomFieldForm';
import type {NetSuiteCustomFieldForm} from '@src/types/form/NetSuiteCustomFieldForm';
import type {Policy} from '@src/types/onyx';
import {getCustomListInitialSubstep, getSubstepValues} from './customUtils';
import ChooseCustomListStep from './substeps/ChooseCustomListStep';
import ConfirmCustomListStep from './substeps/ConfirmCustomListStep';
import CustomListMappingStep from './substeps/CustomListMappingStep';
import TransactionFieldIDStep from './substeps/TransactionFieldIDStep';
import ChooseCustomListStep from './subPages/ChooseCustomListStep';
import ConfirmCustomListStep from './subPages/ConfirmCustomListStep';
import CustomListMappingStep from './subPages/CustomListMappingStep';
import TransactionFieldIDStep from './subPages/TransactionFieldIDStep';

type NetSuiteImportAddCustomListContentProps = {
policy: OnyxEntry<Policy>;
policyIDParam: string | undefined;
draftValues: OnyxEntry<NetSuiteCustomFieldForm>;
};

const formSteps = [ChooseCustomListStep, TransactionFieldIDStep, CustomListMappingStep, ConfirmCustomListStep];
const pages = [
{pageName: CONST.NETSUITE_CONFIG.NETSUITE_ADD_CUSTOM_LIST.PAGE_NAME.NAME, component: ChooseCustomListStep},
{pageName: CONST.NETSUITE_CONFIG.NETSUITE_ADD_CUSTOM_LIST.PAGE_NAME.FIELD_ID, component: TransactionFieldIDStep},
{pageName: CONST.NETSUITE_CONFIG.NETSUITE_ADD_CUSTOM_LIST.PAGE_NAME.MAPPING_TITLE, component: CustomListMappingStep},
{pageName: CONST.NETSUITE_CONFIG.NETSUITE_ADD_CUSTOM_LIST.PAGE_NAME.CONFIRM, component: ConfirmCustomListStep},
];

function NetSuiteImportAddCustomListContent({policy, draftValues}: NetSuiteImportAddCustomListContentProps) {
const policyID = policy?.id ?? '-1';
function NetSuiteImportAddCustomListContent({policy, draftValues, policyIDParam}: NetSuiteImportAddCustomListContentProps) {
const policyID = policy?.id;
const styles = useThemeStyles();
const ref: ForwardedRef<InteractiveStepSubHeaderHandle> = useRef(null);
const formRef = useRef<FormRef | null>(null);

const values = useMemo(() => getSubstepValues(draftValues), [draftValues]);
Expand Down Expand Up @@ -66,45 +71,48 @@ function NetSuiteImportAddCustomListContent({policy, draftValues}: NetSuiteImpor
});
}, [values, customLists, policyID]);

const {
componentToRender: SubStep,
isEditing,
nextScreen,
prevScreen,
screenIndex,
moveTo,
goToTheLastStep,
} = useSubStep<CustomFieldSubStepWithPolicy>({
bodyContent: formSteps,
const {CurrentPage, isEditing, nextPage, prevPage, pageIndex, moveTo, isRedirecting} = useSubPage<CustomFieldSubPageWithPolicy>({
pages,
startFrom,
onFinished: handleFinishStep,
buildRoute: (pageName, action) => ROUTES.POLICY_ACCOUNTING_NETSUITE_IMPORT_CUSTOM_LIST_ADD.getRoute(policyIDParam, pageName, action),
});

const goBackToConfirmStep = () => {
Comment thread
arosiclair marked this conversation as resolved.
Navigation.goBack(ROUTES.POLICY_ACCOUNTING_NETSUITE_IMPORT_CUSTOM_LIST_ADD.getRoute(policyIDParam, CONST.NETSUITE_CONFIG.NETSUITE_ADD_CUSTOM_LIST.PAGE_NAME.CONFIRM));
};

const handleBackButtonPress = () => {
if (isEditing) {
goToTheLastStep();
goBackToConfirmStep();
return;
}

// Clicking back on the first screen should go back to listing
if (screenIndex === CONST.NETSUITE_CUSTOM_FIELD_SUBSTEP_INDEXES.CUSTOM_LISTS.CUSTOM_LIST_PICKER) {
if (pageIndex === CONST.NETSUITE_CUSTOM_FIELD_SUBSTEP_INDEXES.CUSTOM_LISTS.CUSTOM_LIST_PICKER) {
clearDraftValues(ONYXKEYS.FORMS.NETSUITE_CUSTOM_LIST_ADD_FORM);
Navigation.goBack(ROUTES.POLICY_ACCOUNTING_NETSUITE_IMPORT_CUSTOM_FIELD_MAPPING.getRoute(policyID, CONST.NETSUITE_CONFIG.IMPORT_CUSTOM_FIELDS.CUSTOM_LISTS));
return;
}
ref.current?.movePrevious();
formRef.current?.resetErrors();
prevScreen();
prevPage();
};

const handleNextScreen = useCallback(() => {
if (isEditing) {
goToTheLastStep();
goBackToConfirmStep();
return;
}
ref.current?.moveNext();
nextScreen();
}, [goToTheLastStep, isEditing, nextScreen]);
nextPage();
}, [isEditing, goBackToConfirmStep, nextPage]);

if (isRedirecting) {
return (
<ScreenWrapper testID="NetSuiteImportAddCustomListContent">
<FullScreenLoadingIndicator />
</ScreenWrapper>
);
}

return (
<ConnectionLayout
Expand All @@ -120,19 +128,16 @@ function NetSuiteImportAddCustomListContent({policy, draftValues}: NetSuiteImpor
shouldUseScrollView={false}
>
<View style={[styles.ph5, styles.mb3, styles.mt3, {height: CONST.NETSUITE_FORM_STEPS_HEADER_HEIGHT}]}>
<InteractiveStepSubHeader
ref={ref}
startStepIndex={startFrom}
stepNames={CONST.NETSUITE_CONFIG.NETSUITE_ADD_CUSTOM_LIST_STEP_NAMES}
<InteractiveStepSubPageHeader
currentStepIndex={pageIndex}
stepNames={CONST.NETSUITE_CONFIG.NETSUITE_ADD_CUSTOM_LIST.STEP_INDEX_LIST}
/>
</View>
<View style={[styles.flexGrow1, styles.mt3]}>
<SubStep
<CurrentPage
isEditing={isEditing}
onNext={handleNextScreen}
onMove={moveTo}
screenIndex={screenIndex}
policyID={policyID}
policy={policy}
importCustomField={CONST.NETSUITE_CONFIG.IMPORT_CUSTOM_FIELDS.CUSTOM_LISTS}
netSuiteCustomFieldFormValues={values}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
import NetSuiteImportAddCustomListContent from './NetSuiteImportAddCustomListContent';

function NetSuiteImportAddCustomListPage({policy}: WithPolicyConnectionsProps) {
function NetSuiteImportAddCustomListPage({policy, route}: WithPolicyConnectionsProps) {
const [draftValues, draftValuesMetadata] = useOnyx(ONYXKEYS.FORMS.NETSUITE_CUSTOM_LIST_ADD_FORM_DRAFT);
const isLoading = isLoadingOnyxValue(draftValuesMetadata);

Expand All @@ -18,6 +18,7 @@ function NetSuiteImportAddCustomListPage({policy}: WithPolicyConnectionsProps) {
return (
<NetSuiteImportAddCustomListContent
policy={policy}
policyIDParam={route.params.policyID}
draftValues={draftValues}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import INPUT_IDS from '@src/types/form/NetSuiteCustomFieldForm';
import type {NetSuiteCustomFieldForm} from '@src/types/form/NetSuiteCustomFieldForm';
import type {Policy} from '@src/types/onyx';
import {getCustomSegmentInitialSubstep, getSubstepValues} from './customUtils';
import ChooseSegmentTypeStep from './substeps/ChooseSegmentTypeStep';
import ConfirmCustomSegmentStep from './substeps/ConfirmCustomSegmentList';
import CustomSegmentInternalIdStep from './substeps/CustomSegmentInternalIdStep';
import CustomSegmentMappingStep from './substeps/CustomSegmentMappingStep';
import CustomSegmentNameStep from './substeps/CustomSegmentNameStep';
import CustomSegmentScriptIdStep from './substeps/CustomSegmentScriptIdStep';
import ChooseSegmentTypeStep from './subPages/ChooseSegmentTypeStep';
import ConfirmCustomSegmentStep from './subPages/ConfirmCustomSegmentList';
import CustomSegmentInternalIdStep from './subPages/CustomSegmentInternalIdStep';
import CustomSegmentMappingStep from './subPages/CustomSegmentMappingStep';
import CustomSegmentNameStep from './subPages/CustomSegmentNameStep';
import CustomSegmentScriptIdStep from './subPages/CustomSegmentScriptIdStep';

type NetSuiteImportAddCustomSegmentContentProps = {
policy: OnyxEntry<Policy>;
Expand All @@ -36,7 +36,7 @@ type NetSuiteImportAddCustomSegmentContentProps = {
const formSteps = [ChooseSegmentTypeStep, CustomSegmentNameStep, CustomSegmentInternalIdStep, CustomSegmentScriptIdStep, CustomSegmentMappingStep, ConfirmCustomSegmentStep];

function NetSuiteImportAddCustomSegmentContent({policy, draftValues}: NetSuiteImportAddCustomSegmentContentProps) {
const policyID = policy?.id ?? '-1';
const policyID = policy?.id;
const styles = useThemeStyles();
const ref: ForwardedRef<InteractiveStepSubHeaderHandle> = useRef(null);
const formRef = useRef<FormRef | null>(null);
Expand Down Expand Up @@ -132,7 +132,6 @@ function NetSuiteImportAddCustomSegmentContent({policy, draftValues}: NetSuiteIm
onNext={handleNextScreen}
onMove={moveTo}
screenIndex={screenIndex}
policyID={policyID}
policy={policy}
importCustomField={CONST.NETSUITE_CONFIG.IMPORT_CUSTOM_FIELDS.CUSTOM_SEGMENTS}
customSegmentType={customSegmentType}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import useNetSuiteImportAddCustomListFormSubmit from '@hooks/useNetSuiteImportAd
import useThemeStyles from '@hooks/useThemeStyles';
import {getFieldRequiredErrors} from '@libs/ValidationUtils';
import NetSuiteCustomListPicker from '@pages/workspace/accounting/netsuite/import/NetSuiteImportCustomFieldNew/NetSuiteCustomListPicker';
import type {CustomFieldSubStepWithPolicy} from '@pages/workspace/accounting/netsuite/types';
import type {CustomFieldSubPageWithPolicy} from '@pages/workspace/accounting/netsuite/types';
import ONYXKEYS from '@src/ONYXKEYS';
import INPUT_IDS from '@src/types/form/NetSuiteCustomFieldForm';

const STEP_FIELDS = [INPUT_IDS.LIST_NAME, INPUT_IDS.INTERNAL_ID];

function ChooseCustomListStep({policy, onNext, isEditing, netSuiteCustomFieldFormValues}: CustomFieldSubStepWithPolicy) {
function ChooseCustomListStep({policy, onNext, isEditing, netSuiteCustomFieldFormValues}: CustomFieldSubPageWithPolicy) {
const styles = useThemeStyles();
const {translate} = useLocalize();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useNetSuiteImportAddCustomSegmentFormSubmit from '@hooks/useNetSuiteImportAddCustomSegmentForm';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ValidationUtils from '@libs/ValidationUtils';
import {isRequiredFulfilled} from '@libs/ValidationUtils';
import NetSuiteCustomSegmentMappingPicker from '@pages/workspace/accounting/netsuite/import/NetSuiteImportCustomFieldNew/NetSuiteCustomSegmentMappingPicker';
import type {CustomFieldSubStepWithPolicy} from '@pages/workspace/accounting/netsuite/types';
import type CONST from '@src/CONST';
Expand All @@ -24,7 +24,7 @@ function ChooseSegmentTypeStep({onNext, setCustomSegmentType, isEditing, netSuit
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.NETSUITE_CUSTOM_SEGMENT_ADD_FORM>): FormInputErrors<typeof ONYXKEYS.FORMS.NETSUITE_CUSTOM_SEGMENT_ADD_FORM> => {
const errors: FormInputErrors<typeof ONYXKEYS.FORMS.NETSUITE_CUSTOM_SEGMENT_ADD_FORM> = {};

if (!ValidationUtils.isRequiredFulfilled(values[INPUT_IDS.SEGMENT_TYPE])) {
if (!isRequiredFulfilled(values[INPUT_IDS.SEGMENT_TYPE])) {
errors[INPUT_IDS.SEGMENT_TYPE] = translate('common.error.pleaseSelectOne');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import useBottomSafeSafeAreaPaddingStyle from '@hooks/useBottomSafeSafeAreaPaddi
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
import type {CustomFieldSubStepWithPolicy} from '@pages/workspace/accounting/netsuite/types';
import type {CustomFieldSubPageWithPolicy} from '@pages/workspace/accounting/netsuite/types';
import type {TranslationPaths} from '@src/languages/types';
import INPUT_IDS from '@src/types/form/NetSuiteCustomFieldForm';

function ConfirmCustomListStep({onMove, netSuiteCustomFieldFormValues: values, onNext}: CustomFieldSubStepWithPolicy) {
function ConfirmCustomListStep({onMove, netSuiteCustomFieldFormValues: values, onNext}: CustomFieldSubPageWithPolicy) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {isOffline} = useNetwork();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useNetSuiteImportAddCustomListFormSubmit from '@hooks/useNetSuiteImportAddCustomListForm';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ValidationUtils from '@libs/ValidationUtils';
import {isRequiredFulfilled} from '@libs/ValidationUtils';
import NetSuiteCustomFieldMappingPicker from '@pages/workspace/accounting/netsuite/import/NetSuiteImportCustomFieldNew/NetSuiteCustomFieldMappingPicker';
import type {CustomFieldSubStepWithPolicy} from '@pages/workspace/accounting/netsuite/types';
import type {CustomFieldSubPageWithPolicy} from '@pages/workspace/accounting/netsuite/types';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import INPUT_IDS from '@src/types/form/NetSuiteCustomFieldForm';

const STEP_FIELDS = [INPUT_IDS.MAPPING];

function CustomListMappingStep({importCustomField, customSegmentType, onNext, isEditing, netSuiteCustomFieldFormValues}: CustomFieldSubStepWithPolicy) {
function CustomListMappingStep({importCustomField, customSegmentType, onNext, isEditing, netSuiteCustomFieldFormValues}: CustomFieldSubPageWithPolicy) {
const styles = useThemeStyles();
const {translate} = useLocalize();

const validate = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.NETSUITE_CUSTOM_LIST_ADD_FORM>): FormInputErrors<typeof ONYXKEYS.FORMS.NETSUITE_CUSTOM_LIST_ADD_FORM> => {
const errors: FormInputErrors<typeof ONYXKEYS.FORMS.NETSUITE_CUSTOM_LIST_ADD_FORM> = {};

if (!ValidationUtils.isRequiredFulfilled(values[INPUT_IDS.MAPPING])) {
if (!isRequiredFulfilled(values[INPUT_IDS.MAPPING])) {
errors[INPUT_IDS.MAPPING] = translate('common.error.pleaseSelectOne');
}

Expand Down
Loading
Loading