From e9c7742aac218884caaf5e20a1035883b27fb562 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 30 Jan 2024 11:23:00 -0700 Subject: [PATCH 1/7] Add GPS coordinates to smartscanned images --- src/libs/actions/IOU.js | 5 ++++ .../step/IOURequestStepConfirmation.js | 24 +++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 3d6664099866..3890d1d3262a 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1289,6 +1289,7 @@ function updateDistanceRequest(transactionID, transactionThreadReportID, transac * @param {Object} [policy] * @param {Object} [policyTags] * @param {Object} [policyCategories] + * @param {Object} [gpsPoints] */ function requestMoney( report, @@ -1309,6 +1310,7 @@ function requestMoney( policy = undefined, policyTags = undefined, policyCategories = undefined, + gpsPoints = undefined, ) { // If the report is iou or expense report, we should get the linked chat report to be passed to the getMoneyRequestInformation function const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); @@ -1360,6 +1362,9 @@ function requestMoney( taxCode, taxAmount, billable, + + // This needs to be a string of JSON because of limitations with the fetch() API and nested objects + gpsPoints: gpsPoints ? JSON.stringify(gpsPoints) : undefined, }, onyxData, ); diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.js b/src/pages/iou/request/step/IOURequestStepConfirmation.js index 6028a735d132..154ad0198a08 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.js +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.js @@ -18,6 +18,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import compose from '@libs/compose'; import * as DeviceCapabilities from '@libs/DeviceCapabilities'; +import getCurrentPosition from '@libs/getCurrentPosition'; import * as IOUUtils from '@libs/IOUUtils'; import Navigation from '@libs/Navigation/Navigation'; import * as OptionsListUtils from '@libs/OptionsListUtils'; @@ -160,7 +161,7 @@ function IOURequestStepConfirmation({ * @param {File} [receiptObj] */ const requestMoney = useCallback( - (selectedParticipants, trimmedComment, receiptObj) => { + (selectedParticipants, trimmedComment, receiptObj, gpsPoints) => { IOU.requestMoney( report, transaction.amount, @@ -180,6 +181,7 @@ function IOURequestStepConfirmation({ policy, policyTags, policyCategories, + gpsPoints, ); }, [report, transaction, transactionTaxCode, transactionTaxAmount, currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, policy, policyTags, policyCategories], @@ -265,7 +267,25 @@ function IOURequestStepConfirmation({ } if (receiptFile) { - requestMoney(selectedParticipants, trimmedComment, receiptFile); + getCurrentPosition( + (successData) => { + requestMoney(selectedParticipants, trimmedComment, receiptFile, { + lat: successData.coords.latitude, + long: successData.coords.longitude, + }); + }, + () => { + // When there is an error, the money can still be requested, it just won't include the GPS coordinates + requestMoney(selectedParticipants, trimmedComment, receiptFile); + }, + { + // It's OK to get a cached location that is up to an hour old because the only accuracy needed is the country the user is in + maximumAge: 1000 * 60 * 60, + + // 15 seconds, don't way too long because the server can always fall back to using the IP address + timeout: 15000, + }, + ); return; } From 141cf89428a21ff85e7ee643d017afa3d831e1b9 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 30 Jan 2024 14:56:09 -0700 Subject: [PATCH 2/7] Add error logging --- src/pages/iou/request/step/IOURequestStepConfirmation.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.js b/src/pages/iou/request/step/IOURequestStepConfirmation.js index 154ad0198a08..edd788f51e90 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.js +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.js @@ -20,6 +20,7 @@ import compose from '@libs/compose'; import * as DeviceCapabilities from '@libs/DeviceCapabilities'; import getCurrentPosition from '@libs/getCurrentPosition'; import * as IOUUtils from '@libs/IOUUtils'; +import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; import * as OptionsListUtils from '@libs/OptionsListUtils'; import * as ReportUtils from '@libs/ReportUtils'; @@ -274,7 +275,8 @@ function IOURequestStepConfirmation({ long: successData.coords.longitude, }); }, - () => { + (errorData) => { + Log.info('[IOURequestStepConfirmation] getCurrentPosition failed', false, errorData); // When there is an error, the money can still be requested, it just won't include the GPS coordinates requestMoney(selectedParticipants, trimmedComment, receiptFile); }, From ae1665dc6293066d4571e0dfb2b82a9e35777808 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Fri, 2 Feb 2024 09:39:09 -0700 Subject: [PATCH 3/7] Update src/pages/iou/request/step/IOURequestStepConfirmation.js Co-authored-by: Ionatan Wiznia --- src/pages/iou/request/step/IOURequestStepConfirmation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.js b/src/pages/iou/request/step/IOURequestStepConfirmation.js index edd788f51e90..37186dc28931 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.js +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.js @@ -284,7 +284,7 @@ function IOURequestStepConfirmation({ // It's OK to get a cached location that is up to an hour old because the only accuracy needed is the country the user is in maximumAge: 1000 * 60 * 60, - // 15 seconds, don't way too long because the server can always fall back to using the IP address + // 15 seconds, don't wait too long because the server can always fall back to using the IP address timeout: 15000, }, ); From c34932cb2f7ad51d66aa3fb401e6ce32a6bf08f3 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 5 Feb 2024 13:14:47 -0700 Subject: [PATCH 4/7] Prevent form from being submitted multiple times --- src/pages/iou/request/step/IOURequestStepConfirmation.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.js b/src/pages/iou/request/step/IOURequestStepConfirmation.js index b21c53c01580..daa653f616ba 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.js +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.js @@ -105,6 +105,7 @@ function IOURequestStepConfirmation({ [transaction.participants, personalDetails], ); const isPolicyExpenseChat = useMemo(() => ReportUtils.isPolicyExpenseChat(ReportUtils.getRootParentReport(report)), [report]); + let formHasBeenSubmitted = false; useEffect(() => { if (!transaction || !transaction.originalCurrency) { @@ -228,6 +229,13 @@ function IOURequestStepConfirmation({ (selectedParticipants) => { const trimmedComment = lodashGet(transaction, 'comment.comment', '').trim(); + // Don't let the form be submitted multiple times while the navigator is waiting to take the user to a different page + if (formHasBeenSubmitted) { + return; + } + + formHasBeenSubmitted = true; + // If we have a receipt let's start the split bill by creating only the action, the transaction, and the group DM if needed if (iouType === CONST.IOU.TYPE.SPLIT && receiptFile) { IOU.startSplitBill( From df02d87b9064ca827e66572a6dc5bb076f3a9355 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 5 Feb 2024 13:50:42 -0700 Subject: [PATCH 5/7] Add GPS points to the types --- src/libs/API/parameters/RequestMoneyParams.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/API/parameters/RequestMoneyParams.ts b/src/libs/API/parameters/RequestMoneyParams.ts index ccafdd692137..983394008ba7 100644 --- a/src/libs/API/parameters/RequestMoneyParams.ts +++ b/src/libs/API/parameters/RequestMoneyParams.ts @@ -24,6 +24,7 @@ type RequestMoneyParams = { taxCode: string; taxAmount: number; billable?: boolean; + gpsPoints?: string; }; export default RequestMoneyParams; From 77be41142b8e0f87e41bc28a83b8f6f9bb4a20f6 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 5 Feb 2024 13:56:46 -0700 Subject: [PATCH 6/7] Use a ref instead of a variable. --- src/pages/iou/request/step/IOURequestStepConfirmation.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.js b/src/pages/iou/request/step/IOURequestStepConfirmation.js index daa653f616ba..b939e0e725c0 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.js +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.js @@ -1,6 +1,6 @@ import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; -import React, {useCallback, useEffect, useMemo, useState} from 'react'; +import React, {useCallback, useEffect, useMemo, useState, useRef} from 'react'; import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; @@ -105,7 +105,7 @@ function IOURequestStepConfirmation({ [transaction.participants, personalDetails], ); const isPolicyExpenseChat = useMemo(() => ReportUtils.isPolicyExpenseChat(ReportUtils.getRootParentReport(report)), [report]); - let formHasBeenSubmitted = false; + const formHasBeenSubmitted = useRef(false); useEffect(() => { if (!transaction || !transaction.originalCurrency) { @@ -230,11 +230,11 @@ function IOURequestStepConfirmation({ const trimmedComment = lodashGet(transaction, 'comment.comment', '').trim(); // Don't let the form be submitted multiple times while the navigator is waiting to take the user to a different page - if (formHasBeenSubmitted) { + if (formHasBeenSubmitted.current) { return; } - formHasBeenSubmitted = true; + formHasBeenSubmitted.current = true; // If we have a receipt let's start the split bill by creating only the action, the transaction, and the group DM if needed if (iouType === CONST.IOU.TYPE.SPLIT && receiptFile) { From e83c24a01a31607e5ccf406de8dd09a22c9d7c7e Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 5 Feb 2024 14:04:32 -0700 Subject: [PATCH 7/7] Style --- src/pages/iou/request/step/IOURequestStepConfirmation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.js b/src/pages/iou/request/step/IOURequestStepConfirmation.js index b939e0e725c0..be57de687e3a 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.js +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.js @@ -1,6 +1,6 @@ import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; -import React, {useCallback, useEffect, useMemo, useState, useRef} from 'react'; +import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore';