diff --git a/src/pages/home/HeaderView.js b/src/pages/home/HeaderView.js index 7b315ff6c819..5b57419c8530 100644 --- a/src/pages/home/HeaderView.js +++ b/src/pages/home/HeaderView.js @@ -19,14 +19,12 @@ import TaskHeaderActionButton from '@components/TaskHeaderActionButton'; import Text from '@components/Text'; import ThreeDotsMenu from '@components/ThreeDotsMenu'; import Tooltip from '@components/Tooltip'; -import withLocalize, {withLocalizePropTypes} from '@components/withLocalize'; -import withWindowDimensions, {windowDimensionsPropTypes} from '@components/withWindowDimensions'; -import compose from '@libs/compose'; +import useLocalize from '@hooks/useLocalize'; +import useWindowDimensions from '@hooks/useWindowDimensions'; import {getGroupChatName} from '@libs/GroupChatUtils'; import * as HeaderUtils from '@libs/HeaderUtils'; import reportWithoutHasDraftSelector from '@libs/OnyxSelectors/reportWithoutHasDraftSelector'; import * as OptionsListUtils from '@libs/OptionsListUtils'; -import * as PolicyUtils from '@libs/PolicyUtils'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import reportPropTypes from '@pages/reportPropTypes'; @@ -60,8 +58,14 @@ const propTypes = { accountID: PropTypes.number, }), - ...windowDimensionsPropTypes, - ...withLocalizePropTypes, + /** The current policy of the report */ + policy: PropTypes.shape({ + /** The policy name */ + name: PropTypes.string, + + /** The URL for the policy avatar */ + avatar: PropTypes.string, + }), }; const defaultProps = { @@ -72,9 +76,12 @@ const defaultProps = { session: { accountID: 0, }, + policy: {}, }; function HeaderView(props) { + const {isSmallScreenWidth, windowWidth} = useWindowDimensions(); + const {translate} = useLocalize(); const theme = useTheme(); const styles = useThemeStyles(); const participants = lodashGet(props.report, 'participantAccountIDs', []); @@ -97,10 +104,9 @@ function HeaderView(props) { const lastVisibleMessage = ReportActionsUtils.getLastVisibleMessage(props.report.reportID); const isEmptyChat = !props.report.lastMessageText && !props.report.lastMessageTranslationKey && !lastVisibleMessage.lastMessageText && !lastVisibleMessage.lastMessageTranslationKey; const isUserCreatedPolicyRoom = ReportUtils.isUserCreatedPolicyRoom(props.report); - const policy = useMemo(() => props.policies[`${ONYXKEYS.COLLECTION.POLICY}${props.report.policyID}`], [props.policies, props.report.policyID]); - const canLeaveRoom = ReportUtils.canLeaveRoom(props.report, !_.isEmpty(policy)); + const isPolicyMember = useMemo(() => !_.isEmpty(props.policy), [props.policy]); + const canLeaveRoom = ReportUtils.canLeaveRoom(props.report, isPolicyMember); const isArchivedRoom = ReportUtils.isArchivedRoom(props.report); - const isPolicyMember = useMemo(() => PolicyUtils.isPolicyMember(props.report.policyID, props.policies), [props.report.policyID, props.policies]); // We hide the button when we are chatting with an automated Expensify account since it's not possible to contact // these users via alternative means. It is possible to request a call with Concierge so we leave the option for them. @@ -112,7 +118,7 @@ function HeaderView(props) { if (ReportUtils.isCompletedTaskReport(props.report) && canModifyTask) { threeDotMenuItems.push({ icon: Expensicons.Checkmark, - text: props.translate('task.markAsIncomplete'), + text: translate('task.markAsIncomplete'), onSelected: Session.checkIfActionIsAllowed(() => Task.reopenTask(props.report)), }); } @@ -121,7 +127,7 @@ function HeaderView(props) { if (props.report.stateNum !== CONST.REPORT.STATE_NUM.SUBMITTED && props.report.statusNum !== CONST.REPORT.STATUS.CLOSED && canModifyTask) { threeDotMenuItems.push({ icon: Expensicons.Trashcan, - text: props.translate('common.cancel'), + text: translate('common.cancel'), onSelected: Session.checkIfActionIsAllowed(() => Task.cancelTask(props.report.reportID, props.report.reportName, props.report.stateNum, props.report.statusNum)), }); } @@ -131,7 +137,7 @@ function HeaderView(props) { if (props.report.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { threeDotMenuItems.push({ icon: Expensicons.ChatBubbles, - text: props.translate('common.join'), + text: translate('common.join'), onSelected: Session.checkIfActionIsAllowed(() => Report.updateNotificationPreference(props.report.reportID, props.report.notificationPreference, CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS, false), ), @@ -140,7 +146,7 @@ function HeaderView(props) { const isWorkspaceMemberLeavingWorkspaceRoom = lodashGet(props.report, 'visibility', '') === CONST.REPORT.VISIBILITY.RESTRICTED && isPolicyMember; threeDotMenuItems.push({ icon: Expensicons.ChatBubbles, - text: props.translate('common.leave'), + text: translate('common.leave'), onSelected: Session.checkIfActionIsAllowed(() => Report.leaveRoom(props.report.reportID, isWorkspaceMemberLeavingWorkspaceRoom)), }); } @@ -151,7 +157,7 @@ function HeaderView(props) { if (isConcierge && props.guideCalendarLink) { threeDotMenuItems.push({ icon: Expensicons.Phone, - text: props.translate('videoChatButtonAndMenu.tooltip'), + text: translate('videoChatButtonAndMenu.tooltip'), onSelected: Session.checkIfActionIsAllowed(() => { Link.openExternalLink(props.guideCalendarLink); }), @@ -159,14 +165,14 @@ function HeaderView(props) { } else if (!isAutomatedExpensifyAccount && !isTaskReport && !isArchivedRoom) { threeDotMenuItems.push({ icon: ZoomIcon, - text: props.translate('videoChatButtonAndMenu.zoom'), + text: translate('videoChatButtonAndMenu.zoom'), onSelected: Session.checkIfActionIsAllowed(() => { Link.openExternalLink(CONST.NEW_ZOOM_MEETING_URL); }), }); threeDotMenuItems.push({ icon: GoogleMeetIcon, - text: props.translate('videoChatButtonAndMenu.googleMeet'), + text: translate('videoChatButtonAndMenu.googleMeet'), onSelected: Session.checkIfActionIsAllowed(() => { Link.openExternalLink(CONST.NEW_GOOGLE_MEET_MEETING_URL); }), @@ -179,7 +185,7 @@ function HeaderView(props) { const defaultSubscriptSize = ReportUtils.isExpenseRequest(props.report) ? CONST.AVATAR_SIZE.SMALL_NORMAL : CONST.AVATAR_SIZE.DEFAULT; const icons = ReportUtils.getIcons(reportHeaderData, props.personalDetails); const brickRoadIndicator = ReportUtils.hasReportNameError(props.report) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : ''; - const shouldShowBorderBottom = !isTaskReport || !props.isSmallScreenWidth; + const shouldShowBorderBottom = !isTaskReport || !isSmallScreenWidth; const shouldDisableDetailPage = ReportUtils.shouldDisableDetailPage(props.report); const isLoading = !props.report || !title; @@ -189,21 +195,21 @@ function HeaderView(props) { style={[styles.appContentHeader, shouldShowBorderBottom && styles.borderBottom]} dataSet={{dragArea: true}} > - + {isLoading ? ( ) : ( <> - {props.isSmallScreenWidth && ( + {isSmallScreenWidth && ( @@ -267,10 +273,10 @@ function HeaderView(props) { )} - {isTaskReport && !props.isSmallScreenWidth && ReportUtils.isOpenTaskReport(props.report) && } + {isTaskReport && !isSmallScreenWidth && ReportUtils.isOpenTaskReport(props.report) && } {shouldShowThreeDotsButton && ( @@ -288,25 +294,22 @@ HeaderView.displayName = 'HeaderView'; HeaderView.defaultProps = defaultProps; export default memo( - compose( - withWindowDimensions, - withLocalize, - withOnyx({ - guideCalendarLink: { - key: ONYXKEYS.ACCOUNT, - selector: (account) => (account && account.guideCalendarLink) || null, - initialValue: null, - }, - parentReport: { - key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID || report.reportID}`, - selector: reportWithoutHasDraftSelector, - }, - session: { - key: ONYXKEYS.SESSION, - }, - policies: { - key: ONYXKEYS.COLLECTION.POLICY, - }, - }), - )(HeaderView), + withOnyx({ + guideCalendarLink: { + key: ONYXKEYS.ACCOUNT, + selector: (account) => (account && account.guideCalendarLink) || null, + initialValue: null, + }, + parentReport: { + key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID || report.reportID}`, + selector: reportWithoutHasDraftSelector, + }, + session: { + key: ONYXKEYS.SESSION, + }, + policy: { + key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`, + selector: (policy) => _.pick(policy, ['name', 'avatar', 'pendingAction']), + }, + })(HeaderView), );