From 857170ef6d56a1e76a52d893d68898918f0cdd5a Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 13 Dec 2023 00:08:06 +0800 Subject: [PATCH 1/3] correctly handle a split bill request case --- src/libs/actions/IOU.js | 5 ++-- ...yForRefactorRequestParticipantsSelector.js | 23 +++++++++++-------- .../step/IOURequestStepParticipants.js | 18 ++++++++------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 42def424c136..8141c632a53d 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -141,6 +141,7 @@ function startMoneyRequest_temporaryForRefactor(reportID, isFromGlobalCreate, io reportID, transactionID: newTransactionID, isFromGlobalCreate, + isSplitRequest: false, }); } @@ -234,8 +235,8 @@ function setMoneyRequestBillable_temporaryForRefactor(transactionID, billable) { * @param {String} transactionID * @param {Object[]} participants */ -function setMoneyRequestParticipants_temporaryForRefactor(transactionID, participants) { - Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {participants}); +function setMoneyRequestParticipants_temporaryForRefactor(transactionID, participants, isSplitRequest) { + Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {participants, isSplitRequest}); } /** diff --git a/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js b/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js index 95fa64723737..58a9dfb01da3 100644 --- a/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js +++ b/src/pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector.js @@ -163,13 +163,16 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({ * @param {Object} option */ const addSingleParticipant = (option) => { - onParticipantsAdded([ - { - ..._.pick(option, 'accountID', 'login', 'isPolicyExpenseChat', 'reportID', 'searchText'), - selected: true, - }, - ]); - onFinish(); + onParticipantsAdded( + [ + { + ..._.pick(option, 'accountID', 'login', 'isPolicyExpenseChat', 'reportID', 'searchText'), + selected: true, + }, + ], + false, + ); + onFinish(iouType); }; /** @@ -208,7 +211,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({ ]; } - onParticipantsAdded(newSelectedOptions); + onParticipantsAdded(newSelectedOptions, newSelectedOptions.length !== 0); }, [participants, onParticipantsAdded], ); @@ -276,7 +279,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({ return; } - onFinish(); + onFinish(CONST.IOU.TYPE.SPLIT); }, [shouldShowSplitBillErrorMessage, onFinish]); const footerContent = ( @@ -315,7 +318,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({ boldStyle shouldShowConfirmButton={shouldShowSplitBillErrorMessage && isAllowedToSplit} confirmButtonText={translate('iou.addToSplit')} - onConfirmSelection={onFinish} + onConfirmSelection={() => onFinish(CONST.IOU.TYPE.SPLIT)} textInputLabel={translate('optionsSelector.nameEmailOrPhoneNumber')} textInputAlert={isOffline ? `${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}` : ''} safeAreaPaddingBottomStyle={safeAreaPaddingBottomStyle} diff --git a/src/pages/iou/request/step/IOURequestStepParticipants.js b/src/pages/iou/request/step/IOURequestStepParticipants.js index d07f900dbb6f..2283ea952f10 100644 --- a/src/pages/iou/request/step/IOURequestStepParticipants.js +++ b/src/pages/iou/request/step/IOURequestStepParticipants.js @@ -40,7 +40,7 @@ function IOURequestStepParticipants({ const selectedReportID = useRef(reportID); const numberOfParticipants = useRef(participants.length); const iouRequestType = TransactionUtils.getRequestType(transaction); - const headerTitle = translate(TransactionUtils.getHeaderTitleTranslationKey(transaction)); + const headerTitle = translate(transaction.isSplitRequest ? 'iou.split' : TransactionUtils.getHeaderTitleTranslationKey(transaction)); const receiptFilename = lodashGet(transaction, 'filename'); const receiptPath = lodashGet(transaction, 'receipt.source'); @@ -52,8 +52,8 @@ function IOURequestStepParticipants({ }, [receiptPath, receiptFilename, iouRequestType, iouType, transactionID, reportID]); const addParticipant = useCallback( - (val) => { - IOU.setMoneyRequestParticipants_temporaryForRefactor(transactionID, val); + (val, isSplitRequest) => { + IOU.setMoneyRequestParticipants_temporaryForRefactor(transactionID, val, isSplitRequest); numberOfParticipants.current = val.length; // When multiple participants are selected, the reportID is generated at the end of the confirmation step. @@ -67,10 +67,12 @@ function IOURequestStepParticipants({ [reportID, transactionID], ); - const goToNextStep = useCallback(() => { - const nextStepIOUType = numberOfParticipants.current === 1 ? iouType : CONST.IOU.TYPE.SPLIT; - Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(nextStepIOUType, transactionID, selectedReportID.current || reportID)); - }, [iouType, transactionID, reportID]); + const goToNextStep = useCallback( + (nextStepIOUType) => { + Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(nextStepIOUType, transactionID, selectedReportID.current || reportID)); + }, + [iouType, transactionID, reportID], + ); const navigateBack = useCallback(() => { IOUUtils.navigateToStartMoneyRequestStep(iouRequestType, iouType, transactionID, reportID); @@ -86,7 +88,7 @@ function IOURequestStepParticipants({ > (optionsSelectorRef.current = el)} - participants={participants} + participants={transaction.isSplitRequest ? participants : []} onParticipantsAdded={addParticipant} onFinish={goToNextStep} iouType={iouType} From f7ad4f9ec49d808e50340fc3fb23ffd6ce8acb41 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 13 Dec 2023 00:25:18 +0800 Subject: [PATCH 2/3] fix lint --- src/libs/actions/IOU.js | 1 + src/pages/iou/request/step/IOURequestStepParticipants.js | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 8141c632a53d..4ff6e6732928 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -234,6 +234,7 @@ function setMoneyRequestBillable_temporaryForRefactor(transactionID, billable) { /** * @param {String} transactionID * @param {Object[]} participants + * @param {Boolean} isSplitRequest */ function setMoneyRequestParticipants_temporaryForRefactor(transactionID, participants, isSplitRequest) { Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {participants, isSplitRequest}); diff --git a/src/pages/iou/request/step/IOURequestStepParticipants.js b/src/pages/iou/request/step/IOURequestStepParticipants.js index 2283ea952f10..6b243a749266 100644 --- a/src/pages/iou/request/step/IOURequestStepParticipants.js +++ b/src/pages/iou/request/step/IOURequestStepParticipants.js @@ -8,7 +8,6 @@ import Navigation from '@libs/Navigation/Navigation'; import * as TransactionUtils from '@libs/TransactionUtils'; import MoneyRequestParticipantsSelector from '@pages/iou/request/MoneyTemporaryForRefactorRequestParticipantsSelector'; import * as IOU from '@userActions/IOU'; -import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; import IOURequestStepRoutePropTypes from './IOURequestStepRoutePropTypes'; import StepScreenWrapper from './StepScreenWrapper'; From d2393354fa36bcec31c24f9b1db3d343de596384 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 13 Dec 2023 00:29:24 +0800 Subject: [PATCH 3/3] fix lint --- src/pages/iou/request/step/IOURequestStepParticipants.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepParticipants.js b/src/pages/iou/request/step/IOURequestStepParticipants.js index 6b243a749266..4ab30e617c4e 100644 --- a/src/pages/iou/request/step/IOURequestStepParticipants.js +++ b/src/pages/iou/request/step/IOURequestStepParticipants.js @@ -70,7 +70,7 @@ function IOURequestStepParticipants({ (nextStepIOUType) => { Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(nextStepIOUType, transactionID, selectedReportID.current || reportID)); }, - [iouType, transactionID, reportID], + [transactionID, reportID], ); const navigateBack = useCallback(() => {