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 4 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 @@ -6417,6 +6417,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 @@ -6452,25 +6473,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 @@ -6769,6 +6772,7 @@ export {
shouldShowMerchantColumn,
isCurrentUserInvoiceReceiver,
isDraftReport,
createDraftWorkspaceAndNavigateToConfirmationScreen,
};

export type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({participants, onF

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

{!!participants.length && (
{!!participants.length && !isCategorizeOrShareAction && (
<Button
success
text={translate('common.next')}
Expand All @@ -324,9 +324,29 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({participants, onF
isDisabled={shouldShowSplitBillErrorMessage}
/>
)}
{isCategorizeOrShareAction && (
<Button
success
text={translate('workspace.new.newWorkspace')}
onPress={() => onFinish()}
Copy link
Contributor

@ishpaul777 ishpaul777 May 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
onPress={() => onFinish()}
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/MoneyTemporaryForRefactorRequestParticipantsSelector';
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