From 151da261342b3b4b4dcf4b1b8f5098dd45f705a8 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Tue, 26 Mar 2024 13:07:06 +0700 Subject: [PATCH 1/3] Fix the optimistic data of hold action isn't consistent with backend data --- src/libs/actions/IOU.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 85ab98bb7819..17785304af80 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -5047,8 +5047,9 @@ function getIOUReportID(iou?: OnyxTypes.IOU, route?: MoneyRequestRoute): string * 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(DateUtils.subtractMillisecondsFromDateTime(currentTime, 1)); + const createdReportActionComment = ReportUtils.buildOptimisticHoldReportActionComment(comment, currentTime); const optimisticData: OnyxUpdate[] = [ { From 311f96bbf1d5e0856c9ab0a11dddfe4443cacc35 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 3 Apr 2024 13:19:33 +0700 Subject: [PATCH 2/3] add new function --- src/libs/DateUtils.ts | 9 +++++++++ src/libs/actions/IOU.ts | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/libs/DateUtils.ts b/src/libs/DateUtils.ts index 4d4f8d425681..6a2f5b5c8b7a 100644 --- a/src/libs/DateUtils.ts +++ b/src/libs/DateUtils.ts @@ -1,6 +1,7 @@ import { addDays, addHours, + addMilliseconds, addMinutes, eachDayOfInterval, eachMonthOfInterval, @@ -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 @@ -784,6 +792,7 @@ const DateUtils = { getDBTimeWithSkew, setLocale, subtractMillisecondsFromDateTime, + addMillisecondsFromDateTime, getDateStringFromISOTimestamp, getThirtyMinutesFromNow, getEndOfToday, diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index f6222dc9eca6..56702bb4ffcb 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -5121,8 +5121,8 @@ function setShownHoldUseExplanation() { */ function putOnHold(transactionID: string, comment: string, reportID: string) { const currentTime = DateUtils.getDBTime(); - const createdReportAction = ReportUtils.buildOptimisticHoldReportAction(DateUtils.subtractMillisecondsFromDateTime(currentTime, 1)); - const createdReportActionComment = ReportUtils.buildOptimisticHoldReportActionComment(comment, currentTime); + const createdReportAction = ReportUtils.buildOptimisticHoldReportAction(currentTime); + const createdReportActionComment = ReportUtils.buildOptimisticHoldReportActionComment(comment, DateUtils.addMillisecondsFromDateTime(currentTime, 1)); const optimisticData: OnyxUpdate[] = [ { From 714ea5e0f5247e1d7d41625248b12ec7f50b98e5 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 15 Apr 2024 21:34:00 +0700 Subject: [PATCH 3/3] edit type of hold comment report action --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 1b60cd611d57..f5eccb046765 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -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: [