Skip to content

Commit f542ddd

Browse files
committed
Fix changed policy offline issue
1 parent 4789acf commit f542ddd

1 file changed

Lines changed: 5 additions & 11 deletions

File tree

src/components/ReportActionAvatars/useReportActionAvatars.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {FallbackAvatar} from '@components/Icon/Expensicons';
44
import useOnyx from '@hooks/useOnyx';
55
import usePolicy from '@hooks/usePolicy';
66
import useReportIsArchived from '@hooks/useReportIsArchived';
7-
import {getOriginalMessage, getReportAction, getSortedReportActions, isMoneyRequestAction} from '@libs/ReportActionsUtils';
7+
import {getOriginalMessage, getReportAction, isMoneyRequestAction} from '@libs/ReportActionsUtils';
88
import {
99
getDefaultWorkspaceAvatar,
1010
getDisplayNameForParticipant,
@@ -21,7 +21,6 @@ import CONST from '@src/CONST';
2121
import ONYXKEYS from '@src/ONYXKEYS';
2222
import type {OnyxInputOrEntry, Report, ReportAction} from '@src/types/onyx';
2323
import type {Icon as IconType} from '@src/types/onyx/OnyxCommon';
24-
import type {OriginalMessageChangePolicy} from '@src/types/onyx/OriginalMessage';
2524
import useReportPreviewSenderID from './useReportPreviewSenderID';
2625

2726
function useReportActionAvatars({
@@ -63,11 +62,7 @@ function useReportActionAvatars({
6362
action = getReportAction(reportChatReport?.reportID, chatReport.parentReportActionID);
6463
}
6564

66-
const [latestChangePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${action?.childReportID}`, {
67-
canBeMissing: true,
68-
selector: (reportActions) =>
69-
getSortedReportActions(Object.values(reportActions ?? {}).filter((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CHANGE_POLICY)).at(-1),
70-
});
65+
const [actionChildReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${action?.childReportID}`, {canBeMissing: true});
7166

7267
const isAReportPreviewAction = action?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW;
7368

@@ -81,9 +76,8 @@ function useReportActionAvatars({
8176

8277
const reportPolicyID = iouReport?.policyID ?? chatReport?.policyID;
8378
const chatReportPolicyIDExists = chatReport?.policyID === CONST.POLICY.ID_FAKE || !chatReport?.policyID;
84-
const latestChangePolicyOM = getOriginalMessage(latestChangePolicy as ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.CHANGE_POLICY>) ?? {};
85-
const {fromPolicy: policyIDBeforeChange, toPolicy: changedPolicyID} = latestChangePolicyOM as OriginalMessageChangePolicy;
86-
const shouldUseChangedPolicyID = !!changedPolicyID;
79+
const changedPolicyID = actionChildReport?.policyID ?? iouReport?.policyID;
80+
const shouldUseChangedPolicyID = !!changedPolicyID && changedPolicyID !== chatReport?.policyID;
8781
const retrievedPolicyID = chatReportPolicyIDExists ? reportPolicyID : chatReport?.policyID;
8882

8983
const policyID = shouldUseChangedPolicyID ? changedPolicyID : (passedPolicyID ?? retrievedPolicyID);
@@ -289,7 +283,7 @@ function useReportActionAvatars({
289283
const isWorkspaceWithUserAvatar =
290284
avatars.at(0)?.type === CONST.ICON_TYPE_WORKSPACE && avatars.at(1)?.type === CONST.ICON_TYPE_AVATAR && avatarType === CONST.REPORT_ACTION_AVATARS.TYPE.MULTIPLE;
291285
// eslint-disable-next-line rulesdir/no-negated-variables
292-
const wasReportPreviewMovedToDifferentPolicy = chatReport?.policyID === policyIDBeforeChange && policyIDBeforeChange !== changedPolicyID && isAReportPreviewAction;
286+
const wasReportPreviewMovedToDifferentPolicy = shouldUseChangedPolicyID && isAReportPreviewAction;
293287

294288
if (shouldUseInvoiceExpenseIcons) {
295289
avatars = getIconsWithDefaults(invoiceReport);

0 commit comments

Comments
 (0)