Skip to content

Commit

Permalink
Merge pull request #38980 from nkdengineer/fix/38583
Browse files Browse the repository at this point in the history
Fix the optimistic data of hold action isn't consistent with backend data
  • Loading branch information
neil-marcellini authored Apr 16, 2024
2 parents b16aed0 + 714ea5e commit 28fa0e8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
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 @@ -4054,7 +4054,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 @@ -5379,8 +5379,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

0 comments on commit 28fa0e8

Please sign in to comment.