From 907167cb007b1fa78937b749c828f6bb3e88996e Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 26 Apr 2024 17:55:39 +0200 Subject: [PATCH] improve admin chat searching --- .../report/SystemChatReportFooterMessage.tsx | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/pages/home/report/SystemChatReportFooterMessage.tsx b/src/pages/home/report/SystemChatReportFooterMessage.tsx index a946968f0ec7..c9ccac8f5c18 100644 --- a/src/pages/home/report/SystemChatReportFooterMessage.tsx +++ b/src/pages/home/report/SystemChatReportFooterMessage.tsx @@ -1,6 +1,6 @@ import React, {useMemo} from 'react'; import {withOnyx} from 'react-native-onyx'; -import type {OnyxEntry} from 'react-native-onyx'; +import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import Banner from '@components/Banner'; import * as Expensicons from '@components/Icon/Expensicons'; import Text from '@components/Text'; @@ -15,25 +15,32 @@ import type {OnboardingPurposeType} from '@src/CONST'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import type {Policy as PolicyType} from '@src/types/onyx'; type SystemChatReportFooterMessageOnyxProps = { /** Saved onboarding purpose selected by the user */ choice: OnyxEntry; + /** The list of this user's policies */ + policies: OnyxCollection; + /** policyID for main workspace */ activePolicyID: OnyxEntry>; }; type SystemChatReportFooterMessageProps = SystemChatReportFooterMessageOnyxProps; -function SystemChatReportFooterMessage({choice, activePolicyID}: SystemChatReportFooterMessageProps) { +function SystemChatReportFooterMessage({choice, policies, activePolicyID}: SystemChatReportFooterMessageProps) { const {translate} = useLocalize(); const styles = useThemeStyles(); const adminChatReport = useMemo(() => { - const policy = PolicyUtils.getPolicy(activePolicyID ?? ''); - return ReportUtils.getReport(String(policy.chatReportIDAdmins)); - }, [activePolicyID]); + const adminPolicy = activePolicyID + ? PolicyUtils.getPolicy(activePolicyID ?? '') + : Object.values(policies ?? {}).find((policy) => PolicyUtils.shouldShowPolicy(policy, false) && policy?.role === CONST.POLICY.ROLE.ADMIN && policy?.chatReportIDAdmins); + + return ReportUtils.getReport(String(adminPolicy?.chatReportIDAdmins)); + }, [activePolicyID, policies]); const content = useMemo(() => { switch (choice) { @@ -74,7 +81,9 @@ export default withOnyx