Skip to content

Commit

Permalink
Merge pull request #51625 from nkdengineer/fix/50418
Browse files Browse the repository at this point in the history
fix:  Deleted room is displayed in the 'Assign task'
  • Loading branch information
tgolen authored Nov 15, 2024
2 parents 88713ab + d9a6af7 commit a312ab4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
25 changes: 25 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7945,6 +7945,30 @@ function getOptimisticDataForParentReportAction(reportID: string, lastVisibleAct
});
}

function getQuickActionDetails(
quickActionReport: Report,
personalDetails: PersonalDetailsList | undefined,
policyChatForActivePolicy: Report | undefined,
reportNameValuePairs: ReportNameValuePairs,
): {quickActionAvatars: Icon[]; hideQABSubtitle: boolean} {
const isValidQuickActionReport = !(isEmptyObject(quickActionReport) || isArchivedRoom(quickActionReport, reportNameValuePairs));
let hideQABSubtitle = false;
let quickActionAvatars: Icon[] = [];
if (isValidQuickActionReport) {
const avatars = getIcons(quickActionReport, personalDetails);
quickActionAvatars = avatars.length <= 1 || isPolicyExpenseChat(quickActionReport) ? avatars : avatars.filter((avatar) => avatar.id !== currentUserAccountID);
} else {
hideQABSubtitle = true;
}
if (!isEmptyObject(policyChatForActivePolicy)) {
quickActionAvatars = getIcons(policyChatForActivePolicy, personalDetails);
}
return {
quickActionAvatars,
hideQABSubtitle,
};
}

function canBeAutoReimbursed(report: OnyxInputOrEntry<Report>, policy: OnyxInputOrEntry<Policy>): boolean {
if (isEmptyObject(policy)) {
return false;
Expand Down Expand Up @@ -8567,6 +8591,7 @@ export {
getInvoicePayerName,
getInvoicesChatName,
getPayeeName,
getQuickActionDetails,
hasActionsWithErrors,
hasAutomatedExpensifyAccountIDs,
hasExpensifyGuidesEmails,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl

const {canUseSpotnanaTravel, canUseCombinedTrackSubmit} = usePermissions();
const canSendInvoice = useMemo(() => PolicyUtils.canSendInvoice(allPolicies as OnyxCollection<OnyxTypes.Policy>, session?.email), [allPolicies, session?.email]);
const isValidReport = !(isEmptyObject(quickActionReport) || ReportUtils.isArchivedRoom(quickActionReport, reportNameValuePairs));
const {environment} = useEnvironment();
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const navatticURL = getNavatticURL(environment, introSelected?.choice);
Expand All @@ -202,7 +203,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
);

const quickActionAvatars = useMemo(() => {
if (quickActionReport) {
if (isValidReport) {
const avatars = ReportUtils.getIcons(quickActionReport, personalDetails);
return avatars.length <= 1 || ReportUtils.isPolicyExpenseChat(quickActionReport) ? avatars : avatars.filter((avatar) => avatar.id !== session?.accountID);
}
Expand Down Expand Up @@ -237,15 +238,15 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
}, [quickAction, translate, quickActionAvatars, quickActionReport]);

const hideQABSubtitle = useMemo(() => {
if (isEmptyObject(quickActionReport)) {
if (!isValidReport) {
return true;
}
if (quickActionAvatars.length === 0) {
return false;
}
const displayName = personalDetails?.[quickActionAvatars.at(0)?.id ?? -1]?.firstName ?? '';
return quickAction?.action === CONST.QUICK_ACTIONS.SEND_MONEY && displayName.length === 0;
}, [personalDetails, quickActionReport, quickAction?.action, quickActionAvatars]);
}, [isValidReport, quickActionAvatars, personalDetails, quickAction?.action]);

const selectOption = useCallback(
(onSelected: () => void, shouldRestrictAction: boolean) => {
Expand All @@ -259,7 +260,6 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
);

const navigateToQuickAction = useCallback(() => {
const isValidReport = !(isEmptyObject(quickActionReport) || ReportUtils.isArchivedRoom(quickActionReport, reportNameValuePairs));
const quickActionReportID = isValidReport ? quickActionReport?.reportID ?? '-1' : ReportUtils.generateReportID();

switch (quickAction?.action) {
Expand Down Expand Up @@ -288,7 +288,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
break;
default:
}
}, [quickAction, quickActionReport, reportNameValuePairs, selectOption]);
}, [isValidReport, quickAction?.action, quickAction?.targetAccountID, quickActionReport?.reportID, selectOption]);

/**
* Check if LHN status changed from active to inactive.
Expand Down Expand Up @@ -476,7 +476,6 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
onSelected: () =>
interceptAnonymousUser(() => {
selectOption(() => {
const isValidReport = !(isEmptyObject(policyChatForActivePolicy) || ReportUtils.isArchivedRoom(policyChatForActivePolicy, reportNameValuePairs));
const quickActionReportID = isValidReport ? policyChatForActivePolicy?.reportID ?? '-1' : ReportUtils.generateReportID();
IOU.startMoneyRequest(CONST.IOU.TYPE.SUBMIT, quickActionReportID ?? '-1', CONST.IOU.REQUEST_TYPE.SCAN, true);
}, true);
Expand All @@ -503,7 +502,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
quickActionReport,
navigateToQuickAction,
selectOption,
reportNameValuePairs,
isValidReport,
]);

return (
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,28 @@ describe('ReportUtils', () => {
});
});

describe('getQuickActionDetails', () => {
it('if the report is archived, the quick action will hide the subtitle and avatar', () => {
// Create a fake archived report as quick action report
const archivedReport: Report = {
...LHNTestUtils.getFakeReport(),
reportID: '1',
private_isArchived: DateUtils.getDBTime(),
};
const reportNameValuePairs = {
type: 'chat',
private_isArchived: true,
};

// Get the quick action detail
const quickActionDetails = ReportUtils.getQuickActionDetails(archivedReport, undefined, undefined, reportNameValuePairs);

// Expect the quickActionAvatars is empty array and hideQABSubtitle is true since the quick action report is archived
expect(quickActionDetails.quickActionAvatars.length).toEqual(0);
expect(quickActionDetails.hideQABSubtitle).toEqual(true);
});
});

describe('getChatByParticipants', () => {
const userAccountID = 1;
const userAccountID2 = 2;
Expand Down

0 comments on commit a312ab4

Please sign in to comment.