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] Store GPS coordinate when using the QAB to scan a receipt #41208

Merged
merged 7 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
120 changes: 94 additions & 26 deletions src/pages/iou/request/step/IOURequestStepScan/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import useLocalize from '@hooks/useLocalize';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as FileUtils from '@libs/fileDownload/FileUtils';
import getCurrentPosition from '@libs/getCurrentPosition';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
import * as OptionsListUtils from '@libs/OptionsListUtils';
Expand Down Expand Up @@ -245,32 +246,98 @@ 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,
transaction?.currency ?? 'USD',
transaction?.created ?? '',
'',
currentUserPersonalDetails.login,
currentUserPersonalDetails.accountID,
participants[0],
'',
receipt,
getCurrentPosition(
blimpich marked this conversation as resolved.
Show resolved Hide resolved
(successData) => {
if (iouType === CONST.IOU.TYPE.TRACK && report) {
IOU.trackExpense(
report,
0,
transaction?.currency ?? 'USD',
transaction?.created ?? '',
'',
currentUserPersonalDetails.login,
currentUserPersonalDetails.accountID,
participants[0],
'',
receipt,
'',
'',
'',
0,
false,
policy,
{},
{},
{
lat: successData.coords.latitude,
long: successData.coords.longitude,
},
);
} else {
IOU.requestMoney(
report,
0,
transaction?.currency ?? 'USD',
transaction?.created ?? '',
'',
currentUserPersonalDetails.login,
currentUserPersonalDetails.accountID,
participants[0],
'',
receipt,
'',
'',
'',
0,
false,
policy,
{},
{},
{
lat: successData.coords.latitude,
long: successData.coords.longitude,
},
);
}
},
(errorData) => {
Log.info('[IOURequestStepScan] getCurrentPosition failed', false, errorData);
// When there is an error, the money can still be requested, it just won't include the GPS coordinates
if (iouType === CONST.IOU.TYPE.TRACK && report) {
IOU.trackExpense(
report,
0,
transaction?.currency ?? 'USD',
transaction?.created ?? '',
'',
currentUserPersonalDetails.login,
currentUserPersonalDetails.accountID,
participants[0],
'',
receipt,
);
} else {
IOU.requestMoney(
report,
0,
transaction?.currency ?? 'USD',
transaction?.created ?? '',
'',
currentUserPersonalDetails.login,
currentUserPersonalDetails.accountID,
participants[0],
'',
receipt,
);
}
},
{
// 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,
Gonals marked this conversation as resolved.
Show resolved Hide resolved

// 15 seconds, don't wait too long because the server can always fall back to using the IP address
timeout: 15000,
},
);
return;
}
Expand All @@ -288,6 +355,7 @@ function IOURequestStepScan({
transaction,
navigateToConfirmationPage,
navigateToParticipantPage,
policy,
],
);

Expand Down
121 changes: 95 additions & 26 deletions src/pages/iou/request/step/IOURequestStepScan/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as Browser from '@libs/Browser';
import * as FileUtils from '@libs/fileDownload/FileUtils';
import getCurrentPosition from '@libs/getCurrentPosition';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as ReportUtils from '@libs/ReportUtils';
Expand Down Expand Up @@ -285,32 +287,98 @@ 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,
transaction?.currency ?? 'USD',
transaction?.created ?? '',
'',
currentUserPersonalDetails.login,
currentUserPersonalDetails.accountID,
participants[0],
'',
receipt,
getCurrentPosition(
(successData) => {
if (iouType === CONST.IOU.TYPE.TRACK && report) {
IOU.trackExpense(
report,
0,
transaction?.currency ?? 'USD',
transaction?.created ?? '',
'',
currentUserPersonalDetails.login,
currentUserPersonalDetails.accountID,
participants[0],
'',
receipt,
'',
'',
'',
0,
false,
policy,
{},
{},
{
lat: successData.coords.latitude,
long: successData.coords.longitude,
},
);
} else {
IOU.requestMoney(
report,
0,
transaction?.currency ?? 'USD',
transaction?.created ?? '',
'',
currentUserPersonalDetails.login,
currentUserPersonalDetails.accountID,
participants[0],
'',
receipt,
'',
'',
'',
0,
false,
policy,
{},
{},
{
lat: successData.coords.latitude,
long: successData.coords.longitude,
},
);
}
},
(errorData) => {
Log.info('[IOURequestStepScan] getCurrentPosition failed', false, errorData);
// When there is an error, the money can still be requested, it just won't include the GPS coordinates
if (iouType === CONST.IOU.TYPE.TRACK && report) {
IOU.trackExpense(
report,
0,
transaction?.currency ?? 'USD',
transaction?.created ?? '',
'',
currentUserPersonalDetails.login,
currentUserPersonalDetails.accountID,
participants[0],
'',
receipt,
);
} else {
IOU.requestMoney(
report,
0,
transaction?.currency ?? 'USD',
transaction?.created ?? '',
'',
currentUserPersonalDetails.login,
currentUserPersonalDetails.accountID,
participants[0],
'',
receipt,
);
}
},
{
// 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 wait too long because the server can always fall back to using the IP address
timeout: 15000,
},
);
return;
}
Expand All @@ -328,6 +396,7 @@ function IOURequestStepScan({
transaction,
navigateToConfirmationPage,
navigateToParticipantPage,
policy,
],
);

Expand Down
Loading