From b742d6642e2c94d6accdbaf9322fd8e6bc77ff4a Mon Sep 17 00:00:00 2001 From: Shahe Shahinyan Date: Sun, 4 Feb 2024 14:23:24 +0400 Subject: [PATCH] Addressed to reviewer comments --- src/libs/PolicyUtils.ts | 2 +- .../Report/NotificationPreferencePage.tsx | 4 +-- .../settings/Report/ReportSettingsPage.tsx | 26 +++++++++---------- src/pages/settings/Report/RoomNamePage.tsx | 3 +-- .../settings/Report/WriteCapabilityPage.tsx | 5 ++-- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 426071a81894..b6ee4ab3a353 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -107,7 +107,7 @@ function isExpensifyGuideTeam(email: string): boolean { /** * Checks if the current user is an admin of the policy. */ -const isPolicyAdmin = (policy: OnyxEntry | undefined): boolean => policy?.role === CONST.POLICY.ROLE.ADMIN; +const isPolicyAdmin = (policy: OnyxEntry): boolean => policy?.role === CONST.POLICY.ROLE.ADMIN; const isPolicyMember = (policyID: string, policies: Record): boolean => Object.values(policies).some((policy) => policy?.id === policyID); diff --git a/src/pages/settings/Report/NotificationPreferencePage.tsx b/src/pages/settings/Report/NotificationPreferencePage.tsx index 30b9ffa3c2d2..05f3483f7ce8 100644 --- a/src/pages/settings/Report/NotificationPreferencePage.tsx +++ b/src/pages/settings/Report/NotificationPreferencePage.tsx @@ -40,9 +40,9 @@ function NotificationPreferencePage({report}: NotificationPreferencePageProps) { - ReportActions.updateNotificationPreference(report?.reportID ?? '', report?.notificationPreference, option.value, true, undefined, undefined, report) + report && ReportActions.updateNotificationPreference(report.reportID, report.notificationPreference, option.value, true, undefined, undefined, report) } - initiallyFocusedOptionKey={Object.values(notificationPreferenceOptions ?? {}).find((locale) => locale.isSelected)?.keyForList} + initiallyFocusedOptionKey={notificationPreferenceOptions.find((locale) => locale.isSelected)?.keyForList} /> diff --git a/src/pages/settings/Report/ReportSettingsPage.tsx b/src/pages/settings/Report/ReportSettingsPage.tsx index 28d189359860..37408ef61df2 100644 --- a/src/pages/settings/Report/ReportSettingsPage.tsx +++ b/src/pages/settings/Report/ReportSettingsPage.tsx @@ -1,5 +1,4 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import isEmpty from 'lodash/isEmpty'; import React, {useMemo} from 'react'; import {ScrollView, View} from 'react-native'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; @@ -23,6 +22,7 @@ import * as ReportActions from '@userActions/Report'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; +import {isEmptyObject} from '@src/types/utils/EmptyObject'; type ReportSettingsPageProps = WithReportOrNotFoundProps & StackScreenProps; @@ -38,7 +38,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { // We only want policy owners and admins to be able to modify the welcome message, but not in thread chat const shouldDisableWelcomeMessage = ReportUtils.shouldDisableWelcomeMessage(report, linkedWorkspace); - const shouldDisableSettings = isEmpty(report) || ReportUtils.isArchivedRoom(report); + const shouldDisableSettings = isEmptyObject(report) || ReportUtils.isArchivedRoom(report); const shouldShowRoomName = !ReportUtils.isPolicyExpenseChat(report) && !ReportUtils.isChatThread(report); const notificationPreference = report?.notificationPreference && report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN @@ -60,7 +60,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(reportID ?? ''))} + onBackButtonPress={() => Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(reportID))} /> {shouldShowNotificationPref && ( @@ -68,7 +68,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { shouldShowRightIcon title={notificationPreference} description={translate('notificationPreferencesPage.label')} - onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.getRoute(reportID ?? ''))} + onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.getRoute(reportID))} /> )} {shouldShowRoomName && ( @@ -76,7 +76,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { pendingAction={report?.pendingFields?.reportName} errors={report?.errorFields?.reportName} errorRowStyles={[styles.ph5]} - onClose={() => ReportActions.clearPolicyRoomNameErrors(reportID ?? '')} + onClose={() => ReportActions.clearPolicyRoomNameErrors(reportID)} > {shouldDisableRename ? ( @@ -99,7 +99,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { shouldShowRightIcon title={report?.reportName} description={translate('newRoomPage.roomName')} - onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_ROOM_NAME.getRoute(reportID ?? ''))} + onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_ROOM_NAME.getRoute(reportID))} /> )} @@ -110,7 +110,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { shouldShowRightIcon title={writeCapabilityText} description={translate('writeCapabilityPage.label')} - onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_WRITE_CAPABILITY.getRoute(reportID ?? ''))} + onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_WRITE_CAPABILITY.getRoute(reportID))} /> ) : ( @@ -129,7 +129,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { ))} - {Boolean(linkedWorkspace) && ( + {linkedWorkspace !== null && ( )} - {Boolean(report?.visibility) && ( + {report?.visibility !== undefined && ( - {report?.visibility && translate(`newRoomPage.visibilityOptions.${report.visibility}`)} + {translate(`newRoomPage.visibilityOptions.${report.visibility}`)} - {report?.visibility && translate(`newRoomPage.${report.visibility}Description`)} + {report.visibility && translate(`newRoomPage.${report.visibility}Description`)} )} @@ -168,7 +168,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { Navigation.navigate(ROUTES.REPORT_WELCOME_MESSAGE.getRoute(reportID ?? ''))} + onPress={() => Navigation.navigate(ROUTES.REPORT_WELCOME_MESSAGE.getRoute(reportID))} shouldShowRightIcon /> )} diff --git a/src/pages/settings/Report/RoomNamePage.tsx b/src/pages/settings/Report/RoomNamePage.tsx index 6b2fd751f01f..30226bc6f502 100644 --- a/src/pages/settings/Report/RoomNamePage.tsx +++ b/src/pages/settings/Report/RoomNamePage.tsx @@ -27,7 +27,6 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import type {Policy, Report} from '@src/types/onyx'; -import {isEmptyObject} from '@src/types/utils/EmptyObject'; type RoomNamePageOnyxProps = { /** All reports shared with the user */ @@ -87,7 +86,7 @@ function RoomNamePage({report, policy, reports}: RoomNamePageProps) { !isEmptyObject(report) && ReportActions.updatePolicyRoomNameAndNavigate(report, values.roomName)} + onSubmit={(values) => report && ReportActions.updatePolicyRoomNameAndNavigate(report, values.roomName)} validate={validate} submitButtonText={translate('common.save')} enabledWhenOffline diff --git a/src/pages/settings/Report/WriteCapabilityPage.tsx b/src/pages/settings/Report/WriteCapabilityPage.tsx index 7af951d685d4..5f5fe73e5199 100644 --- a/src/pages/settings/Report/WriteCapabilityPage.tsx +++ b/src/pages/settings/Report/WriteCapabilityPage.tsx @@ -18,7 +18,6 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import type {Policy} from '@src/types/onyx'; -import {isEmptyObject} from '@src/types/utils/EmptyObject'; type WriteCapabilityPageOnyxProps = { /** The policy object for the current route */ @@ -53,8 +52,8 @@ function WriteCapabilityPage({report, policy}: WriteCapabilityPageProps) { /> !isEmptyObject(report) && ReportActions.updateWriteCapabilityAndNavigate(report, option.value)} - initiallyFocusedOptionKey={Object.values(writeCapabilityOptions).find((locale) => locale.isSelected)?.keyForList} + onSelectRow={(option) => report && ReportActions.updateWriteCapabilityAndNavigate(report, option.value)} + initiallyFocusedOptionKey={writeCapabilityOptions.find((locale) => locale.isSelected)?.keyForList} />