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

Fix the optimistic data of hold action isn't consistent with backend data #38980

Merged
merged 6 commits into from
Apr 16, 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
9 changes: 9 additions & 0 deletions src/libs/DateUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
addDays,
addHours,
addMilliseconds,
addMinutes,
eachDayOfInterval,
eachMonthOfInterval,
Expand Down Expand Up @@ -392,6 +393,13 @@ function subtractMillisecondsFromDateTime(dateTime: string, milliseconds: number
return getDBTime(newTimestamp);
}

function addMillisecondsFromDateTime(dateTime: string, milliseconds: number): string {
const date = zonedTimeToUtc(dateTime, 'UTC');
const newTimestamp = addMilliseconds(date, milliseconds).valueOf();

return getDBTime(newTimestamp);
}

/**
* @param isoTimestamp example: 2023-05-16 05:34:14.388
* @returns example: 2023-05-16
Expand Down Expand Up @@ -784,6 +792,7 @@ const DateUtils = {
getDBTimeWithSkew,
setLocale,
subtractMillisecondsFromDateTime,
addMillisecondsFromDateTime,
getDateStringFromISOTimestamp,
getThirtyMinutesFromNow,
getEndOfToday,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4042,7 +4042,7 @@ function buildOptimisticHoldReportAction(created = DateUtils.getDBTime()): Optim
function buildOptimisticHoldReportActionComment(comment: string, created = DateUtils.getDBTime()): OptimisticHoldReportAction {
return {
reportActionID: NumberUtils.rand64(),
actionName: CONST.REPORT.ACTIONS.TYPE.HOLDCOMMENT,
actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
actorAccountID: currentUserAccountID,
message: [
Expand Down
5 changes: 3 additions & 2 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5392,8 +5392,9 @@ function setShownHoldUseExplanation() {
* Put money request on HOLD
*/
function putOnHold(transactionID: string, comment: string, reportID: string) {
const createdReportAction = ReportUtils.buildOptimisticHoldReportAction();
const createdReportActionComment = ReportUtils.buildOptimisticHoldReportActionComment(comment);
const currentTime = DateUtils.getDBTime();
const createdReportAction = ReportUtils.buildOptimisticHoldReportAction(currentTime);
const createdReportActionComment = ReportUtils.buildOptimisticHoldReportActionComment(comment, DateUtils.addMillisecondsFromDateTime(currentTime, 1));

const optimisticData: OnyxUpdate[] = [
{
Expand Down
Loading