Skip to content

Commit 12e0941

Browse files
authored
Merge pull request #53529 from huult/53182-submit-button-jump-confirmation-page
53182 submit button jump confirmation page
2 parents ad99c20 + 6704403 commit 12e0941

File tree

4 files changed

+85
-12
lines changed

4 files changed

+85
-12
lines changed

src/libs/DistanceRequestUtils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,15 @@ function convertToDistanceInMeters(distance: number, unit: Unit): number {
289289
/**
290290
* Returns custom unit rate ID for the distance transaction
291291
*/
292-
function getCustomUnitRateID(reportID: string) {
292+
function getCustomUnitRateID(reportID?: string) {
293+
let customUnitRateID: string = CONST.CUSTOM_UNITS.FAKE_P2P_ID;
294+
295+
if (!reportID) {
296+
return customUnitRateID;
297+
}
293298
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
294299
const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`];
295300
const policy = PolicyUtils.getPolicy(report?.policyID ?? parentReport?.policyID);
296-
let customUnitRateID: string = CONST.CUSTOM_UNITS.FAKE_P2P_ID;
297301

298302
if (isEmptyObject(policy)) {
299303
return customUnitRateID;

src/pages/iou/request/step/IOURequestStepParticipants.tsx

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import FormHelpMessage from '@components/FormHelpMessage';
55
import useLocalize from '@hooks/useLocalize';
66
import useThemeStyles from '@hooks/useThemeStyles';
77
import {READ_COMMANDS} from '@libs/API/types';
8+
import * as Browser from '@libs/Browser';
89
import DistanceRequestUtils from '@libs/DistanceRequestUtils';
10+
import getPlatform from '@libs/getPlatform';
911
import HttpUtils from '@libs/HttpUtils';
1012
import * as IOUUtils from '@libs/IOUUtils';
1113
import Navigation from '@libs/Navigation/Navigation';
@@ -15,9 +17,11 @@ import MoneyRequestParticipantsSelector from '@pages/iou/request/MoneyRequestPar
1517
import * as IOU from '@userActions/IOU';
1618
import CONST from '@src/CONST';
1719
import ONYXKEYS from '@src/ONYXKEYS';
20+
import type {Route} from '@src/ROUTES';
1821
import ROUTES from '@src/ROUTES';
1922
import type SCREENS from '@src/SCREENS';
2023
import type {Participant} from '@src/types/onyx/IOU';
24+
import KeyboardUtils from '@src/utils/keyboard';
2125
import StepScreenWrapper from './StepScreenWrapper';
2226
import type {WithFullTransactionOrNotFoundProps} from './withFullTransactionOrNotFound';
2327
import withFullTransactionOrNotFound from './withFullTransactionOrNotFound';
@@ -37,7 +41,7 @@ function IOURequestStepParticipants({
3741
const {translate} = useLocalize();
3842
const styles = useThemeStyles();
3943
const isFocused = useIsFocused();
40-
const [skipConfirmation] = useOnyx(`${ONYXKEYS.COLLECTION.SKIP_CONFIRMATION}${transactionID ?? -1}`);
44+
const [skipConfirmation] = useOnyx(`${ONYXKEYS.COLLECTION.SKIP_CONFIRMATION}${transactionID ?? CONST.DEFAULT_NUMBER_ID}`);
4145

4246
// We need to set selectedReportID if user has navigated back from confirmation page and navigates to confirmation page with already selected participant
4347
const selectedReportID = useRef<string>(participants?.length === 1 ? participants.at(0)?.reportID ?? reportID : reportID);
@@ -70,6 +74,8 @@ function IOURequestStepParticipants({
7074
const receiptFilename = transaction?.filename;
7175
const receiptPath = transaction?.receipt?.source;
7276
const receiptType = transaction?.receipt?.type;
77+
const isAndroidNative = getPlatform() === CONST.PLATFORM.ANDROID;
78+
const isMobileSafari = Browser.isMobileSafari();
7379

7480
// When the component mounts, if there is a receipt, see if the image can be read from the disk. If not, redirect the user to the starting step of the flow.
7581
// This is because until the expense is saved, the receipt file is only stored in the browsers memory as a blob:// and if the browser is refreshed, then
@@ -86,7 +92,7 @@ function IOURequestStepParticipants({
8692
(val: Participant[]) => {
8793
HttpUtils.cancelPendingRequests(READ_COMMANDS.SEARCH_FOR_REPORTS);
8894

89-
const firstParticipantReportID = val.at(0)?.reportID ?? '';
95+
const firstParticipantReportID = val.at(0)?.reportID;
9096
const rateID = DistanceRequestUtils.getCustomUnitRateID(firstParticipantReportID);
9197
const isInvoice = iouType === CONST.IOU.TYPE.INVOICE && ReportUtils.isInvoiceRoomWithID(firstParticipantReportID);
9298
numberOfParticipants.current = val.length;
@@ -102,11 +108,24 @@ function IOURequestStepParticipants({
102108
}
103109

104110
// When a participant is selected, the reportID needs to be saved because that's the reportID that will be used in the confirmation step.
105-
selectedReportID.current = firstParticipantReportID || reportID;
111+
selectedReportID.current = firstParticipantReportID ?? reportID;
106112
},
107113
[iouType, reportID, transactionID],
108114
);
109115

116+
const handleNavigation = useCallback(
117+
(route: Route) => {
118+
if (isAndroidNative || isMobileSafari) {
119+
KeyboardUtils.dismiss().then(() => {
120+
Navigation.navigate(route);
121+
});
122+
} else {
123+
Navigation.navigate(route);
124+
}
125+
},
126+
[isAndroidNative, isMobileSafari],
127+
);
128+
110129
const goToNextStep = useCallback(() => {
111130
const isCategorizing = action === CONST.IOU.ACTION.CATEGORIZE;
112131
const isShareAction = action === CONST.IOU.ACTION.SHARE;
@@ -132,12 +151,13 @@ function IOURequestStepParticipants({
132151
transactionID,
133152
selectedReportID.current || reportID,
134153
);
135-
if (isCategorizing) {
136-
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CATEGORY.getRoute(action, iouType, transactionID, selectedReportID.current || reportID, iouConfirmationPageRoute));
137-
} else {
138-
Navigation.navigate(iouConfirmationPageRoute);
139-
}
140-
}, [iouType, transactionID, transaction, reportID, action, participants]);
154+
155+
const route = isCategorizing
156+
? ROUTES.MONEY_REQUEST_STEP_CATEGORY.getRoute(action, iouType, transactionID, selectedReportID.current || reportID, iouConfirmationPageRoute)
157+
: iouConfirmationPageRoute;
158+
159+
handleNavigation(route);
160+
}, [action, participants, iouType, transaction, transactionID, reportID, handleNavigation]);
141161

142162
const navigateBack = useCallback(() => {
143163
IOUUtils.navigateToStartMoneyRequestStep(iouRequestType, iouType, transactionID, reportID, action);
@@ -154,7 +174,8 @@ function IOURequestStepParticipants({
154174
IOU.setCustomUnitRateID(transactionID, rateID);
155175
IOU.setMoneyRequestParticipantsFromReport(transactionID, selfDMReport);
156176
const iouConfirmationPageRoute = ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(action, CONST.IOU.TYPE.TRACK, transactionID, selfDMReportID);
157-
Navigation.navigate(iouConfirmationPageRoute);
177+
178+
handleNavigation(iouConfirmationPageRoute);
158179
};
159180

160181
useEffect(() => {
File renamed without changes.

src/utils/keyboard/index.website.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import {Keyboard} from 'react-native';
2+
3+
let isVisible = false;
4+
const initialViewportHeight = window?.visualViewport?.height;
5+
6+
const handleResize = () => {
7+
const currentHeight = window?.visualViewport?.height;
8+
9+
if (!currentHeight || !initialViewportHeight) {
10+
return;
11+
}
12+
13+
if (currentHeight < initialViewportHeight) {
14+
isVisible = true;
15+
return;
16+
}
17+
18+
if (currentHeight === initialViewportHeight) {
19+
isVisible = false;
20+
}
21+
};
22+
23+
window.visualViewport?.addEventListener('resize', handleResize);
24+
25+
const dismiss = (): Promise<void> => {
26+
return new Promise((resolve) => {
27+
if (!isVisible) {
28+
resolve();
29+
return;
30+
}
31+
32+
const handleDismissResize = () => {
33+
if (window.visualViewport?.height !== initialViewportHeight) {
34+
return;
35+
}
36+
37+
window.visualViewport?.removeEventListener('resize', handleDismissResize);
38+
return resolve();
39+
};
40+
41+
window.visualViewport?.addEventListener('resize', handleDismissResize);
42+
Keyboard.dismiss();
43+
});
44+
};
45+
46+
const utils = {dismiss};
47+
48+
export default utils;

0 commit comments

Comments
 (0)