diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 42def424c136..4ff6e6732928 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, }); } @@ -233,9 +234,10 @@ function setMoneyRequestBillable_temporaryForRefactor(transactionID, billable) { /** * @param {String} transactionID * @param {Object[]} participants + * @param {Boolean} isSplitRequest */ -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..4ab30e617c4e 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'; @@ -40,7 +39,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 +51,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 +66,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)); + }, + [transactionID, reportID], + ); const navigateBack = useCallback(() => { IOUUtils.navigateToStartMoneyRequestStep(iouRequestType, iouType, transactionID, reportID); @@ -86,7 +87,7 @@ function IOURequestStepParticipants({ > (optionsSelectorRef.current = el)} - participants={participants} + participants={transaction.isSplitRequest ? participants : []} onParticipantsAdded={addParticipant} onFinish={goToNextStep} iouType={iouType}