Skip to content

Commit

Permalink
simplify admin chat getting
Browse files Browse the repository at this point in the history
  • Loading branch information
rezkiy37 committed Apr 26, 2024
1 parent 62b193a commit 90a72e9
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/pages/home/report/SystemChatReportFooterMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,39 @@
import React, {useMemo} from 'react';
import {withOnyx} from 'react-native-onyx';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import Banner from '@components/Banner';
import * as Expensicons from '@components/Icon/Expensicons';
import Text from '@components/Text';
import TextLink from '@components/TextLink';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as PolicyUtils from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import Navigation from '@navigation/Navigation';
import * as ReportInstance from '@userActions/Report';
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, Report} from '@src/types/onyx';

type SystemChatReportFooterMessageOnyxProps = {
/** Saved onboarding purpose selected by the user */
choice: OnyxEntry<OnboardingPurposeType>;

/** Collection of reports */
reports: OnyxCollection<Report>;

/** The list of this user's policies */
policies: OnyxCollection<PolicyType>;
/** policyID for main workspace */
activePolicyID: OnyxEntry<Required<string>>;
};

type SystemChatReportFooterMessageProps = SystemChatReportFooterMessageOnyxProps;

function SystemChatReportFooterMessage({choice, reports, policies}: SystemChatReportFooterMessageProps) {
function SystemChatReportFooterMessage({choice, activePolicyID}: SystemChatReportFooterMessageProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();

const adminChatReport = useMemo(() => {
const adminsReports = Object.values(reports ?? {}).filter((report) => report?.chatType === CONST.REPORT.CHAT_TYPE.POLICY_ADMINS);
const activePolicies = Object.values(policies ?? {}).filter((policy) => PolicyUtils.shouldShowPolicy(policy, false));

return adminsReports.find((report) => activePolicies.find((policy) => policy?.id === report?.policyID));
}, [policies, reports]);
const policy = PolicyUtils.getPolicy(activePolicyID ?? '');
return ReportUtils.getReport(String(policy.chatReportIDAdmins));
}, [activePolicyID]);

const content = useMemo(() => {
switch (choice) {
Expand Down Expand Up @@ -79,10 +74,9 @@ export default withOnyx<SystemChatReportFooterMessageProps, SystemChatReportFoot
choice: {
key: ONYXKEYS.ONBOARDING_PURPOSE_SELECTED,
},
reports: {
key: ONYXKEYS.COLLECTION.REPORT,
},
policies: {
key: ONYXKEYS.COLLECTION.POLICY,

activePolicyID: {
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID,
initialValue: null,
},
})(SystemChatReportFooterMessage);

0 comments on commit 90a72e9

Please sign in to comment.