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

Load recent waypoints on first sign in #45000

Merged
merged 14 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const ONYXKEYS = {
NVP_LAST_PAYMENT_METHOD: 'nvp_private_lastPaymentMethod',

/** This NVP holds to most recent waypoints that a person has used when creating a distance expense */
NVP_RECENT_WAYPOINTS: 'expensify_recentWaypoints',
NVP_RECENT_WAYPOINTS: 'nvp_expensify_recentWaypoints',

/** This NVP contains the choice that the user made on the engagement modal */
NVP_INTRO_SELECTED: 'nvp_introSelected',
Expand Down
2 changes: 2 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ const READ_COMMANDS = {
OPEN_POLICY_INITIAL_PAGE: 'OpenPolicyInitialPage',
SEARCH: 'Search',
OPEN_SUBSCRIPTION_PAGE: 'OpenSubscriptionPage',
OPEN_DRAFT_DISTANCE_EXPENSE: 'OpenDraftDistanceExpense',
} as const;

type ReadCommand = ValueOf<typeof READ_COMMANDS>;
Expand Down Expand Up @@ -734,6 +735,7 @@ type ReadCommandParameters = {
[READ_COMMANDS.OPEN_POLICY_INITIAL_PAGE]: Parameters.OpenPolicyInitialPageParams;
[READ_COMMANDS.SEARCH]: Parameters.SearchParams;
[READ_COMMANDS.OPEN_SUBSCRIPTION_PAGE]: null;
[READ_COMMANDS.OPEN_DRAFT_DISTANCE_EXPENSE]: null;
};

const SIDE_EFFECT_REQUEST_COMMANDS = {
Expand Down
29 changes: 28 additions & 1 deletion src/libs/actions/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,4 +444,31 @@ function markAsCash(transactionID: string, transactionThreadReportID: string) {
return API.write(WRITE_COMMANDS.MARK_AS_CASH, parameters, onyxData);
}

export {addStop, createInitialWaypoints, saveWaypoint, removeWaypoint, getRoute, updateWaypoints, clearError, markAsCash, dismissDuplicateTransactionViolation, setReviewDuplicatesKey};
function openDraftDistanceExpense() {
const onyxData: OnyxData = {
optimisticData: [
{
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.NVP_RECENT_WAYPOINTS,

// By optimistically setting the recent waypoints to an empty array, no further loading attempts will be made
value: [],
},
],
};
API.read(READ_COMMANDS.OPEN_DRAFT_DISTANCE_EXPENSE, null, onyxData);
}

export {
addStop,
createInitialWaypoints,
saveWaypoint,
removeWaypoint,
getRoute,
updateWaypoints,
clearError,
markAsCash,
dismissDuplicateTransactionViolation,
setReviewDuplicatesKey,
openDraftDistanceExpense,
};
15 changes: 14 additions & 1 deletion src/pages/iou/request/step/IOURequestStepDistance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ function IOURequestStepDistance({
const isEditing = action === CONST.IOU.ACTION.EDIT;
const transactionWasSaved = useRef(false);
const isCreatingNewRequest = !(backTo || isEditing);
const [recentWaypoints, {status: recentWaypointsStatus}] = useOnyx(ONYXKEYS.NVP_RECENT_WAYPOINTS);
const iouRequestType = TransactionUtils.getRequestType(transaction);

// 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
Expand All @@ -142,6 +144,16 @@ function IOURequestStepDistance({
}
}

useEffect(() => {
if (iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE || isOffline || recentWaypointsStatus === 'loading' || recentWaypoints !== undefined) {
return;
}

// Only load the recent waypoints if they have been read from Onyx as undefined
// If the account doesn't have recent waypoints they will be returned as an empty array
TransactionAction.openDraftDistanceExpense();
}, [iouRequestType, recentWaypointsStatus, recentWaypoints, isOffline]);

useEffect(() => {
MapboxToken.init();
return MapboxToken.stop;
Expand Down Expand Up @@ -261,7 +273,7 @@ function IOURequestStepDistance({
category: '',
tag: '',
billable: false,
iouRequestType: CONST.IOU.REQUEST_TYPE.DISTANCE,
iouRequestType,
existingSplitChatReportID: report?.reportID,
});
return;
Expand Down Expand Up @@ -333,6 +345,7 @@ function IOURequestStepDistance({
navigateToParticipantPage,
navigateToConfirmationPage,
policy,
iouRequestType,
reportNameValuePairs,
]);

Expand Down
Loading