Skip to content

Commit

Permalink
Merge pull request #41811 from allroundexperts/feat-40823
Browse files Browse the repository at this point in the history
Include an add workspace button when selecting participants
  • Loading branch information
thienlnam authored May 14, 2024
2 parents 3ea30d6 + 8da90c7 commit 27a1e83
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 22 deletions.
42 changes: 23 additions & 19 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6573,6 +6573,27 @@ function getReportActionActorAccountID(reportAction: OnyxEntry<ReportAction>, io
}
}

function createDraftWorkspaceAndNavigateToConfirmationScreen(transactionID: string, actionName: IOUAction): void {
const isCategorizing = actionName === CONST.IOU.ACTION.CATEGORIZE;
const {expenseChatReportID, policyID, policyName} = PolicyActions.createDraftWorkspace();
IOU.setMoneyRequestParticipants(transactionID, [
{
selected: true,
accountID: 0,
isPolicyExpenseChat: true,
reportID: expenseChatReportID,
policyID,
searchText: policyName,
},
]);
const iouConfirmationPageRoute = ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(actionName, CONST.IOU.TYPE.SUBMIT, transactionID, expenseChatReportID);
if (isCategorizing) {
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CATEGORY.getRoute(actionName, CONST.IOU.TYPE.SUBMIT, transactionID, expenseChatReportID, iouConfirmationPageRoute));
} else {
Navigation.navigate(iouConfirmationPageRoute);
}
}

function createDraftTransactionAndNavigateToParticipantSelector(transactionID: string, reportID: string, actionName: IOUAction, reportActionID: string): void {
const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction);
const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] ?? ([] as ReportAction[]);
Expand Down Expand Up @@ -6608,25 +6629,7 @@ function createDraftTransactionAndNavigateToParticipantSelector(transactionID: s
return;
}

const {expenseChatReportID, policyID, policyName} = PolicyActions.createDraftWorkspace();
const isCategorizing = actionName === CONST.IOU.ACTION.CATEGORIZE;

IOU.setMoneyRequestParticipants(transactionID, [
{
selected: true,
accountID: 0,
isPolicyExpenseChat: true,
reportID: expenseChatReportID,
policyID,
searchText: policyName,
},
]);
const iouConfirmationPageRoute = ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(actionName, CONST.IOU.TYPE.SUBMIT, transactionID, expenseChatReportID);
if (isCategorizing) {
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CATEGORY.getRoute(actionName, CONST.IOU.TYPE.SUBMIT, transactionID, expenseChatReportID, iouConfirmationPageRoute));
} else {
Navigation.navigate(iouConfirmationPageRoute);
}
return createDraftWorkspaceAndNavigateToConfirmationScreen(transactionID, actionName);
}

/**
Expand Down Expand Up @@ -6927,6 +6930,7 @@ export {
shouldShowMerchantColumn,
isCurrentUserInvoiceReceiver,
isDraftReport,
createDraftWorkspaceAndNavigateToConfirmationScreen,
};

export type {
Expand Down
26 changes: 23 additions & 3 deletions src/pages/iou/request/MoneyRequestParticipantsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ function MoneyRequestParticipantsSelector({participants = [], onFinish, onPartic

return (
<>
{shouldShowReferralBanner && (
{shouldShowReferralBanner && !isCategorizeOrShareAction && (
<ReferralProgramCTA
referralContentType={referralContentType}
style={[styles.flexShrink0, !!participants.length && !shouldShowSplitBillErrorMessage && styles.mb5]}
Expand All @@ -313,7 +313,7 @@ function MoneyRequestParticipantsSelector({participants = [], onFinish, onPartic
/>
)}

{!!participants.length && (
{!!participants.length && !isCategorizeOrShareAction && (
<Button
success
text={translate('common.next')}
Expand All @@ -323,9 +323,29 @@ function MoneyRequestParticipantsSelector({participants = [], onFinish, onPartic
isDisabled={shouldShowSplitBillErrorMessage}
/>
)}
{isCategorizeOrShareAction && (
<Button
success
text={translate('workspace.new.newWorkspace')}
onPress={() => onFinish()}
pressOnEnter
large
/>
)}
</>
);
}, [handleConfirmSelection, participants.length, isDismissed, referralContentType, shouldShowSplitBillErrorMessage, styles, translate, shouldShowReferralBanner]);
}, [
handleConfirmSelection,
participants.length,
isDismissed,
referralContentType,
shouldShowSplitBillErrorMessage,
styles,
translate,
shouldShowReferralBanner,
isCategorizeOrShareAction,
onFinish,
]);

return (
<SelectionList
Expand Down
7 changes: 7 additions & 0 deletions src/pages/iou/request/step/IOURequestStepParticipants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import DistanceRequestUtils from '@libs/DistanceRequestUtils';
import * as IOUUtils from '@libs/IOUUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as ReportUtils from '@libs/ReportUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import MoneyRequestParticipantsSelector from '@pages/iou/request/MoneyRequestParticipantsSelector';
import * as IOU from '@userActions/IOU';
Expand Down Expand Up @@ -104,6 +105,7 @@ function IOURequestStepParticipants({

const goToNextStep = useCallback(() => {
const isCategorizing = action === CONST.IOU.ACTION.CATEGORIZE;
const isShareAction = action === CONST.IOU.ACTION.SHARE;

const isPolicyExpenseChat = participants?.some((participant) => participant.isPolicyExpenseChat);
if (iouType === CONST.IOU.TYPE.SPLIT && !isPolicyExpenseChat && transaction?.amount && transaction?.currency) {
Expand All @@ -113,6 +115,11 @@ function IOURequestStepParticipants({

IOU.setMoneyRequestTag(transactionID, '');
IOU.setMoneyRequestCategory(transactionID, '');
if ((isCategorizing || isShareAction) && numberOfParticipants.current === 0) {
ReportUtils.createDraftWorkspaceAndNavigateToConfirmationScreen(transactionID, action);
return;
}

const iouConfirmationPageRoute = ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(action, iouType, transactionID, selectedReportID.current || reportID);
if (isCategorizing) {
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CATEGORY.getRoute(action, iouType, transactionID, selectedReportID.current || reportID, iouConfirmationPageRoute));
Expand Down

0 comments on commit 27a1e83

Please sign in to comment.