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

[QAB] Skip confirmation for track flows #40574

Merged
merged 20 commits into from
Apr 23, 2024
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ export default {
nextStep: 'Next Steps',
finished: 'Finished',
submitAmount: ({amount}: RequestAmountParams) => `submit ${amount}`,
trackAmount: ({amount}: RequestAmountParams) => `track ${amount}`,
submittedAmount: ({formattedAmount, comment}: RequestedAmountMessageParams) => `submitted ${formattedAmount}${comment ? ` for ${comment}` : ''}`,
trackedAmount: ({formattedAmount, comment}: RequestedAmountMessageParams) => `tracking ${formattedAmount}${comment ? ` for ${comment}` : ''}`,
splitAmount: ({amount}: SplitAmountParams) => `split ${amount}`,
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ export default {
nextStep: 'Pasos Siguientes',
finished: 'Finalizado',
submitAmount: ({amount}: RequestAmountParams) => `solicitar ${amount}`,
trackAmount: ({amount}: RequestAmountParams) => `seguimiento de ${amount}`,
submittedAmount: ({formattedAmount, comment}: RequestedAmountMessageParams) => `solicitó ${formattedAmount}${comment ? ` para ${comment}` : ''}`,
trackedAmount: ({formattedAmount, comment}: RequestedAmountMessageParams) => `realizó un seguimiento de ${formattedAmount}${comment ? ` para ${comment}` : ''}`,
splitAmount: ({amount}: SplitAmountParams) => `dividir ${amount}`,
Expand Down
40 changes: 21 additions & 19 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -835,29 +835,31 @@ function buildOnyxDataForTrackExpense(
} else if (isDistanceRequest) {
newQuickAction = CONST.QUICK_ACTIONS.TRACK_DISTANCE;
}
optimisticData.push({
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE,
value: {
action: newQuickAction,
chatReportID: chatReport?.reportID,
isFirstQuickAction: isEmptyObject(quickAction),
},
});
const existingTransactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${existingTransactionThreadReportID}`] ?? null;

if (chatReport) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`,
value: {
...chatReport,
lastMessageText: iouAction.message?.[0]?.text,
lastMessageHtml: iouAction.message?.[0]?.html,
lastReadTime: DateUtils.getDBTime(),
iouReportID: iouReport?.reportID,
optimisticData.push(
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`,
value: {
...chatReport,
lastMessageText: iouAction.message?.[0]?.text,
lastMessageHtml: iouAction.message?.[0]?.html,
lastReadTime: DateUtils.getDBTime(),
iouReportID: iouReport?.reportID,
},
},
});
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE,
value: {
action: newQuickAction,
chatReportID: chatReport.reportID,
isFirstQuickAction: isEmptyObject(quickAction),
},
},
);
}

if (iouReport) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ function FloatingActionButtonAndPopover(
Task.clearOutTaskInfoAndNavigate(quickAction?.chatReportID ?? '', quickActionReport, quickAction.targetAccountID ?? 0, true);
break;
case CONST.QUICK_ACTIONS.TRACK_MANUAL:
IOU.startMoneyRequest(CONST.IOU.TYPE.TRACK, quickAction?.chatReportID ?? '', CONST.IOU.REQUEST_TYPE.MANUAL);
IOU.startMoneyRequest(CONST.IOU.TYPE.TRACK, quickAction?.chatReportID ?? '', CONST.IOU.REQUEST_TYPE.MANUAL, true);
break;
case CONST.QUICK_ACTIONS.TRACK_SCAN:
IOU.startMoneyRequest(CONST.IOU.TYPE.TRACK, quickAction?.chatReportID ?? '', CONST.IOU.REQUEST_TYPE.SCAN);
IOU.startMoneyRequest(CONST.IOU.TYPE.TRACK, quickAction?.chatReportID ?? '', CONST.IOU.REQUEST_TYPE.SCAN, true);
break;
case CONST.QUICK_ACTIONS.TRACK_DISTANCE:
IOU.startMoneyRequest(CONST.IOU.TYPE.TRACK, quickAction?.chatReportID ?? '', CONST.IOU.REQUEST_TYPE.DISTANCE);
IOU.startMoneyRequest(CONST.IOU.TYPE.TRACK, quickAction?.chatReportID ?? '', CONST.IOU.REQUEST_TYPE.DISTANCE, true);
break;
default:
}
Expand Down
24 changes: 19 additions & 5 deletions src/pages/iou/request/step/IOURequestStepAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ function IOURequestStepAmount({
// For quick button actions, we'll skip the confirmation page unless the report is archived or this is a workspace request, as
// the user will have to add a merchant.
const shouldSkipConfirmation: boolean = useMemo(() => {
if (!skipConfirmation || !report?.reportID || iouType === CONST.IOU.TYPE.TRACK) {
if (!skipConfirmation || !report?.reportID) {
return false;
}

return !(ReportUtils.isArchivedRoom(report) || ReportUtils.isPolicyExpenseChat(report));
}, [report, skipConfirmation, iouType]);
}, [report, skipConfirmation]);

useFocusEffect(
useCallback(() => {
Expand Down Expand Up @@ -186,7 +186,7 @@ function IOURequestStepAmount({
IOU.splitBillAndOpenReport({
participants,
currentUserLogin: currentUserPersonalDetails.login ?? '',
currentUserAccountID: currentUserPersonalDetails.accountID ?? 0,
currentUserAccountID: currentUserPersonalDetails.accountID,
amount: backendAmount,
comment: '',
currency,
Expand Down Expand Up @@ -215,14 +215,28 @@ function IOURequestStepAmount({
currency,
transaction?.created ?? '',
'',
currentUserPersonalDetails.login ?? '',
currentUserPersonalDetails.accountID ?? 0,
currentUserPersonalDetails.login,
currentUserPersonalDetails.accountID,
participants[0],
'',
{},
);
return;
}
if (iouType === CONST.IOU.TYPE.TRACK) {
IOU.trackExpense(
report,
backendAmount,
currency ?? 'USD',
transaction?.created ?? '',
'',
currentUserPersonalDetails.login,
currentUserPersonalDetails.accountID,
participants[0],
'',
);
return;
}
}
IOU.setMoneyRequestParticipantsFromReport(transactionID, report);
navigateToConfirmationPage();
Expand Down
40 changes: 36 additions & 4 deletions src/pages/iou/request/step/IOURequestStepDistance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,21 @@ function IOURequestStepDistance({
// For quick button actions, we'll skip the confirmation page unless the report is archived or this is a workspace
// request and the workspace requires a category or a tag
const shouldSkipConfirmation: boolean = useMemo(() => {
if (!skipConfirmation || !report?.reportID || iouType === CONST.IOU.TYPE.TRACK) {
if (!skipConfirmation || !report?.reportID) {
return false;
}

return !ReportUtils.isArchivedRoom(report) && !(ReportUtils.isPolicyExpenseChat(report) && ((policy?.requiresCategory ?? false) || (policy?.requiresTag ?? false)));
}, [report, skipConfirmation, policy, iouType]);
}, [report, skipConfirmation, policy]);
let buttonText = !isCreatingNewRequest ? translate('common.save') : translate('common.next');
if (shouldSkipConfirmation) {
buttonText = iouType === CONST.IOU.TYPE.SPLIT ? translate('iou.split') : translate('iou.submitExpense');
if (iouType === CONST.IOU.TYPE.SPLIT) {
buttonText = translate('iou.split');
} else if (iouType === CONST.IOU.TYPE.TRACK) {
buttonText = translate('iou.trackExpense');
} else {
buttonText = translate('iou.submitExpense');
}
}

useEffect(() => {
Expand Down Expand Up @@ -228,7 +234,7 @@ function IOURequestStepDistance({
IOU.splitBillAndOpenReport({
participants,
currentUserLogin: currentUserPersonalDetails.login ?? '',
currentUserAccountID: currentUserPersonalDetails.accountID ?? 0,
currentUserAccountID: currentUserPersonalDetails.accountID,
amount: 0,
comment: '',
currency: transaction?.currency ?? 'USD',
Expand All @@ -243,6 +249,31 @@ function IOURequestStepDistance({
}
IOU.setMoneyRequestPendingFields(transactionID, {waypoints: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD});
IOU.setMoneyRequestMerchant(transactionID, translate('iou.routePending'), false);
if (iouType === CONST.IOU.TYPE.TRACK) {
IOU.trackExpense(
report,
0,
transaction?.currency ?? 'USD',
transaction?.created ?? '',
translate('iou.routePending'),
Gonals marked this conversation as resolved.
Show resolved Hide resolved
currentUserPersonalDetails.login,
currentUserPersonalDetails.accountID,
participants[0],
'',
{},
'',
'',
'',
0,
false,
policy,
undefined,
undefined,
undefined,
TransactionUtils.getValidWaypoints(waypoints, true),
);
return;
}
IOU.createDistanceRequest(
report,
participants[0],
Expand Down Expand Up @@ -279,6 +310,7 @@ function IOURequestStepDistance({
translate,
navigateToParticipantPage,
navigateToConfirmationPage,
policy,
]);

const getError = () => {
Expand Down
19 changes: 17 additions & 2 deletions src/pages/iou/request/step/IOURequestStepScan/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ function IOURequestStepScan({
// For quick button actions, we'll skip the confirmation page unless the report is archived or this is a workspace
// request and the workspace requires a category or a tag
const shouldSkipConfirmation: boolean = useMemo(() => {
if (!skipConfirmation || !report?.reportID || iouType === CONST.IOU.TYPE.TRACK) {
if (!skipConfirmation || !report?.reportID) {
return false;
}

return !ReportUtils.isArchivedRoom(report) && !(ReportUtils.isPolicyExpenseChat(report) && ((policy?.requiresCategory ?? false) || (policy?.requiresTag ?? false)));
}, [report, skipConfirmation, policy, iouType]);
}, [report, skipConfirmation, policy]);

const {translate} = useLocalize();

Expand Down Expand Up @@ -245,6 +245,21 @@ function IOURequestStepScan({
});
return;
}
if (iouType === CONST.IOU.TYPE.TRACK && report) {
IOU.trackExpense(
report,
0,
transaction?.currency ?? 'USD',
transaction?.created ?? '',
'',
currentUserPersonalDetails.login,
currentUserPersonalDetails.accountID,
participants[0],
'',
receipt,
);
return;
}
IOU.requestMoney(
report,
0,
Expand Down
19 changes: 17 additions & 2 deletions src/pages/iou/request/step/IOURequestStepScan/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ function IOURequestStepScan({
// For quick button actions, we'll skip the confirmation page unless the report is archived or this is a workspace
// request and the workspace requires a category or a tag
const shouldSkipConfirmation: boolean = useMemo(() => {
if (!skipConfirmation || !report?.reportID || iouType === CONST.IOU.TYPE.TRACK) {
if (!skipConfirmation || !report?.reportID) {
return false;
}

return !ReportUtils.isArchivedRoom(report) && !(ReportUtils.isPolicyExpenseChat(report) && ((policy?.requiresCategory ?? false) || (policy?.requiresTag ?? false)));
}, [report, skipConfirmation, policy, iouType]);
}, [report, skipConfirmation, policy]);

/**
* On phones that have ultra-wide lens, react-webcam uses ultra-wide by default.
Expand Down Expand Up @@ -285,6 +285,21 @@ function IOURequestStepScan({
});
return;
}
if (iouType === CONST.IOU.TYPE.TRACK && report) {
IOU.trackExpense(
report,
0,
transaction?.currency ?? 'USD',
transaction?.created ?? '',
'',
currentUserPersonalDetails.login,
currentUserPersonalDetails.accountID,
participants[0],
'',
receipt,
);
return;
}
IOU.requestMoney(
report,
0,
Expand Down
16 changes: 14 additions & 2 deletions src/pages/iou/steps/MoneyRequestAmountForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,22 @@ function MoneyRequestAmountForm(
if (skipConfirmation) {
if (currentAmount !== '') {
const currencyAmount = CurrencyUtils.convertToDisplayString(CurrencyUtils.convertToBackendAmount(Number.parseFloat(currentAmount)), currency) ?? '';
const text = iouType === CONST.IOU.TYPE.SPLIT ? translate('iou.splitAmount', {amount: currencyAmount}) : translate('iou.submitAmount', {amount: currencyAmount});
let text = translate('iou.submitAmount', {amount: currencyAmount});
if (iouType === CONST.IOU.TYPE.SPLIT) {
text = translate('iou.splitAmount', {amount: currencyAmount});
} else if (iouType === CONST.IOU.TYPE.TRACK) {
text = translate('iou.trackAmount', {amount: currencyAmount});
}
return text[0].toUpperCase() + text.slice(1);
}
return iouType === CONST.IOU.TYPE.SPLIT ? translate('iou.splitExpense') : translate('iou.submitExpense');

if (iouType === CONST.IOU.TYPE.SPLIT) {
return translate('iou.splitExpense');
}
if (iouType === CONST.IOU.TYPE.TRACK) {
return translate('iou.trackExpense');
}
return translate('iou.submitExpense');
}
return isEditing ? translate('common.save') : translate('common.next');
}, [skipConfirmation, iouType, currentAmount, currency, isEditing, translate]);
Expand Down
Loading