Skip to content

Commit

Permalink
add and update backTo
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardoj committed Aug 31, 2024
1 parent de211c1 commit 4317aaa
Show file tree
Hide file tree
Showing 17 changed files with 168 additions and 52 deletions.
20 changes: 10 additions & 10 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ const ROUTES = {
},
REPORT_WITH_ID_DETAILS_EXPORT: {
route: 'r/:reportID/details/export/:connectionName',
getRoute: (reportID: string, connectionName: ConnectionName) => `r/${reportID}/details/export/${connectionName}` as const,
getRoute: (reportID: string, connectionName: ConnectionName, backTo?: string) => getUrlWithBackToParam(`r/${reportID}/details/export/${connectionName}` as const, backTo),
},
REPORT_SETTINGS: {
route: 'r/:reportID/settings',
Expand Down Expand Up @@ -1045,39 +1045,39 @@ const ROUTES = {
},
TRANSACTION_DUPLICATE_REVIEW_PAGE: {
route: 'r/:threadReportID/duplicates/review',
getRoute: (threadReportID: string) => `r/${threadReportID}/duplicates/review` as const,
getRoute: (threadReportID: string, backTo?: string) => getUrlWithBackToParam(`r/${threadReportID}/duplicates/review` as const, backTo),
},
TRANSACTION_DUPLICATE_REVIEW_MERCHANT_PAGE: {
route: 'r/:threadReportID/duplicates/review/merchant',
getRoute: (threadReportID: string) => `r/${threadReportID}/duplicates/review/merchant` as const,
getRoute: (threadReportID: string, backTo?: string) => getUrlWithBackToParam(`r/${threadReportID}/duplicates/review/merchant` as const, backTo),
},
TRANSACTION_DUPLICATE_REVIEW_CATEGORY_PAGE: {
route: 'r/:threadReportID/duplicates/review/category',
getRoute: (threadReportID: string) => `r/${threadReportID}/duplicates/review/category` as const,
getRoute: (threadReportID: string, backTo?: string) => getUrlWithBackToParam(`r/${threadReportID}/duplicates/review/category` as const, backTo),
},
TRANSACTION_DUPLICATE_REVIEW_TAG_PAGE: {
route: 'r/:threadReportID/duplicates/review/tag',
getRoute: (threadReportID: string) => `r/${threadReportID}/duplicates/review/tag` as const,
getRoute: (threadReportID: string, backTo?: string) => getUrlWithBackToParam(`r/${threadReportID}/duplicates/review/tag` as const, backTo),
},
TRANSACTION_DUPLICATE_REVIEW_TAX_CODE_PAGE: {
route: 'r/:threadReportID/duplicates/review/tax-code',
getRoute: (threadReportID: string) => `r/${threadReportID}/duplicates/review/tax-code` as const,
getRoute: (threadReportID: string, backTo?: string) => getUrlWithBackToParam(`r/${threadReportID}/duplicates/review/tax-code` as const, backTo),
},
TRANSACTION_DUPLICATE_REVIEW_DESCRIPTION_PAGE: {
route: 'r/:threadReportID/duplicates/review/description',
getRoute: (threadReportID: string) => `r/${threadReportID}/duplicates/review/description` as const,
getRoute: (threadReportID: string, backTo?: string) => getUrlWithBackToParam(`r/${threadReportID}/duplicates/review/description` as const, backTo),
},
TRANSACTION_DUPLICATE_REVIEW_REIMBURSABLE_PAGE: {
route: 'r/:threadReportID/duplicates/review/reimbursable',
getRoute: (threadReportID: string) => `r/${threadReportID}/duplicates/review/reimbursable` as const,
getRoute: (threadReportID: string, backTo?: string) => getUrlWithBackToParam(`r/${threadReportID}/duplicates/review/reimbursable` as const, backTo),
},
TRANSACTION_DUPLICATE_REVIEW_BILLABLE_PAGE: {
route: 'r/:threadReportID/duplicates/review/billable',
getRoute: (threadReportID: string) => `r/${threadReportID}/duplicates/review/billable` as const,
getRoute: (threadReportID: string, backTo?: string) => getUrlWithBackToParam(`r/${threadReportID}/duplicates/review/billable` as const, backTo),
},
TRANSACTION_DUPLICATE_CONFIRMATION_PAGE: {
route: 'r/:threadReportID/duplicates/confirm',
getRoute: (threadReportID: string) => `r/${threadReportID}/duplicates/confirm` as const,
getRoute: (threadReportID: string, backTo?: string) => getUrlWithBackToParam(`r/${threadReportID}/duplicates/confirm` as const, backTo),
},
POLICY_ACCOUNTING_XERO_IMPORT: {
route: 'settings/workspaces/:policyID/accounting/xero/import',
Expand Down
4 changes: 2 additions & 2 deletions src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, shouldUseNarrow
text={translate('iou.reviewDuplicates')}
style={[styles.p0, styles.ml2]}
onPress={() => {
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_PAGE.getRoute(report.reportID));
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_PAGE.getRoute(report.reportID, Navigation.getReportRHPActiveRoute()));
}}
/>
)}
Expand All @@ -177,7 +177,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, shouldUseNarrow
text={translate('iou.reviewDuplicates')}
style={[styles.w100, styles.pr0]}
onPress={() => {
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_PAGE.getRoute(report.reportID));
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_PAGE.getRoute(report.reportID, Navigation.getReportRHPActiveRoute()));
}}
/>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,24 +283,25 @@ function MoneyRequestPreviewContent({
);

const navigateToReviewFields = () => {
const backTo = route.params.backTo;
const comparisonResult = TransactionUtils.compareDuplicateTransactionFields(reviewingTransactionID);
Transaction.setReviewDuplicatesKey({...comparisonResult.keep, duplicates, transactionID: transaction?.transactionID ?? ''});
if ('merchant' in comparisonResult.change) {
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_MERCHANT_PAGE.getRoute(route.params?.threadReportID));
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_MERCHANT_PAGE.getRoute(route.params?.threadReportID, backTo));
} else if ('category' in comparisonResult.change) {
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_CATEGORY_PAGE.getRoute(route.params?.threadReportID));
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_CATEGORY_PAGE.getRoute(route.params?.threadReportID, backTo));
} else if ('tag' in comparisonResult.change) {
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_TAG_PAGE.getRoute(route.params?.threadReportID));
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_TAG_PAGE.getRoute(route.params?.threadReportID, backTo));
} else if ('description' in comparisonResult.change) {
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_DESCRIPTION_PAGE.getRoute(route.params?.threadReportID));
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_DESCRIPTION_PAGE.getRoute(route.params?.threadReportID, backTo));
} else if ('taxCode' in comparisonResult.change) {
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_TAX_CODE_PAGE.getRoute(route.params?.threadReportID));
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_TAX_CODE_PAGE.getRoute(route.params?.threadReportID, backTo));
} else if ('billable' in comparisonResult.change) {
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_BILLABLE_PAGE.getRoute(route.params?.threadReportID));
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_BILLABLE_PAGE.getRoute(route.params?.threadReportID, backTo));
} else if ('reimbursable' in comparisonResult.change) {
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_REIMBURSABLE_PAGE.getRoute(route.params?.threadReportID));
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_REIMBURSABLE_PAGE.getRoute(route.params?.threadReportID, backTo));
} else {
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_CONFIRMATION_PAGE.getRoute(route.params?.threadReportID));
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_CONFIRMATION_PAGE.getRoute(route.params?.threadReportID, backTo));
}
};

Expand Down
60 changes: 48 additions & 12 deletions src/hooks/useReviewDuplicatesNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,86 @@ import Navigation from '@libs/Navigation/Navigation';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';

type StepName = 'description' | 'merchant' | 'category' | 'billable' | 'tag' | 'taxCode' | 'reimbursable';
type StepName = 'description' | 'merchant' | 'category' | 'billable' | 'tag' | 'taxCode' | 'reimbursable' | 'confirmation';

function useReviewDuplicatesNavigation(stepNames: string[], currentScreenName: StepName, threadReportID: string) {
const [nextScreen, setNextScreen] = useState<StepName>(currentScreenName);
function useReviewDuplicatesNavigation(stepNames: string[], currentScreenName: StepName, threadReportID: string, backTo?: string) {
const [nextScreen, setNextScreen] = useState<StepName>();
const [prevScreen, setPrevScreen] = useState<StepName>();
const [currentScreenIndex, setCurrentScreenIndex] = useState(0);
const intersection = useMemo(() => CONST.REVIEW_DUPLICATES_ORDER.filter((element) => stepNames.includes(element)), [stepNames]);

useEffect(() => {
if (currentScreenName === 'confirmation') {
setPrevScreen(intersection[intersection.length - 1] ?? '');
return;
}
const currentIndex = intersection.indexOf(currentScreenName);
const nextScreenIndex = currentIndex + 1;
const prevScreenIndex = currentIndex - 1;
setCurrentScreenIndex(currentIndex);
setNextScreen(intersection[nextScreenIndex] ?? '');
setPrevScreen(intersection[prevScreenIndex] ?? '');
}, [currentScreenName, intersection]);

const goBack = () => {
switch (prevScreen) {
case 'merchant':
Navigation.goBack(ROUTES.TRANSACTION_DUPLICATE_REVIEW_MERCHANT_PAGE.getRoute(threadReportID, backTo));
break;
case 'category':
Navigation.goBack(ROUTES.TRANSACTION_DUPLICATE_REVIEW_CATEGORY_PAGE.getRoute(threadReportID, backTo));
break;
case 'tag':
Navigation.goBack(ROUTES.TRANSACTION_DUPLICATE_REVIEW_TAG_PAGE.getRoute(threadReportID, backTo));
break;
case 'description':
Navigation.goBack(ROUTES.TRANSACTION_DUPLICATE_REVIEW_DESCRIPTION_PAGE.getRoute(threadReportID, backTo));
break;
case 'taxCode':
Navigation.goBack(ROUTES.TRANSACTION_DUPLICATE_REVIEW_TAX_CODE_PAGE.getRoute(threadReportID, backTo));
break;
case 'reimbursable':
Navigation.goBack(ROUTES.TRANSACTION_DUPLICATE_REVIEW_REIMBURSABLE_PAGE.getRoute(threadReportID, backTo));
break;
case 'billable':
Navigation.goBack(ROUTES.TRANSACTION_DUPLICATE_REVIEW_BILLABLE_PAGE.getRoute(threadReportID, backTo));
break;
default:
Navigation.goBack(ROUTES.TRANSACTION_DUPLICATE_REVIEW_PAGE.getRoute(threadReportID, backTo));
break;
}
};

const navigateToNextScreen = () => {
switch (nextScreen) {
case 'merchant':
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_MERCHANT_PAGE.getRoute(threadReportID));
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_MERCHANT_PAGE.getRoute(threadReportID, backTo));
break;
case 'category':
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_CATEGORY_PAGE.getRoute(threadReportID));
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_CATEGORY_PAGE.getRoute(threadReportID, backTo));
break;
case 'tag':
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_TAG_PAGE.getRoute(threadReportID));
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_TAG_PAGE.getRoute(threadReportID, backTo));
break;
case 'description':
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_DESCRIPTION_PAGE.getRoute(threadReportID));
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_DESCRIPTION_PAGE.getRoute(threadReportID, backTo));
break;
case 'taxCode':
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_TAX_CODE_PAGE.getRoute(threadReportID));
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_TAX_CODE_PAGE.getRoute(threadReportID, backTo));
break;
case 'reimbursable':
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_REIMBURSABLE_PAGE.getRoute(threadReportID));
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_REIMBURSABLE_PAGE.getRoute(threadReportID, backTo));
break;
case 'billable':
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_BILLABLE_PAGE.getRoute(threadReportID));
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_BILLABLE_PAGE.getRoute(threadReportID, backTo));
break;
default:
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_CONFIRMATION_PAGE.getRoute(threadReportID));
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_CONFIRMATION_PAGE.getRoute(threadReportID, backTo));
break;
}
};

return {navigateToNextScreen, currentScreenIndex};
return {navigateToNextScreen, goBack, currentScreenIndex};
}

export default useReviewDuplicatesNavigation;
9 changes: 9 additions & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ type ReportDetailsNavigatorParamList = {
reportID: string;
policyID: string;
connectionName: ConnectionName;
backTo?: Routes;
};
};

Expand Down Expand Up @@ -1086,27 +1087,35 @@ type PrivateNotesNavigatorParamList = {
type TransactionDuplicateNavigatorParamList = {
[SCREENS.TRANSACTION_DUPLICATE.REVIEW]: {
threadReportID: string;
backTo?: Routes;
};
[SCREENS.TRANSACTION_DUPLICATE.MERCHANT]: {
threadReportID: string;
backTo?: Routes;
};
[SCREENS.TRANSACTION_DUPLICATE.CATEGORY]: {
threadReportID: string;
backTo?: Routes;
};
[SCREENS.TRANSACTION_DUPLICATE.TAG]: {
threadReportID: string;
backTo?: Routes;
};
[SCREENS.TRANSACTION_DUPLICATE.DESCRIPTION]: {
threadReportID: string;
backTo?: Routes;
};
[SCREENS.TRANSACTION_DUPLICATE.TAX_CODE]: {
threadReportID: string;
backTo?: Routes;
};
[SCREENS.TRANSACTION_DUPLICATE.BILLABLE]: {
threadReportID: string;
backTo?: Routes;
};
[SCREENS.TRANSACTION_DUPLICATE.REIMBURSABLE]: {
threadReportID: string;
backTo?: Routes;
};
};

Expand Down
2 changes: 1 addition & 1 deletion src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ function ReportDetailsPage({policies, report, session, personalDetails, route}:
icon: Expensicons.Upload,
isAnonymousAction: false,
action: () => {
Navigation.navigate(ROUTES.REPORT_WITH_ID_DETAILS_EXPORT.getRoute(report?.reportID ?? '', connectedIntegration));
Navigation.navigate(ROUTES.REPORT_WITH_ID_DETAILS_EXPORT.getRoute(report?.reportID ?? '', connectedIntegration, backTo));
},
});
}
Expand Down
9 changes: 8 additions & 1 deletion src/pages/TransactionDuplicate/Confirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import ScrollView from '@components/ScrollView';
import {ShowContextMenuContext} from '@components/ShowContextMenuContext';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useReviewDuplicatesNavigation from '@hooks/useReviewDuplicatesNavigation';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import type {TransactionDuplicateNavigatorParamList} from '@libs/Navigation/types';
Expand All @@ -36,6 +37,9 @@ function Confirmation() {
const route = useRoute<RouteProp<TransactionDuplicateNavigatorParamList, typeof SCREENS.TRANSACTION_DUPLICATE.REVIEW>>();
const [reviewDuplicates, reviewDuplicatesResult] = useOnyx(ONYXKEYS.REVIEW_DUPLICATES);
const transaction = useMemo(() => TransactionUtils.buildNewTransactionAfterReviewingDuplicates(reviewDuplicates), [reviewDuplicates]);
const transactionID = TransactionUtils.getTransactionID(route.params.threadReportID ?? '');
const compareResult = TransactionUtils.compareDuplicateTransactionFields(transactionID);
const {goBack} = useReviewDuplicatesNavigation(Object.keys(compareResult.change ?? {}), 'confirmation', route.params.threadReportID, route.params.backTo);
const [report, reportResult] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${route.params.threadReportID}`);
const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transaction?.reportID}`);
const reportAction = Object.values(reportActions ?? {}).find(
Expand Down Expand Up @@ -82,7 +86,10 @@ function Confirmation() {
{({safeAreaPaddingBottomStyle}) => (
<FullPageNotFoundView shouldShow={shouldShowNotFoundPage}>
<View style={[styles.flex1, safeAreaPaddingBottomStyle]}>
<HeaderWithBackButton title={translate('iou.reviewDuplicates')} />
<HeaderWithBackButton
title={translate('iou.reviewDuplicates')}
onBackButtonPress={goBack}
/>
<ScrollView>
<View style={[styles.ph5, styles.pb8]}>
<Text
Expand Down
5 changes: 4 additions & 1 deletion src/pages/TransactionDuplicate/Review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ function TransactionDuplicateReview() {
return (
<ScreenWrapper testID={TransactionDuplicateReview.displayName}>
<FullPageNotFoundView shouldShow={transactionID === '-1'}>
<HeaderWithBackButton title={translate('iou.reviewDuplicates')} />
<HeaderWithBackButton
title={translate('iou.reviewDuplicates')}
onBackButtonPress={() => Navigation.goBack(route.params.backTo)}
/>
<View style={[styles.justifyContentCenter, styles.ph5, styles.pb3, styles.borderBottom]}>
<Button
text={translate('iou.keepAll')}
Expand Down
12 changes: 10 additions & 2 deletions src/pages/TransactionDuplicate/ReviewBillable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ function ReviewBillable() {
const transactionID = TransactionUtils.getTransactionID(route.params.threadReportID ?? '');
const compareResult = TransactionUtils.compareDuplicateTransactionFields(transactionID);
const stepNames = Object.keys(compareResult.change ?? {}).map((key, index) => (index + 1).toString());
const {currentScreenIndex, navigateToNextScreen} = useReviewDuplicatesNavigation(Object.keys(compareResult.change ?? {}), 'billable', route.params.threadReportID ?? '');
const {currentScreenIndex, goBack, navigateToNextScreen} = useReviewDuplicatesNavigation(
Object.keys(compareResult.change ?? {}),
'billable',
route.params.threadReportID ?? '',
route.params.backTo,
);
const options = useMemo(
() =>
compareResult.change.billable?.map((billable) => ({
Expand All @@ -37,7 +42,10 @@ function ReviewBillable() {

return (
<ScreenWrapper testID={ReviewBillable.displayName}>
<HeaderWithBackButton title={translate('iou.reviewDuplicates')} />
<HeaderWithBackButton
title={translate('iou.reviewDuplicates')}
onBackButtonPress={goBack}
/>
<ReviewFields<'billable'>
stepNames={stepNames}
label={translate('violations.isTransactionBillable')}
Expand Down
Loading

0 comments on commit 4317aaa

Please sign in to comment.