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

Include an add workspace button when selecting participants #41811

Merged
merged 5 commits into from
May 14, 2024
Merged
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
42 changes: 23 additions & 19 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6570,6 +6570,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 @@ -6605,25 +6626,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 @@ -6924,6 +6927,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
Loading