Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix money request is treated as a split bill after selecting a single participant #32931

Closed
Closed
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
6 changes: 4 additions & 2 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ function startMoneyRequest_temporaryForRefactor(reportID, isFromGlobalCreate, io
reportID,
transactionID: newTransactionID,
isFromGlobalCreate,
isSplitRequest: false,
});
}

Expand Down Expand Up @@ -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});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

/**
Expand Down Expand Up @@ -208,7 +211,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({
];
}

onParticipantsAdded(newSelectedOptions);
onParticipantsAdded(newSelectedOptions, newSelectedOptions.length !== 0);
},
[participants, onParticipantsAdded],
);
Expand Down Expand Up @@ -276,7 +279,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({
return;
}

onFinish();
onFinish(CONST.IOU.TYPE.SPLIT);
}, [shouldShowSplitBillErrorMessage, onFinish]);

const footerContent = (
Expand Down Expand Up @@ -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}
Expand Down
19 changes: 10 additions & 9 deletions src/pages/iou/request/step/IOURequestStepParticipants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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');

Expand All @@ -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.
Expand All @@ -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);
Expand All @@ -86,7 +87,7 @@ function IOURequestStepParticipants({
>
<MoneyRequestParticipantsSelector
ref={(el) => (optionsSelectorRef.current = el)}
participants={participants}
participants={transaction.isSplitRequest ? participants : []}
onParticipantsAdded={addParticipant}
onFinish={goToNextStep}
iouType={iouType}
Expand Down
Loading