From 4459b37bb3762b41bf2a4eed338e761424fd0a6a Mon Sep 17 00:00:00 2001 From: Shahe Shahinyan Date: Fri, 26 Jan 2024 21:07:39 +0400 Subject: [PATCH 01/15] Init changes to migrate --- src/ONYXKEYS.ts | 2 +- src/components/DisplayNames/types.ts | 2 +- src/languages/en.ts | 1 + src/libs/ErrorUtils.ts | 2 +- src/libs/PolicyUtils.ts | 2 +- src/libs/ReportUtils.ts | 6 +- src/libs/ValidationUtils.ts | 5 +- src/libs/actions/Report.ts | 4 +- .../home/report/withReportOrNotFound.tsx | 8 +- .../Report/NotificationPreferencePage.js | 59 -------------- .../Report/NotificationPreferencePage.tsx | 55 +++++++++++++ ...SettingsPage.js => ReportSettingsPage.tsx} | 80 +++++-------------- .../{RoomNamePage.js => RoomNamePage.tsx} | 53 ++++++------ ...abilityPage.js => WriteCapabilityPage.tsx} | 49 ++++++------ src/types/onyx/Form.ts | 6 +- src/types/onyx/index.ts | 3 +- 16 files changed, 149 insertions(+), 188 deletions(-) delete mode 100644 src/pages/settings/Report/NotificationPreferencePage.js create mode 100644 src/pages/settings/Report/NotificationPreferencePage.tsx rename src/pages/settings/Report/{ReportSettingsPage.js => ReportSettingsPage.tsx} (78%) rename src/pages/settings/Report/{RoomNamePage.js => RoomNamePage.tsx} (80%) rename src/pages/settings/Report/{WriteCapabilityPage.js => WriteCapabilityPage.tsx} (52%) diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index 7abf6db1769d..3c9c3aba11b7 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -486,7 +486,7 @@ type OnyxValues = { [ONYXKEYS.FORMS.PROFILE_SETTINGS_FORM_DRAFT]: OnyxTypes.Form; [ONYXKEYS.FORMS.DISPLAY_NAME_FORM]: OnyxTypes.DisplayNameForm; [ONYXKEYS.FORMS.DISPLAY_NAME_FORM_DRAFT]: OnyxTypes.DisplayNameForm; - [ONYXKEYS.FORMS.ROOM_NAME_FORM]: OnyxTypes.Form; + [ONYXKEYS.FORMS.ROOM_NAME_FORM]: OnyxTypes.RoomNameForm; [ONYXKEYS.FORMS.ROOM_NAME_FORM_DRAFT]: OnyxTypes.Form; [ONYXKEYS.FORMS.WELCOME_MESSAGE_FORM]: OnyxTypes.Form; [ONYXKEYS.FORMS.WELCOME_MESSAGE_FORM_DRAFT]: OnyxTypes.Form; diff --git a/src/components/DisplayNames/types.ts b/src/components/DisplayNames/types.ts index 2e6f36d5cc07..7da1819c9f01 100644 --- a/src/components/DisplayNames/types.ts +++ b/src/components/DisplayNames/types.ts @@ -20,7 +20,7 @@ type DisplayNamesProps = { fullTitle: string; /** Array of objects that map display names to their corresponding tooltip */ - displayNamesWithTooltips: DisplayNameWithTooltip[]; + displayNamesWithTooltips?: DisplayNameWithTooltip[]; /** Number of lines before wrapping */ numberOfLines: number; diff --git a/src/languages/en.ts b/src/languages/en.ts index 8a959b5da550..80c73f547e99 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -673,6 +673,7 @@ export default { always: 'Immediately', daily: 'Daily', mute: 'Mute', + hidden: 'Hidden', }, }, loginField: { diff --git a/src/libs/ErrorUtils.ts b/src/libs/ErrorUtils.ts index 18aa262c2079..29db104c322d 100644 --- a/src/libs/ErrorUtils.ts +++ b/src/libs/ErrorUtils.ts @@ -101,7 +101,7 @@ type ErrorsList = Record; * @param errors - An object containing current errors in the form * @param message - Message to assign to the inputID errors */ -function addErrorMessage(errors: ErrorsList, inputID?: string, message?: TKey) { +function addErrorMessage(errors: ErrorsList, inputID?: string, message?: TKey | [TKey, Record] ) { if (!message || !inputID) { return; } diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index b8ed62f93082..0d406bd78bd9 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -110,7 +110,7 @@ function isExpensifyGuideTeam(email: string): boolean { /** * Checks if the current user is an admin of the policy. */ -const isPolicyAdmin = (policy: OnyxEntry): 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/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index fa51ca06e68e..eef3e894e4ec 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4222,7 +4222,7 @@ function getWorkspaceChats(policyID: string, accountIDs: number[]): Array, policy: OnyxEntry): boolean { +function shouldDisableRename(report: OnyxEntry, policy?: OnyxEntry): boolean { if (isDefaultRoom(report) || isArchivedRoom(report) || isThread(report) || isMoneyRequestReport(report) || isPolicyExpenseChat(report)) { return true; } @@ -4241,7 +4241,7 @@ function shouldDisableRename(report: OnyxEntry, policy: OnyxEntry, policy: OnyxEntry): boolean { +function canEditWriteCapability(report: OnyxEntry, policy?: OnyxEntry): boolean { return PolicyUtils.isPolicyAdmin(policy) && !isAdminRoom(report) && !isArchivedRoom(report) && !isThread(report); } @@ -4499,7 +4499,7 @@ function getRoom(type: ValueOf, policyID: string) /** * We only want policy owners and admins to be able to modify the welcome message, but not in thread chat. */ -function shouldDisableWelcomeMessage(report: OnyxEntry, policy: OnyxEntry): boolean { +function shouldDisableWelcomeMessage(report: OnyxEntry, policy?: OnyxEntry): boolean { return isMoneyRequestReport(report) || isArchivedRoom(report) || !isChatRoom(report) || isChatThread(report) || !PolicyUtils.isPolicyAdmin(policy); } /** diff --git a/src/libs/ValidationUtils.ts b/src/libs/ValidationUtils.ts index 7eff51c354df..ee8234f946c1 100644 --- a/src/libs/ValidationUtils.ts +++ b/src/libs/ValidationUtils.ts @@ -11,6 +11,7 @@ import DateUtils from './DateUtils'; import * as LoginUtils from './LoginUtils'; import {parsePhoneNumber} from './PhoneNumber'; import StringUtils from './StringUtils'; +import type {OnyxCollection} from "react-native-onyx"; /** * Implements the Luhn Algorithm, a checksum formula used to validate credit card @@ -354,8 +355,8 @@ function isReservedRoomName(roomName: string): boolean { /** * Checks if the room name already exists. */ -function isExistingRoomName(roomName: string, reports: Record, policyID: string): boolean { - return Object.values(reports).some((report) => report && report.policyID === policyID && report.reportName === roomName); +function isExistingRoomName(roomName: string, reports: OnyxCollection, policyID?: string): boolean { + return Object.values(reports ?? {}).some((report) => report && report.policyID === policyID && report.reportName === roomName); } /** diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index e084a99df0c7..54f20e672e5b 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -1729,7 +1729,7 @@ function navigateToConciergeChatAndDeleteReport(reportID: string) { /** * @param policyRoomName The updated name for the policy room */ -function updatePolicyRoomNameAndNavigate(policyRoomReport: Report, policyRoomName: string) { +function updatePolicyRoomNameAndNavigate(policyRoomReport: Report, policyRoomName?: string) { const reportID = policyRoomReport.reportID; const previousName = policyRoomReport.reportName; @@ -1777,7 +1777,7 @@ function updatePolicyRoomNameAndNavigate(policyRoomReport: Report, policyRoomNam type UpdatePolicyRoomNameParameters = { reportID: string; - policyRoomName: string; + policyRoomName?: string; }; const parameters: UpdatePolicyRoomNameParameters = {reportID, policyRoomName}; diff --git a/src/pages/home/report/withReportOrNotFound.tsx b/src/pages/home/report/withReportOrNotFound.tsx index 7613bafeacdc..a8facc3e1c76 100644 --- a/src/pages/home/report/withReportOrNotFound.tsx +++ b/src/pages/home/report/withReportOrNotFound.tsx @@ -22,16 +22,16 @@ type OnyxProps = { isLoadingReportData: OnyxEntry; }; -type ComponentProps = OnyxProps & { +type WithReportOrNotFoundProps = OnyxProps & { route: RouteProp<{params: {reportID: string}}>; }; export default function ( shouldRequireReportID = true, -): ( +): ( WrappedComponent: React.ComponentType>, ) => React.ComponentType, keyof OnyxProps>> { - return function (WrappedComponent: ComponentType>) { + return function (WrappedComponent: ComponentType>) { function WithReportOrNotFound(props: TProps, ref: ForwardedRef) { const contentShown = React.useRef(false); @@ -89,3 +89,5 @@ export default function ( })(React.forwardRef(WithReportOrNotFound)); }; } + +export type {WithReportOrNotFoundProps}; diff --git a/src/pages/settings/Report/NotificationPreferencePage.js b/src/pages/settings/Report/NotificationPreferencePage.js deleted file mode 100644 index c6044bd81efe..000000000000 --- a/src/pages/settings/Report/NotificationPreferencePage.js +++ /dev/null @@ -1,59 +0,0 @@ -import React from 'react'; -import _ from 'underscore'; -import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; -import HeaderWithBackButton from '@components/HeaderWithBackButton'; -import ScreenWrapper from '@components/ScreenWrapper'; -import SelectionList from '@components/SelectionList'; -import withLocalize, {withLocalizePropTypes} from '@components/withLocalize'; -import compose from '@libs/compose'; -import * as ReportUtils from '@libs/ReportUtils'; -import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; -import reportPropTypes from '@pages/reportPropTypes'; -import * as Report from '@userActions/Report'; -import CONST from '@src/CONST'; - -const propTypes = { - ...withLocalizePropTypes, - - /** The report for which we are setting notification preferences */ - report: reportPropTypes.isRequired, -}; - -function NotificationPreferencePage(props) { - const shouldDisableNotificationPreferences = ReportUtils.isArchivedRoom(props.report); - const notificationPreferenceOptions = _.map( - _.filter(_.values(CONST.REPORT.NOTIFICATION_PREFERENCE), (pref) => pref !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN), - (preference) => ({ - value: preference, - text: props.translate(`notificationPreferencesPage.notificationPreferences.${preference}`), - keyForList: preference, - isSelected: preference === props.report.notificationPreference, - }), - ); - - return ( - - - ReportUtils.goBackToDetailsPage(props.report)} - /> - - Report.updateNotificationPreference(props.report.reportID, props.report.notificationPreference, option.value, true, undefined, undefined, props.report) - } - initiallyFocusedOptionKey={_.find(notificationPreferenceOptions, (locale) => locale.isSelected).keyForList} - /> - - - ); -} - -NotificationPreferencePage.displayName = 'NotificationPreferencePage'; -NotificationPreferencePage.propTypes = propTypes; - -export default compose(withLocalize, withReportOrNotFound())(NotificationPreferencePage); diff --git a/src/pages/settings/Report/NotificationPreferencePage.tsx b/src/pages/settings/Report/NotificationPreferencePage.tsx new file mode 100644 index 000000000000..8d3ed23f6845 --- /dev/null +++ b/src/pages/settings/Report/NotificationPreferencePage.tsx @@ -0,0 +1,55 @@ +import React from 'react'; +import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; +import HeaderWithBackButton from '@components/HeaderWithBackButton'; +import ScreenWrapper from '@components/ScreenWrapper'; +import SelectionList from '@components/SelectionList'; +import * as ReportUtils from '@libs/ReportUtils'; +import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; +import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound'; +import * as ReportActions from '@userActions/Report'; +import CONST from '@src/CONST'; +import useLocalize from "@hooks/useLocalize"; +import type {Report} from '@src/types/onyx'; + +type NotificationPreferencePageProps = WithReportOrNotFoundProps & { + report: Report; +} + +function NotificationPreferencePage({report}:NotificationPreferencePageProps) { + const {translate} = useLocalize() + const shouldDisableNotificationPreferences = ReportUtils.isArchivedRoom(report); + const notificationPreferenceOptions = + Object.values(CONST.REPORT.NOTIFICATION_PREFERENCE).filter((pref) => pref !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) + .map((preference) => ({ + value: preference, + text: translate(`notificationPreferencesPage.notificationPreferences.${preference}`), + keyForList: preference, + isSelected: preference === report.notificationPreference, + }) + ); + + return ( + + + ReportUtils.goBackToDetailsPage(report)} + /> + + ReportActions.updateNotificationPreference(report.reportID, report.notificationPreference, option.value, true, undefined, undefined, report) + } + initiallyFocusedOptionKey={Object.values(notificationPreferenceOptions ?? {}).find((locale) => locale.isSelected)?.keyForList} + /> + + + ); +} + +NotificationPreferencePage.displayName = 'NotificationPreferencePage'; + +export default withReportOrNotFound()(NotificationPreferencePage); diff --git a/src/pages/settings/Report/ReportSettingsPage.js b/src/pages/settings/Report/ReportSettingsPage.tsx similarity index 78% rename from src/pages/settings/Report/ReportSettingsPage.js rename to src/pages/settings/Report/ReportSettingsPage.tsx index c7cfd9c7850d..7d4598d549ff 100644 --- a/src/pages/settings/Report/ReportSettingsPage.js +++ b/src/pages/settings/Report/ReportSettingsPage.tsx @@ -1,9 +1,6 @@ -import lodashGet from 'lodash/get'; -import PropTypes from 'prop-types'; +import isEmpty from 'lodash/isEmpty'; import React, {useMemo} from 'react'; import {ScrollView, View} from 'react-native'; -import {withOnyx} from 'react-native-onyx'; -import _ from 'underscore'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; import DisplayNames from '@components/DisplayNames'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; @@ -15,71 +12,46 @@ import ScreenWrapper from '@components/ScreenWrapper'; import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; -import compose from '@libs/compose'; import {getGroupChatName} from '@libs/GroupChatUtils'; import Navigation from '@libs/Navigation/Navigation'; import * as ReportUtils from '@libs/ReportUtils'; import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; -import reportPropTypes from '@pages/reportPropTypes'; -import * as Report from '@userActions/Report'; +import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound'; +import * as ReportActions from '@userActions/Report'; import CONST from '@src/CONST'; -import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import type {Report} from '@src/types/onyx'; -const propTypes = { - /** Route params */ - route: PropTypes.shape({ - params: PropTypes.shape({ - /** Report ID passed via route r/:reportID/settings */ - reportID: PropTypes.string, - }), - }).isRequired, - /* Onyx Props */ - - /** The active report */ - report: reportPropTypes.isRequired, - - /** The policies which the user has access to and which the report could be tied to */ - policies: PropTypes.shape({ - /** The policy name */ - name: PropTypes.string, - - /** ID of the policy */ - id: PropTypes.string, - }), -}; - -const defaultProps = { - policies: {}, -}; +type ReportSettingsPageProps = WithReportOrNotFoundProps & { + report: Report +} -function ReportSettingsPage(props) { +function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { const styles = useThemeStyles(); - const {report, policies} = props; const {translate} = useLocalize(); // The workspace the report is on, null if the user isn't a member of the workspace - const linkedWorkspace = useMemo(() => _.find(policies, (policy) => policy && policy.id === report.policyID), [policies, report.policyID]); + const linkedWorkspace = useMemo(() => Object.values(policies ?? {}).find( (policy) => policy && policy.id === report.policyID), [policies, report.policyID]); const shouldDisableRename = useMemo(() => ReportUtils.shouldDisableRename(report, linkedWorkspace), [report, linkedWorkspace]); const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); // 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 = isEmpty(report) || ReportUtils.isArchivedRoom(report); const shouldShowRoomName = !ReportUtils.isPolicyExpenseChat(report) && !ReportUtils.isChatThread(report); const notificationPreference = - report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN + report.notificationPreference && report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN ? translate(`notificationPreferencesPage.notificationPreferences.${report.notificationPreference}`) : ''; - const writeCapability = ReportUtils.isAdminRoom(report) ? CONST.REPORT.WRITE_CAPABILITIES.ADMINS : report.writeCapability || CONST.REPORT.WRITE_CAPABILITIES.ALL; + const writeCapability = ReportUtils.isAdminRoom(report) ? CONST.REPORT.WRITE_CAPABILITIES.ADMINS : report.writeCapability ?? CONST.REPORT.WRITE_CAPABILITIES.ALL; const writeCapabilityText = translate(`writeCapabilityPage.writeCapability.${writeCapability}`); const shouldAllowWriteCapabilityEditing = useMemo(() => ReportUtils.canEditWriteCapability(report, linkedWorkspace), [report, linkedWorkspace]); const shouldShowNotificationPref = !isMoneyRequestReport && report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; const roomNameLabel = translate(isMoneyRequestReport ? 'workspace.editor.nameInputLabel' : 'newRoomPage.roomName'); - const reportName = ReportUtils.isGroupChat(props.report) ? getGroupChatName(props.report) : ReportUtils.getReportName(props.report); + const reportName = ReportUtils.isGroupChat(report) ? getGroupChatName(report) : ReportUtils.getReportName(report); const shouldShowWriteCapability = !isMoneyRequestReport; @@ -101,10 +73,10 @@ function ReportSettingsPage(props) { )} {shouldShowRoomName && ( Report.clearPolicyRoomNameErrors(report.reportID)} + onClose={() => ReportActions.clearPolicyRoomNameErrors(report.reportID)} > {shouldDisableRename ? ( @@ -115,7 +87,7 @@ function ReportSettingsPage(props) { {roomNameLabel} - {translate(`newRoomPage.visibilityOptions.${report.visibility}`)} + {report.visibility && translate(`newRoomPage.visibilityOptions.${report.visibility}`)} - {translate(`newRoomPage.${report.visibility}Description`)} + {report.visibility && translate(`newRoomPage.${report.visibility}Description`)} )} @@ -206,14 +178,6 @@ function ReportSettingsPage(props) { ); } -ReportSettingsPage.propTypes = propTypes; -ReportSettingsPage.defaultProps = defaultProps; ReportSettingsPage.displayName = 'ReportSettingsPage'; -export default compose( - withReportOrNotFound(), - withOnyx({ - policies: { - key: ONYXKEYS.COLLECTION.POLICY, - }, - }), -)(ReportSettingsPage); + +export default withReportOrNotFound()(ReportSettingsPage); diff --git a/src/pages/settings/Report/RoomNamePage.js b/src/pages/settings/Report/RoomNamePage.tsx similarity index 80% rename from src/pages/settings/Report/RoomNamePage.js rename to src/pages/settings/Report/RoomNamePage.tsx index 5f64faca50fc..793fb04ca68c 100644 --- a/src/pages/settings/Report/RoomNamePage.js +++ b/src/pages/settings/Report/RoomNamePage.tsx @@ -1,15 +1,14 @@ import {useIsFocused} from '@react-navigation/native'; -import PropTypes from 'prop-types'; import React, {useCallback, useRef} from 'react'; import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; +import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; import FormProvider from '@components/Form/FormProvider'; import InputWrapper from '@components/Form/InputWrapper'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import RoomNameInput from '@components/RoomNameInput'; import ScreenWrapper from '@components/ScreenWrapper'; -import withLocalize, {withLocalizePropTypes} from '@components/withLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import compose from '@libs/compose'; import * as ErrorUtils from '@libs/ErrorUtils'; @@ -17,39 +16,37 @@ import Navigation from '@libs/Navigation/Navigation'; import * as ReportUtils from '@libs/ReportUtils'; import * as ValidationUtils from '@libs/ValidationUtils'; import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; -import reportPropTypes from '@pages/reportPropTypes'; -import * as Report from '@userActions/Report'; +import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound'; +import * as ReportActions from '@userActions/Report'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import useLocalize from "@hooks/useLocalize"; +import type {Policy, Report} from "@src/types/onyx"; +import type {OnyxFormValuesFields} from "@components/Form/types"; +import type {AnimatedTextInputRef} from "@components/RNTextInput"; -const propTypes = { - ...withLocalizePropTypes, - - /** The room report for which the name is being edited */ - report: reportPropTypes.isRequired, - +type RoomNamePageOnyxProps = { /** All reports shared with the user */ - reports: PropTypes.objectOf(reportPropTypes), + reports: OnyxCollection, /** Policy of the report for which the name is being edited */ - policy: PropTypes.shape({ - role: PropTypes.string, - owner: PropTypes.string, - }), -}; -const defaultProps = { - reports: {}, - policy: {}, + policy: OnyxEntry +} + +type RoomNamePageProps = RoomNamePageOnyxProps & WithReportOrNotFoundProps & { + /** The room report for which the name is being edited */ + report: Report }; -function RoomNamePage({policy, report, reports, translate}) { +function RoomNamePage({ report, policy, reports }: RoomNamePageProps) { const styles = useThemeStyles(); - const roomNameInputRef = useRef(null); + const roomNameInputRef = useRef(null); const isFocused = useIsFocused(); + const {translate} = useLocalize() const validate = useCallback( - (values) => { + (values: OnyxFormValuesFields) => { const errors = {}; // We should skip validation hence we return an empty errors and we skip Form submission on the onSubmit method @@ -78,7 +75,7 @@ function RoomNamePage({policy, report, reports, translate}) { return ( roomNameInputRef.current && roomNameInputRef.current.focus()} + onEntryTransitionEnd={() => roomNameInputRef.current?.focus()} includeSafeAreaPaddingBottom={false} testID={RoomNamePage.displayName} > @@ -90,7 +87,7 @@ function RoomNamePage({policy, report, reports, translate}) { Report.updatePolicyRoomNameAndNavigate(report, values.roomName)} + onSubmit={(values) => ReportActions.updatePolicyRoomNameAndNavigate(report, values.roomName)} validate={validate} submitButtonText={translate('common.save')} enabledWhenOffline @@ -110,14 +107,10 @@ function RoomNamePage({policy, report, reports, translate}) { ); } -RoomNamePage.propTypes = propTypes; -RoomNamePage.defaultProps = defaultProps; RoomNamePage.displayName = 'RoomNamePage'; export default compose( - withLocalize, - withReportOrNotFound(), - withOnyx({ + withOnyx({ reports: { key: ONYXKEYS.COLLECTION.REPORT, }, @@ -125,4 +118,6 @@ export default compose( key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, }, }), + withReportOrNotFound(), + )(RoomNamePage); diff --git a/src/pages/settings/Report/WriteCapabilityPage.js b/src/pages/settings/Report/WriteCapabilityPage.tsx similarity index 52% rename from src/pages/settings/Report/WriteCapabilityPage.js rename to src/pages/settings/Report/WriteCapabilityPage.tsx index fc587b028f7d..244a47fee113 100644 --- a/src/pages/settings/Report/WriteCapabilityPage.js +++ b/src/pages/settings/Report/WriteCapabilityPage.tsx @@ -1,43 +1,43 @@ import React from 'react'; import {withOnyx} from 'react-native-onyx'; -import _ from 'underscore'; +import type {OnyxEntry} from 'react-native-onyx'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; import SelectionList from '@components/SelectionList'; -import withLocalize, {withLocalizePropTypes} from '@components/withLocalize'; import compose from '@libs/compose'; import Navigation from '@libs/Navigation/Navigation'; import * as ReportUtils from '@libs/ReportUtils'; import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; -import reportPropTypes from '@pages/reportPropTypes'; -import {policyDefaultProps, policyPropTypes} from '@pages/workspace/withPolicy'; -import * as Report from '@userActions/Report'; +import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound'; +import * as ReportActions from '@userActions/Report'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import useLocalize from "@hooks/useLocalize"; +import type {Policy, Report} from "@src/types/onyx"; -const propTypes = { - ...withLocalizePropTypes, - ...policyPropTypes, +type WriteCapabilityPageOnyxProps = { + /** The policy object for the current route */ + policy: OnyxEntry; +}; +type WriteCapabilityPageProps = WriteCapabilityPageOnyxProps & WithReportOrNotFoundProps & { /** The report for which we are setting write capability */ - report: reportPropTypes.isRequired, + report: Report, }; -const defaultProps = { - ...policyDefaultProps, -}; -function WriteCapabilityPage(props) { - const writeCapabilityOptions = _.map(CONST.REPORT.WRITE_CAPABILITIES, (value) => ({ +function WriteCapabilityPage({report, policy}: WriteCapabilityPageProps) { + const {translate} = useLocalize() + const writeCapabilityOptions = Object.values(CONST.REPORT.WRITE_CAPABILITIES).map((value) => ({ value, - text: props.translate(`writeCapabilityPage.writeCapability.${value}`), + text: translate(`writeCapabilityPage.writeCapability.${value}`), keyForList: value, - isSelected: value === (props.report.writeCapability || CONST.REPORT.WRITE_CAPABILITIES.ALL), + isSelected: value === (report.writeCapability ?? CONST.REPORT.WRITE_CAPABILITIES.ALL), })); - const isAbleToEdit = ReportUtils.canEditWriteCapability(props.report, props.policy); + const isAbleToEdit = ReportUtils.canEditWriteCapability(report, policy); return ( Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(props.report.reportID))} + onBackButtonPress={() => Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(report.reportID))} /> Report.updateWriteCapabilityAndNavigate(props.report, option.value)} - initiallyFocusedOptionKey={_.find(writeCapabilityOptions, (locale) => locale.isSelected).keyForList} + onSelectRow={(option) => ReportActions.updateWriteCapabilityAndNavigate(report, option.value)} + initiallyFocusedOptionKey={Object.values(writeCapabilityOptions).find((locale) => locale.isSelected)?.keyForList} /> @@ -61,15 +61,12 @@ function WriteCapabilityPage(props) { } WriteCapabilityPage.displayName = 'WriteCapabilityPage'; -WriteCapabilityPage.propTypes = propTypes; -WriteCapabilityPage.defaultProps = defaultProps; export default compose( - withLocalize, - withReportOrNotFound(), - withOnyx({ + withOnyx({ policy: { key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, }, }), + withReportOrNotFound(), )(WriteCapabilityPage); diff --git a/src/types/onyx/Form.ts b/src/types/onyx/Form.ts index c3bcec2a2d3b..142984d7f4b1 100644 --- a/src/types/onyx/Form.ts +++ b/src/types/onyx/Form.ts @@ -54,6 +54,10 @@ type PrivateNotesForm = Form<{ privateNotes: string; }>; +type RoomNameForm = Form<{ + roomName?: string; +}>; + export default Form; -export type {AddDebitCardForm, DateOfBirthForm, PrivateNotesForm, DisplayNameForm, FormValueType, NewRoomForm, BaseForm, IKnowATeacherForm, IntroSchoolPrincipalForm}; +export type {AddDebitCardForm, DateOfBirthForm, PrivateNotesForm, DisplayNameForm, FormValueType, NewRoomForm, BaseForm, IKnowATeacherForm, IntroSchoolPrincipalForm, RoomNameForm}; diff --git a/src/types/onyx/index.ts b/src/types/onyx/index.ts index 5b04cae58671..a003b8d87e87 100644 --- a/src/types/onyx/index.ts +++ b/src/types/onyx/index.ts @@ -9,7 +9,7 @@ import type Credentials from './Credentials'; import type Currency from './Currency'; import type CustomStatusDraft from './CustomStatusDraft'; import type Download from './Download'; -import type {AddDebitCardForm, DateOfBirthForm, DisplayNameForm, IKnowATeacherForm, IntroSchoolPrincipalForm, NewRoomForm, PrivateNotesForm} from './Form'; +import type {AddDebitCardForm, DateOfBirthForm, DisplayNameForm, IKnowATeacherForm, IntroSchoolPrincipalForm, NewRoomForm, PrivateNotesForm, RoomNameForm} from './Form'; import type Form from './Form'; import type FrequentlyUsedEmoji from './FrequentlyUsedEmoji'; import type {FundList} from './Fund'; @@ -151,4 +151,5 @@ export type { IKnowATeacherForm, IntroSchoolPrincipalForm, PrivateNotesForm, + RoomNameForm }; From 853932d0963bd48fe779b706d16c0bd95c6b061c Mon Sep 17 00:00:00 2001 From: Shahe Shahinyan Date: Mon, 29 Jan 2024 20:51:12 +0400 Subject: [PATCH 02/15] Fix screens crash --- src/pages/settings/Report/RoomNamePage.tsx | 2 +- src/pages/settings/Report/WriteCapabilityPage.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/settings/Report/RoomNamePage.tsx b/src/pages/settings/Report/RoomNamePage.tsx index 793fb04ca68c..091db8f247f6 100644 --- a/src/pages/settings/Report/RoomNamePage.tsx +++ b/src/pages/settings/Report/RoomNamePage.tsx @@ -110,6 +110,7 @@ function RoomNamePage({ report, policy, reports }: RoomNamePageProps) { RoomNamePage.displayName = 'RoomNamePage'; export default compose( + withReportOrNotFound(), withOnyx({ reports: { key: ONYXKEYS.COLLECTION.REPORT, @@ -118,6 +119,5 @@ export default compose( key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, }, }), - withReportOrNotFound(), )(RoomNamePage); diff --git a/src/pages/settings/Report/WriteCapabilityPage.tsx b/src/pages/settings/Report/WriteCapabilityPage.tsx index 244a47fee113..b4de7518f7ba 100644 --- a/src/pages/settings/Report/WriteCapabilityPage.tsx +++ b/src/pages/settings/Report/WriteCapabilityPage.tsx @@ -63,10 +63,10 @@ function WriteCapabilityPage({report, policy}: WriteCapabilityPageProps) { WriteCapabilityPage.displayName = 'WriteCapabilityPage'; export default compose( + withReportOrNotFound(), withOnyx({ policy: { key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, }, }), - withReportOrNotFound(), )(WriteCapabilityPage); From b544a69c5066a160919f246889f50b7dd112c78d Mon Sep 17 00:00:00 2001 From: Shahe Shahinyan Date: Mon, 29 Jan 2024 20:58:08 +0400 Subject: [PATCH 03/15] add translation key for es --- src/languages/es.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/languages/es.ts b/src/languages/es.ts index 16686f54f1e1..f99765a66673 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -668,6 +668,7 @@ export default { always: 'Inmediatamente', daily: 'Cada día', mute: 'Nunca', + hidden: 'Oculta', }, }, loginField: { From ff010eb9ffb9cec9248c3a5a4c7cec8a5876daf8 Mon Sep 17 00:00:00 2001 From: Shahe Shahinyan Date: Mon, 29 Jan 2024 21:19:53 +0400 Subject: [PATCH 04/15] Fix TS and lint errors --- src/libs/ValidationUtils.ts | 2 +- src/libs/actions/Report.ts | 2 +- src/pages/settings/Report/RoomNamePage.tsx | 8 +++----- src/pages/settings/Report/WriteCapabilityPage.tsx | 7 +++---- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/libs/ValidationUtils.ts b/src/libs/ValidationUtils.ts index ee8234f946c1..bc5caa92bbbd 100644 --- a/src/libs/ValidationUtils.ts +++ b/src/libs/ValidationUtils.ts @@ -6,12 +6,12 @@ import isObject from 'lodash/isObject'; import CONST from '@src/CONST'; import type {Report} from '@src/types/onyx'; import type * as OnyxCommon from '@src/types/onyx/OnyxCommon'; +import type {OnyxCollection} from "react-native-onyx"; import * as CardUtils from './CardUtils'; import DateUtils from './DateUtils'; import * as LoginUtils from './LoginUtils'; import {parsePhoneNumber} from './PhoneNumber'; import StringUtils from './StringUtils'; -import type {OnyxCollection} from "react-native-onyx"; /** * Implements the Luhn Algorithm, a checksum formula used to validate credit card diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 6222c09a898e..f2744f8a8269 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -1673,7 +1673,7 @@ function navigateToConciergeChatAndDeleteReport(reportID: string) { /** * @param policyRoomName The updated name for the policy room */ -function updatePolicyRoomNameAndNavigate(policyRoomReport: Report, policyRoomName: string) { +function updatePolicyRoomNameAndNavigate(policyRoomReport: Report, policyRoomName?: string) { const reportID = policyRoomReport.reportID; const previousName = policyRoomReport.reportName; diff --git a/src/pages/settings/Report/RoomNamePage.tsx b/src/pages/settings/Report/RoomNamePage.tsx index 091db8f247f6..1daf20013731 100644 --- a/src/pages/settings/Report/RoomNamePage.tsx +++ b/src/pages/settings/Report/RoomNamePage.tsx @@ -109,8 +109,7 @@ function RoomNamePage({ report, policy, reports }: RoomNamePageProps) { RoomNamePage.displayName = 'RoomNamePage'; -export default compose( - withReportOrNotFound(), +export default withReportOrNotFound()( withOnyx({ reports: { key: ONYXKEYS.COLLECTION.REPORT, @@ -118,6 +117,5 @@ export default compose( policy: { key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, }, - }), - -)(RoomNamePage); + })(RoomNamePage) +); diff --git a/src/pages/settings/Report/WriteCapabilityPage.tsx b/src/pages/settings/Report/WriteCapabilityPage.tsx index b4de7518f7ba..14526ba3c0ac 100644 --- a/src/pages/settings/Report/WriteCapabilityPage.tsx +++ b/src/pages/settings/Report/WriteCapabilityPage.tsx @@ -62,11 +62,10 @@ function WriteCapabilityPage({report, policy}: WriteCapabilityPageProps) { WriteCapabilityPage.displayName = 'WriteCapabilityPage'; -export default compose( - withReportOrNotFound(), +export default withReportOrNotFound()( withOnyx({ policy: { key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, }, - }), -)(WriteCapabilityPage); + })(WriteCapabilityPage), +); From 52670ab458bfa5ca6ef9354db8287c08915c4312 Mon Sep 17 00:00:00 2001 From: Shahe Shahinyan Date: Mon, 29 Jan 2024 21:31:52 +0400 Subject: [PATCH 05/15] Fix Ts error --- src/components/DisplayNames/DisplayNamesWithTooltip.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/DisplayNames/DisplayNamesWithTooltip.tsx b/src/components/DisplayNames/DisplayNamesWithTooltip.tsx index ce0ae7ddcf4f..1cacb0e20c5d 100644 --- a/src/components/DisplayNames/DisplayNamesWithTooltip.tsx +++ b/src/components/DisplayNames/DisplayNamesWithTooltip.tsx @@ -56,7 +56,7 @@ function DisplayNamesWithToolTip({shouldUseFullTitle, fullTitle, displayNamesWit > {shouldUseFullTitle ? ReportUtils.formatReportLastMessageText(fullTitle) - : displayNamesWithTooltips.map(({displayName, accountID, avatar, login}, index) => ( + : displayNamesWithTooltips?.map(({displayName, accountID, avatar, login}, index) => ( // eslint-disable-next-line react/no-array-index-key Date: Mon, 29 Jan 2024 21:41:25 +0400 Subject: [PATCH 06/15] Fix lint errors --- src/pages/settings/Report/RoomNamePage.tsx | 1 - src/pages/settings/Report/WriteCapabilityPage.tsx | 1 - 2 files changed, 2 deletions(-) diff --git a/src/pages/settings/Report/RoomNamePage.tsx b/src/pages/settings/Report/RoomNamePage.tsx index 1daf20013731..a3e24de4c325 100644 --- a/src/pages/settings/Report/RoomNamePage.tsx +++ b/src/pages/settings/Report/RoomNamePage.tsx @@ -10,7 +10,6 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton'; import RoomNameInput from '@components/RoomNameInput'; import ScreenWrapper from '@components/ScreenWrapper'; import useThemeStyles from '@hooks/useThemeStyles'; -import compose from '@libs/compose'; import * as ErrorUtils from '@libs/ErrorUtils'; import Navigation from '@libs/Navigation/Navigation'; import * as ReportUtils from '@libs/ReportUtils'; diff --git a/src/pages/settings/Report/WriteCapabilityPage.tsx b/src/pages/settings/Report/WriteCapabilityPage.tsx index 14526ba3c0ac..f03415a2a56f 100644 --- a/src/pages/settings/Report/WriteCapabilityPage.tsx +++ b/src/pages/settings/Report/WriteCapabilityPage.tsx @@ -5,7 +5,6 @@ import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; import SelectionList from '@components/SelectionList'; -import compose from '@libs/compose'; import Navigation from '@libs/Navigation/Navigation'; import * as ReportUtils from '@libs/ReportUtils'; import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; From fe014b76fefdb9c68718a587dfb223a6d4860fa3 Mon Sep 17 00:00:00 2001 From: Shahe Shahinyan Date: Mon, 29 Jan 2024 21:46:15 +0400 Subject: [PATCH 07/15] Run prettier --- src/libs/ErrorUtils.ts | 2 +- src/libs/ValidationUtils.ts | 2 +- .../Report/NotificationPreferencePage.tsx | 19 +++++------- .../settings/Report/ReportSettingsPage.tsx | 9 +++--- src/pages/settings/Report/RoomNamePage.tsx | 31 ++++++++++--------- .../settings/Report/WriteCapabilityPage.tsx | 18 +++++------ src/types/onyx/index.ts | 2 +- 7 files changed, 40 insertions(+), 43 deletions(-) diff --git a/src/libs/ErrorUtils.ts b/src/libs/ErrorUtils.ts index 9acda5ec722a..8eff66c10751 100644 --- a/src/libs/ErrorUtils.ts +++ b/src/libs/ErrorUtils.ts @@ -101,7 +101,7 @@ type ErrorsList = Record; * @param errors - An object containing current errors in the form * @param message - Message to assign to the inputID errors */ -function addErrorMessage(errors: ErrorsList, inputID?: string, message?: TKey | [TKey, Record] ) { +function addErrorMessage(errors: ErrorsList, inputID?: string, message?: TKey | [TKey, Record]) { if (!message || !inputID) { return; } diff --git a/src/libs/ValidationUtils.ts b/src/libs/ValidationUtils.ts index bc5caa92bbbd..af9e394e0b7f 100644 --- a/src/libs/ValidationUtils.ts +++ b/src/libs/ValidationUtils.ts @@ -3,10 +3,10 @@ import {URL_REGEX_WITH_REQUIRED_PROTOCOL} from 'expensify-common/lib/Url'; import isDate from 'lodash/isDate'; import isEmpty from 'lodash/isEmpty'; import isObject from 'lodash/isObject'; +import type {OnyxCollection} from 'react-native-onyx'; import CONST from '@src/CONST'; import type {Report} from '@src/types/onyx'; import type * as OnyxCommon from '@src/types/onyx/OnyxCommon'; -import type {OnyxCollection} from "react-native-onyx"; import * as CardUtils from './CardUtils'; import DateUtils from './DateUtils'; import * as LoginUtils from './LoginUtils'; diff --git a/src/pages/settings/Report/NotificationPreferencePage.tsx b/src/pages/settings/Report/NotificationPreferencePage.tsx index 8d3ed23f6845..c5fdaa25fac5 100644 --- a/src/pages/settings/Report/NotificationPreferencePage.tsx +++ b/src/pages/settings/Report/NotificationPreferencePage.tsx @@ -3,30 +3,29 @@ import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; import SelectionList from '@components/SelectionList'; +import useLocalize from '@hooks/useLocalize'; import * as ReportUtils from '@libs/ReportUtils'; import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound'; import * as ReportActions from '@userActions/Report'; import CONST from '@src/CONST'; -import useLocalize from "@hooks/useLocalize"; import type {Report} from '@src/types/onyx'; type NotificationPreferencePageProps = WithReportOrNotFoundProps & { report: Report; -} +}; -function NotificationPreferencePage({report}:NotificationPreferencePageProps) { - const {translate} = useLocalize() +function NotificationPreferencePage({report}: NotificationPreferencePageProps) { + const {translate} = useLocalize(); const shouldDisableNotificationPreferences = ReportUtils.isArchivedRoom(report); - const notificationPreferenceOptions = - Object.values(CONST.REPORT.NOTIFICATION_PREFERENCE).filter((pref) => pref !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) + const notificationPreferenceOptions = Object.values(CONST.REPORT.NOTIFICATION_PREFERENCE) + .filter((pref) => pref !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) .map((preference) => ({ value: preference, text: translate(`notificationPreferencesPage.notificationPreferences.${preference}`), keyForList: preference, isSelected: preference === report.notificationPreference, - }) - ); + })); return ( - ReportActions.updateNotificationPreference(report.reportID, report.notificationPreference, option.value, true, undefined, undefined, report) - } + onSelectRow={(option) => ReportActions.updateNotificationPreference(report.reportID, report.notificationPreference, option.value, true, undefined, undefined, report)} initiallyFocusedOptionKey={Object.values(notificationPreferenceOptions ?? {}).find((locale) => locale.isSelected)?.keyForList} /> diff --git a/src/pages/settings/Report/ReportSettingsPage.tsx b/src/pages/settings/Report/ReportSettingsPage.tsx index 7d4598d549ff..d6f3a30c9d63 100644 --- a/src/pages/settings/Report/ReportSettingsPage.tsx +++ b/src/pages/settings/Report/ReportSettingsPage.tsx @@ -22,16 +22,15 @@ import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; import type {Report} from '@src/types/onyx'; - type ReportSettingsPageProps = WithReportOrNotFoundProps & { - report: Report -} + report: Report; +}; function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); // The workspace the report is on, null if the user isn't a member of the workspace - const linkedWorkspace = useMemo(() => Object.values(policies ?? {}).find( (policy) => policy && policy.id === report.policyID), [policies, report.policyID]); + const linkedWorkspace = useMemo(() => Object.values(policies ?? {}).find((policy) => policy && policy.id === report.policyID), [policies, report.policyID]); const shouldDisableRename = useMemo(() => ReportUtils.shouldDisableRename(report, linkedWorkspace), [report, linkedWorkspace]); const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); @@ -87,7 +86,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { {roomNameLabel} , + reports: OnyxCollection; /** Policy of the report for which the name is being edited */ - policy: OnyxEntry -} - -type RoomNamePageProps = RoomNamePageOnyxProps & WithReportOrNotFoundProps & { - /** The room report for which the name is being edited */ - report: Report + policy: OnyxEntry; }; -function RoomNamePage({ report, policy, reports }: RoomNamePageProps) { +type RoomNamePageProps = RoomNamePageOnyxProps & + WithReportOrNotFoundProps & { + /** The room report for which the name is being edited */ + report: Report; + }; + +function RoomNamePage({report, policy, reports}: RoomNamePageProps) { const styles = useThemeStyles(); const roomNameInputRef = useRef(null); const isFocused = useIsFocused(); - const {translate} = useLocalize() + const {translate} = useLocalize(); const validate = useCallback( - (values: OnyxFormValuesFields) => { + (values: OnyxFormValuesFields) => { const errors = {}; // We should skip validation hence we return an empty errors and we skip Form submission on the onSubmit method @@ -116,5 +117,5 @@ export default withReportOrNotFound()( policy: { key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, }, - })(RoomNamePage) + })(RoomNamePage), ); diff --git a/src/pages/settings/Report/WriteCapabilityPage.tsx b/src/pages/settings/Report/WriteCapabilityPage.tsx index f03415a2a56f..49accdff8e13 100644 --- a/src/pages/settings/Report/WriteCapabilityPage.tsx +++ b/src/pages/settings/Report/WriteCapabilityPage.tsx @@ -5,6 +5,7 @@ import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; import SelectionList from '@components/SelectionList'; +import useLocalize from '@hooks/useLocalize'; import Navigation from '@libs/Navigation/Navigation'; import * as ReportUtils from '@libs/ReportUtils'; import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; @@ -13,22 +14,21 @@ import * as ReportActions from '@userActions/Report'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import useLocalize from "@hooks/useLocalize"; -import type {Policy, Report} from "@src/types/onyx"; +import type {Policy, Report} from '@src/types/onyx'; type WriteCapabilityPageOnyxProps = { /** The policy object for the current route */ - policy: OnyxEntry; -}; - -type WriteCapabilityPageProps = WriteCapabilityPageOnyxProps & WithReportOrNotFoundProps & { - /** The report for which we are setting write capability */ - report: Report, + policy: OnyxEntry; }; +type WriteCapabilityPageProps = WriteCapabilityPageOnyxProps & + WithReportOrNotFoundProps & { + /** The report for which we are setting write capability */ + report: Report; + }; function WriteCapabilityPage({report, policy}: WriteCapabilityPageProps) { - const {translate} = useLocalize() + const {translate} = useLocalize(); const writeCapabilityOptions = Object.values(CONST.REPORT.WRITE_CAPABILITIES).map((value) => ({ value, text: translate(`writeCapabilityPage.writeCapability.${value}`), diff --git a/src/types/onyx/index.ts b/src/types/onyx/index.ts index a003b8d87e87..223681de1521 100644 --- a/src/types/onyx/index.ts +++ b/src/types/onyx/index.ts @@ -151,5 +151,5 @@ export type { IKnowATeacherForm, IntroSchoolPrincipalForm, PrivateNotesForm, - RoomNameForm + RoomNameForm, }; From 17f25fc09548849e11291aef361fcdfa8482d66f Mon Sep 17 00:00:00 2001 From: Shahe Shahinyan Date: Thu, 1 Feb 2024 17:47:11 +0400 Subject: [PATCH 08/15] Addressed to reviewer comments --- src/ONYXKEYS.ts | 2 +- src/languages/es.ts | 2 +- src/libs/PolicyUtils.ts | 2 +- src/libs/ReportUtils.ts | 6 +++--- src/libs/actions/Report.ts | 4 ++-- src/pages/home/report/withReportOrNotFound.tsx | 8 ++++---- src/types/onyx/Form.ts | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index c4f66138cffc..ab5ae384a5be 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -491,7 +491,7 @@ type OnyxValues = { [ONYXKEYS.FORMS.DISPLAY_NAME_FORM]: OnyxTypes.DisplayNameForm; [ONYXKEYS.FORMS.DISPLAY_NAME_FORM_DRAFT]: OnyxTypes.DisplayNameForm; [ONYXKEYS.FORMS.ROOM_NAME_FORM]: OnyxTypes.RoomNameForm; - [ONYXKEYS.FORMS.ROOM_NAME_FORM_DRAFT]: OnyxTypes.Form; + [ONYXKEYS.FORMS.ROOM_NAME_FORM_DRAFT]: OnyxTypes.RoomNameForm; [ONYXKEYS.FORMS.WELCOME_MESSAGE_FORM]: OnyxTypes.Form; [ONYXKEYS.FORMS.WELCOME_MESSAGE_FORM_DRAFT]: OnyxTypes.Form; [ONYXKEYS.FORMS.LEGAL_NAME_FORM]: OnyxTypes.Form; diff --git a/src/languages/es.ts b/src/languages/es.ts index f99765a66673..52e49e75fdd4 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -668,7 +668,7 @@ export default { always: 'Inmediatamente', daily: 'Cada día', mute: 'Nunca', - hidden: 'Oculta', + hidden: 'Oculto', }, }, loginField: { diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 0d406bd78bd9..2f0a6367041d 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -110,7 +110,7 @@ function isExpensifyGuideTeam(email: string): boolean { /** * Checks if the current user is an admin of the policy. */ -const isPolicyAdmin = (policy?: OnyxEntry): boolean => policy?.role === CONST.POLICY.ROLE.ADMIN; +const isPolicyAdmin = (policy: OnyxEntry | undefined): 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/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 40842492eb0a..feb3a1baf3c4 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4199,7 +4199,7 @@ function getWorkspaceChats(policyID: string, accountIDs: number[]): Array, policy?: OnyxEntry): boolean { +function shouldDisableRename(report: OnyxEntry, policy: OnyxEntry | undefined): boolean { if (isDefaultRoom(report) || isArchivedRoom(report) || isThread(report) || isMoneyRequestReport(report) || isPolicyExpenseChat(report)) { return true; } @@ -4218,7 +4218,7 @@ function shouldDisableRename(report: OnyxEntry, policy?: OnyxEntry, policy?: OnyxEntry): boolean { +function canEditWriteCapability(report: OnyxEntry, policy: OnyxEntry | undefined): boolean { return PolicyUtils.isPolicyAdmin(policy) && !isAdminRoom(report) && !isArchivedRoom(report) && !isThread(report); } @@ -4506,7 +4506,7 @@ function getRoom(type: ValueOf, policyID: string) /** * We only want policy owners and admins to be able to modify the welcome message, but not in thread chat. */ -function shouldDisableWelcomeMessage(report: OnyxEntry, policy?: OnyxEntry): boolean { +function shouldDisableWelcomeMessage(report: OnyxEntry, policy: OnyxEntry | undefined): boolean { return isMoneyRequestReport(report) || isArchivedRoom(report) || !isChatRoom(report) || isChatThread(report) || !PolicyUtils.isPolicyAdmin(policy); } /** diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index f2744f8a8269..72fc73fc1d5a 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -1673,7 +1673,7 @@ function navigateToConciergeChatAndDeleteReport(reportID: string) { /** * @param policyRoomName The updated name for the policy room */ -function updatePolicyRoomNameAndNavigate(policyRoomReport: Report, policyRoomName?: string) { +function updatePolicyRoomNameAndNavigate(policyRoomReport: Report, policyRoomName: string | undefined) { const reportID = policyRoomReport.reportID; const previousName = policyRoomReport.reportName; @@ -1719,7 +1719,7 @@ function updatePolicyRoomNameAndNavigate(policyRoomReport: Report, policyRoomNam }, ]; - const parameters: UpdatePolicyRoomNameParams = {reportID, policyRoomName}; + const parameters: UpdatePolicyRoomNameParams = {reportID, policyRoomName: policyRoomName ?? ''}; API.write(WRITE_COMMANDS.UPDATE_POLICY_ROOM_NAME, parameters, {optimisticData, successData, failureData}); Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(reportID)); diff --git a/src/pages/home/report/withReportOrNotFound.tsx b/src/pages/home/report/withReportOrNotFound.tsx index a8facc3e1c76..385280c9d2c2 100644 --- a/src/pages/home/report/withReportOrNotFound.tsx +++ b/src/pages/home/report/withReportOrNotFound.tsx @@ -11,7 +11,7 @@ import NotFoundPage from '@pages/ErrorPage/NotFoundPage'; import ONYXKEYS from '@src/ONYXKEYS'; import type * as OnyxTypes from '@src/types/onyx'; -type OnyxProps = { +type WithReportOrNotFoundOnyxProps = { /** The report currently being looked at */ report: OnyxEntry; /** The policies which the user has access to */ @@ -22,7 +22,7 @@ type OnyxProps = { isLoadingReportData: OnyxEntry; }; -type WithReportOrNotFoundProps = OnyxProps & { +type WithReportOrNotFoundProps = WithReportOrNotFoundOnyxProps & { route: RouteProp<{params: {reportID: string}}>; }; @@ -30,7 +30,7 @@ export default function ( shouldRequireReportID = true, ): ( WrappedComponent: React.ComponentType>, -) => React.ComponentType, keyof OnyxProps>> { +) => React.ComponentType, keyof WithReportOrNotFoundOnyxProps>> { return function (WrappedComponent: ComponentType>) { function WithReportOrNotFound(props: TProps, ref: ForwardedRef) { const contentShown = React.useRef(false); @@ -73,7 +73,7 @@ export default function ( WithReportOrNotFound.displayName = `withReportOrNotFound(${getComponentDisplayName(WrappedComponent)})`; - return withOnyx, OnyxProps>({ + return withOnyx, WithReportOrNotFoundOnyxProps>({ report: { key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.reportID}`, }, diff --git a/src/types/onyx/Form.ts b/src/types/onyx/Form.ts index 142984d7f4b1..6aeeeb72e3a8 100644 --- a/src/types/onyx/Form.ts +++ b/src/types/onyx/Form.ts @@ -55,7 +55,7 @@ type PrivateNotesForm = Form<{ }>; type RoomNameForm = Form<{ - roomName?: string; + roomName: string; }>; export default Form; From 7495142498a18e70e8b21add51272229d7c72964 Mon Sep 17 00:00:00 2001 From: Shahe Shahinyan Date: Thu, 1 Feb 2024 19:44:00 +0400 Subject: [PATCH 09/15] Addressed to reviewer comments --- src/libs/ErrorUtils.ts | 2 +- .../Report/NotificationPreferencePage.tsx | 14 ++++--- .../settings/Report/ReportSettingsPage.tsx | 40 +++++++++---------- src/pages/settings/Report/RoomNamePage.tsx | 22 +++++----- .../settings/Report/WriteCapabilityPage.tsx | 20 +++++----- 5 files changed, 51 insertions(+), 47 deletions(-) diff --git a/src/libs/ErrorUtils.ts b/src/libs/ErrorUtils.ts index 8eff66c10751..f0f94839de21 100644 --- a/src/libs/ErrorUtils.ts +++ b/src/libs/ErrorUtils.ts @@ -101,7 +101,7 @@ type ErrorsList = Record; * @param errors - An object containing current errors in the form * @param message - Message to assign to the inputID errors */ -function addErrorMessage(errors: ErrorsList, inputID?: string, message?: TKey | [TKey, Record]) { +function addErrorMessage(errors: ErrorsList, inputID?: string, message?: TKey | Localize.MaybePhraseKey) { if (!message || !inputID) { return; } diff --git a/src/pages/settings/Report/NotificationPreferencePage.tsx b/src/pages/settings/Report/NotificationPreferencePage.tsx index c5fdaa25fac5..30b9ffa3c2d2 100644 --- a/src/pages/settings/Report/NotificationPreferencePage.tsx +++ b/src/pages/settings/Report/NotificationPreferencePage.tsx @@ -1,3 +1,4 @@ +import type {StackScreenProps} from '@react-navigation/stack'; import React from 'react'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; @@ -5,15 +6,14 @@ import ScreenWrapper from '@components/ScreenWrapper'; import SelectionList from '@components/SelectionList'; import useLocalize from '@hooks/useLocalize'; import * as ReportUtils from '@libs/ReportUtils'; +import type {ReportSettingsNavigatorParamList} from '@navigation/types'; import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound'; import * as ReportActions from '@userActions/Report'; import CONST from '@src/CONST'; -import type {Report} from '@src/types/onyx'; +import type SCREENS from '@src/SCREENS'; -type NotificationPreferencePageProps = WithReportOrNotFoundProps & { - report: Report; -}; +type NotificationPreferencePageProps = WithReportOrNotFoundProps & StackScreenProps; function NotificationPreferencePage({report}: NotificationPreferencePageProps) { const {translate} = useLocalize(); @@ -24,7 +24,7 @@ function NotificationPreferencePage({report}: NotificationPreferencePageProps) { value: preference, text: translate(`notificationPreferencesPage.notificationPreferences.${preference}`), keyForList: preference, - isSelected: preference === report.notificationPreference, + isSelected: preference === report?.notificationPreference, })); return ( @@ -39,7 +39,9 @@ function NotificationPreferencePage({report}: NotificationPreferencePageProps) { /> ReportActions.updateNotificationPreference(report.reportID, report.notificationPreference, option.value, true, undefined, undefined, report)} + onSelectRow={(option) => + ReportActions.updateNotificationPreference(report?.reportID ?? '', report?.notificationPreference, option.value, true, undefined, undefined, report) + } initiallyFocusedOptionKey={Object.values(notificationPreferenceOptions ?? {}).find((locale) => locale.isSelected)?.keyForList} /> diff --git a/src/pages/settings/Report/ReportSettingsPage.tsx b/src/pages/settings/Report/ReportSettingsPage.tsx index d6f3a30c9d63..790f61c0503e 100644 --- a/src/pages/settings/Report/ReportSettingsPage.tsx +++ b/src/pages/settings/Report/ReportSettingsPage.tsx @@ -1,3 +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'; @@ -15,22 +16,21 @@ import useThemeStyles from '@hooks/useThemeStyles'; import {getGroupChatName} from '@libs/GroupChatUtils'; import Navigation from '@libs/Navigation/Navigation'; import * as ReportUtils from '@libs/ReportUtils'; +import type {ReportSettingsNavigatorParamList} from '@navigation/types'; import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound'; import * as ReportActions from '@userActions/Report'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; -import type {Report} from '@src/types/onyx'; +import type SCREENS from '@src/SCREENS'; -type ReportSettingsPageProps = WithReportOrNotFoundProps & { - report: Report; -}; +type ReportSettingsPageProps = WithReportOrNotFoundProps & StackScreenProps; function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); // The workspace the report is on, null if the user isn't a member of the workspace - const linkedWorkspace = useMemo(() => Object.values(policies ?? {}).find((policy) => policy && policy.id === report.policyID), [policies, report.policyID]); + const linkedWorkspace = useMemo(() => Object.values(policies ?? {}).find((policy) => policy && policy.id === report?.policyID), [policies, report?.policyID]); const shouldDisableRename = useMemo(() => ReportUtils.shouldDisableRename(report, linkedWorkspace), [report, linkedWorkspace]); const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); @@ -40,15 +40,15 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { const shouldDisableSettings = isEmpty(report) || ReportUtils.isArchivedRoom(report); const shouldShowRoomName = !ReportUtils.isPolicyExpenseChat(report) && !ReportUtils.isChatThread(report); const notificationPreference = - report.notificationPreference && report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN + report?.notificationPreference && report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN ? translate(`notificationPreferencesPage.notificationPreferences.${report.notificationPreference}`) : ''; - const writeCapability = ReportUtils.isAdminRoom(report) ? CONST.REPORT.WRITE_CAPABILITIES.ADMINS : report.writeCapability ?? CONST.REPORT.WRITE_CAPABILITIES.ALL; + const writeCapability = ReportUtils.isAdminRoom(report) ? CONST.REPORT.WRITE_CAPABILITIES.ADMINS : report?.writeCapability ?? CONST.REPORT.WRITE_CAPABILITIES.ALL; const writeCapabilityText = translate(`writeCapabilityPage.writeCapability.${writeCapability}`); const shouldAllowWriteCapabilityEditing = useMemo(() => ReportUtils.canEditWriteCapability(report, linkedWorkspace), [report, linkedWorkspace]); - const shouldShowNotificationPref = !isMoneyRequestReport && report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; + const shouldShowNotificationPref = !isMoneyRequestReport && report?.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; const roomNameLabel = translate(isMoneyRequestReport ? 'workspace.editor.nameInputLabel' : 'newRoomPage.roomName'); const reportName = ReportUtils.isGroupChat(report) ? getGroupChatName(report) : ReportUtils.getReportName(report); @@ -59,7 +59,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(report.reportID))} + onBackButtonPress={() => Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(report?.reportID ?? ''))} /> {shouldShowNotificationPref && ( @@ -67,15 +67,15 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { shouldShowRightIcon title={notificationPreference} description={translate('notificationPreferencesPage.label')} - onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.getRoute(report.reportID))} + onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.getRoute(report?.reportID ?? ''))} /> )} {shouldShowRoomName && ( ReportActions.clearPolicyRoomNameErrors(report.reportID)} + onClose={() => ReportActions.clearPolicyRoomNameErrors(report?.reportID ?? '')} > {shouldDisableRename ? ( @@ -96,9 +96,9 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { ) : ( Navigation.navigate(ROUTES.REPORT_SETTINGS_ROOM_NAME.getRoute(report.reportID))} + onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_ROOM_NAME.getRoute(report?.reportID ?? ''))} /> )} @@ -109,7 +109,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { shouldShowRightIcon title={writeCapabilityText} description={translate('writeCapabilityPage.label')} - onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_WRITE_CAPABILITY.getRoute(report.reportID))} + onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_WRITE_CAPABILITY.getRoute(report?.reportID ?? ''))} /> ) : ( @@ -145,7 +145,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { /> )} - {Boolean(report.visibility) && ( + {Boolean(report?.visibility) && ( - {report.visibility && translate(`newRoomPage.visibilityOptions.${report.visibility}`)} + {report?.visibility && translate(`newRoomPage.visibilityOptions.${report.visibility}`)} - {report.visibility && translate(`newRoomPage.${report.visibility}Description`)} + {report?.visibility && translate(`newRoomPage.${report.visibility}Description`)} )} @@ -167,7 +167,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { Navigation.navigate(ROUTES.REPORT_WELCOME_MESSAGE.getRoute(report.reportID))} + onPress={() => Navigation.navigate(ROUTES.REPORT_WELCOME_MESSAGE.getRoute(report?.reportID ?? ''))} shouldShowRightIcon /> )} diff --git a/src/pages/settings/Report/RoomNamePage.tsx b/src/pages/settings/Report/RoomNamePage.tsx index 2e4a91e7f861..759147f95d95 100644 --- a/src/pages/settings/Report/RoomNamePage.tsx +++ b/src/pages/settings/Report/RoomNamePage.tsx @@ -1,4 +1,5 @@ import {useIsFocused} from '@react-navigation/native'; +import type {StackScreenProps} from '@react-navigation/stack'; import React, {useCallback, useRef} from 'react'; import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; @@ -17,13 +18,16 @@ import * as ErrorUtils from '@libs/ErrorUtils'; import Navigation from '@libs/Navigation/Navigation'; import * as ReportUtils from '@libs/ReportUtils'; import * as ValidationUtils from '@libs/ValidationUtils'; +import type {ReportSettingsNavigatorParamList} from '@navigation/types'; import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound'; import * as ReportActions from '@userActions/Report'; import CONST from '@src/CONST'; 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 */ @@ -33,11 +37,7 @@ type RoomNamePageOnyxProps = { policy: OnyxEntry; }; -type RoomNamePageProps = RoomNamePageOnyxProps & - WithReportOrNotFoundProps & { - /** The room report for which the name is being edited */ - report: Report; - }; +type RoomNamePageProps = RoomNamePageOnyxProps & WithReportOrNotFoundProps & StackScreenProps; function RoomNamePage({report, policy, reports}: RoomNamePageProps) { const styles = useThemeStyles(); @@ -50,7 +50,7 @@ function RoomNamePage({report, policy, reports}: RoomNamePageProps) { const errors = {}; // We should skip validation hence we return an empty errors and we skip Form submission on the onSubmit method - if (values.roomName === report.reportName) { + if (values.roomName === report?.reportName) { return errors; } @@ -63,7 +63,7 @@ function RoomNamePage({report, policy, reports}: RoomNamePageProps) { } else if (ValidationUtils.isReservedRoomName(values.roomName)) { // Certain names are reserved for default rooms and should not be used for policy rooms. ErrorUtils.addErrorMessage(errors, 'roomName', ['newRoomPage.roomNameReservedError', {reservedName: values.roomName}]); - } else if (ValidationUtils.isExistingRoomName(values.roomName, reports, report.policyID)) { + } else if (ValidationUtils.isExistingRoomName(values.roomName, reports, report?.policyID)) { // The room name can't be set to one that already exists on the policy ErrorUtils.addErrorMessage(errors, 'roomName', 'newRoomPage.roomAlreadyExistsError'); } @@ -82,12 +82,12 @@ function RoomNamePage({report, policy, reports}: RoomNamePageProps) { Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(report.reportID))} + onBackButtonPress={() => Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(report?.reportID ?? ''))} /> ReportActions.updatePolicyRoomNameAndNavigate(report, values.roomName)} + onSubmit={(values) => !isEmptyObject(report) && ReportActions.updatePolicyRoomNameAndNavigate(report, values.roomName)} validate={validate} submitButtonText={translate('common.save')} enabledWhenOffline @@ -97,7 +97,7 @@ function RoomNamePage({report, policy, reports}: RoomNamePageProps) { InputComponent={RoomNameInput} ref={roomNameInputRef} inputID="roomName" - defaultValue={report.reportName} + defaultValue={report?.reportName} isFocused={isFocused} /> @@ -115,7 +115,7 @@ export default withReportOrNotFound()( key: ONYXKEYS.COLLECTION.REPORT, }, policy: { - key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, + key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`, }, })(RoomNamePage), ); diff --git a/src/pages/settings/Report/WriteCapabilityPage.tsx b/src/pages/settings/Report/WriteCapabilityPage.tsx index 49accdff8e13..7af951d685d4 100644 --- a/src/pages/settings/Report/WriteCapabilityPage.tsx +++ b/src/pages/settings/Report/WriteCapabilityPage.tsx @@ -1,3 +1,4 @@ +import type {StackScreenProps} from '@react-navigation/stack'; import React from 'react'; import {withOnyx} from 'react-native-onyx'; import type {OnyxEntry} from 'react-native-onyx'; @@ -8,13 +9,16 @@ import SelectionList from '@components/SelectionList'; import useLocalize from '@hooks/useLocalize'; import Navigation from '@libs/Navigation/Navigation'; import * as ReportUtils from '@libs/ReportUtils'; +import type {ReportSettingsNavigatorParamList} from '@navigation/types'; import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound'; import * as ReportActions from '@userActions/Report'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import type {Policy, Report} from '@src/types/onyx'; +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 */ @@ -22,10 +26,8 @@ type WriteCapabilityPageOnyxProps = { }; type WriteCapabilityPageProps = WriteCapabilityPageOnyxProps & - WithReportOrNotFoundProps & { - /** The report for which we are setting write capability */ - report: Report; - }; + WithReportOrNotFoundProps & + StackScreenProps; function WriteCapabilityPage({report, policy}: WriteCapabilityPageProps) { const {translate} = useLocalize(); @@ -33,7 +35,7 @@ function WriteCapabilityPage({report, policy}: WriteCapabilityPageProps) { value, text: translate(`writeCapabilityPage.writeCapability.${value}`), keyForList: value, - isSelected: value === (report.writeCapability ?? CONST.REPORT.WRITE_CAPABILITIES.ALL), + isSelected: value === (report?.writeCapability ?? CONST.REPORT.WRITE_CAPABILITIES.ALL), })); const isAbleToEdit = ReportUtils.canEditWriteCapability(report, policy); @@ -47,11 +49,11 @@ function WriteCapabilityPage({report, policy}: WriteCapabilityPageProps) { Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(report.reportID))} + onBackButtonPress={() => Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(report?.reportID ?? ''))} /> ReportActions.updateWriteCapabilityAndNavigate(report, option.value)} + onSelectRow={(option) => !isEmptyObject(report) && ReportActions.updateWriteCapabilityAndNavigate(report, option.value)} initiallyFocusedOptionKey={Object.values(writeCapabilityOptions).find((locale) => locale.isSelected)?.keyForList} /> @@ -64,7 +66,7 @@ WriteCapabilityPage.displayName = 'WriteCapabilityPage'; export default withReportOrNotFound()( withOnyx({ policy: { - key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, + key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`, }, })(WriteCapabilityPage), ); From e2c935ce0b148c01b4b72c1c50599a3505309c71 Mon Sep 17 00:00:00 2001 From: Shahe Shahinyan Date: Thu, 1 Feb 2024 19:55:48 +0400 Subject: [PATCH 10/15] run prettier --- src/types/onyx/Form.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/onyx/Form.ts b/src/types/onyx/Form.ts index 905270427ac8..fd0af2e5139f 100644 --- a/src/types/onyx/Form.ts +++ b/src/types/onyx/Form.ts @@ -77,5 +77,5 @@ export type { IntroSchoolPrincipalForm, PersonalBankAccountForm, ReportFieldEditForm, - RoomNameForm + RoomNameForm, }; From ba70fc913ea282749ad6d6b831f348ab39a4bb26 Mon Sep 17 00:00:00 2001 From: Shahe Shahinyan Date: Thu, 1 Feb 2024 20:18:23 +0400 Subject: [PATCH 11/15] Addressed to reviewer comments --- src/pages/settings/Report/ReportSettingsPage.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/pages/settings/Report/ReportSettingsPage.tsx b/src/pages/settings/Report/ReportSettingsPage.tsx index 790f61c0503e..3dd096c96a7c 100644 --- a/src/pages/settings/Report/ReportSettingsPage.tsx +++ b/src/pages/settings/Report/ReportSettingsPage.tsx @@ -27,6 +27,7 @@ import type SCREENS from '@src/SCREENS'; type ReportSettingsPageProps = WithReportOrNotFoundProps & StackScreenProps; function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { + const reportID = report?.reportID ?? ''; const styles = useThemeStyles(); const {translate} = useLocalize(); // The workspace the report is on, null if the user isn't a member of the workspace @@ -59,7 +60,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(report?.reportID ?? ''))} + onBackButtonPress={() => Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(reportID ?? ''))} /> {shouldShowNotificationPref && ( @@ -67,7 +68,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { shouldShowRightIcon title={notificationPreference} description={translate('notificationPreferencesPage.label')} - onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.getRoute(report?.reportID ?? ''))} + onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.getRoute(reportID ?? ''))} /> )} {shouldShowRoomName && ( @@ -75,7 +76,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { pendingAction={report?.pendingFields?.reportName} errors={report?.errorFields?.reportName} errorRowStyles={[styles.ph5]} - onClose={() => ReportActions.clearPolicyRoomNameErrors(report?.reportID ?? '')} + onClose={() => ReportActions.clearPolicyRoomNameErrors(reportID ?? '')} > {shouldDisableRename ? ( @@ -98,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(report?.reportID ?? ''))} + onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_ROOM_NAME.getRoute(reportID ?? ''))} /> )} @@ -109,7 +110,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { shouldShowRightIcon title={writeCapabilityText} description={translate('writeCapabilityPage.label')} - onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_WRITE_CAPABILITY.getRoute(report?.reportID ?? ''))} + onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_WRITE_CAPABILITY.getRoute(reportID ?? ''))} /> ) : ( @@ -167,7 +168,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { Navigation.navigate(ROUTES.REPORT_WELCOME_MESSAGE.getRoute(report?.reportID ?? ''))} + onPress={() => Navigation.navigate(ROUTES.REPORT_WELCOME_MESSAGE.getRoute(reportID ?? ''))} shouldShowRightIcon /> )} From d07a1d54323ef1ca78e47b8f0eebf96eae0ebc9e Mon Sep 17 00:00:00 2001 From: Shahe Shahinyan Date: Thu, 1 Feb 2024 21:20:14 +0400 Subject: [PATCH 12/15] Addressed to reviewer comments --- src/libs/ReportUtils.ts | 6 +++--- src/libs/ValidationUtils.ts | 2 +- src/libs/actions/Report.ts | 2 +- src/pages/settings/Report/ReportSettingsPage.tsx | 2 +- src/pages/settings/Report/RoomNamePage.tsx | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index acbe2472fea5..3d21911c83e8 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4269,7 +4269,7 @@ function getWorkspaceChats(policyID: string, accountIDs: number[]): Array, policy: OnyxEntry | undefined): boolean { +function shouldDisableRename(report: OnyxEntry, policy: OnyxEntry): boolean { if (isDefaultRoom(report) || isArchivedRoom(report) || isThread(report) || isMoneyRequestReport(report) || isPolicyExpenseChat(report)) { return true; } @@ -4287,7 +4287,7 @@ function shouldDisableRename(report: OnyxEntry, policy: OnyxEntry, policy: OnyxEntry | undefined): boolean { +function canEditWriteCapability(report: OnyxEntry, policy: OnyxEntry): boolean { return PolicyUtils.isPolicyAdmin(policy) && !isAdminRoom(report) && !isArchivedRoom(report) && !isThread(report); } @@ -4575,7 +4575,7 @@ function getRoom(type: ValueOf, policyID: string) /** * We only want policy owners and admins to be able to modify the welcome message, but not in thread chat. */ -function shouldDisableWelcomeMessage(report: OnyxEntry, policy: OnyxEntry | undefined): boolean { +function shouldDisableWelcomeMessage(report: OnyxEntry, policy: OnyxEntry): boolean { return isMoneyRequestReport(report) || isArchivedRoom(report) || !isChatRoom(report) || isChatThread(report) || !PolicyUtils.isPolicyAdmin(policy); } /** diff --git a/src/libs/ValidationUtils.ts b/src/libs/ValidationUtils.ts index af9e394e0b7f..132fed6d1ada 100644 --- a/src/libs/ValidationUtils.ts +++ b/src/libs/ValidationUtils.ts @@ -355,7 +355,7 @@ function isReservedRoomName(roomName: string): boolean { /** * Checks if the room name already exists. */ -function isExistingRoomName(roomName: string, reports: OnyxCollection, policyID?: string): boolean { +function isExistingRoomName(roomName: string, reports: OnyxCollection, policyID: string): boolean { return Object.values(reports ?? {}).some((report) => report && report.policyID === policyID && report.reportName === roomName); } diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 2eedd090b90c..3d375ec26413 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -1806,7 +1806,7 @@ function navigateToConciergeChatAndDeleteReport(reportID: string) { /** * @param policyRoomName The updated name for the policy room */ -function updatePolicyRoomNameAndNavigate(policyRoomReport: Report, policyRoomName: string | undefined) { +function updatePolicyRoomNameAndNavigate(policyRoomReport: Report, policyRoomName: string) { const reportID = policyRoomReport.reportID; const previousName = policyRoomReport.reportName; diff --git a/src/pages/settings/Report/ReportSettingsPage.tsx b/src/pages/settings/Report/ReportSettingsPage.tsx index 3dd096c96a7c..28d189359860 100644 --- a/src/pages/settings/Report/ReportSettingsPage.tsx +++ b/src/pages/settings/Report/ReportSettingsPage.tsx @@ -31,7 +31,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); // The workspace the report is on, null if the user isn't a member of the workspace - const linkedWorkspace = useMemo(() => Object.values(policies ?? {}).find((policy) => policy && policy.id === report?.policyID), [policies, report?.policyID]); + const linkedWorkspace = useMemo(() => Object.values(policies ?? {}).find((policy) => policy && policy.id === report?.policyID) ?? null, [policies, report?.policyID]); const shouldDisableRename = useMemo(() => ReportUtils.shouldDisableRename(report, linkedWorkspace), [report, linkedWorkspace]); const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); diff --git a/src/pages/settings/Report/RoomNamePage.tsx b/src/pages/settings/Report/RoomNamePage.tsx index 759147f95d95..6b2fd751f01f 100644 --- a/src/pages/settings/Report/RoomNamePage.tsx +++ b/src/pages/settings/Report/RoomNamePage.tsx @@ -63,7 +63,7 @@ function RoomNamePage({report, policy, reports}: RoomNamePageProps) { } else if (ValidationUtils.isReservedRoomName(values.roomName)) { // Certain names are reserved for default rooms and should not be used for policy rooms. ErrorUtils.addErrorMessage(errors, 'roomName', ['newRoomPage.roomNameReservedError', {reservedName: values.roomName}]); - } else if (ValidationUtils.isExistingRoomName(values.roomName, reports, report?.policyID)) { + } else if (ValidationUtils.isExistingRoomName(values.roomName, reports, report?.policyID ?? '')) { // The room name can't be set to one that already exists on the policy ErrorUtils.addErrorMessage(errors, 'roomName', 'newRoomPage.roomAlreadyExistsError'); } From 0b2f0e6e1b0b73a9c3e649f086aae7afdfc06164 Mon Sep 17 00:00:00 2001 From: Shahe Shahinyan Date: Fri, 2 Feb 2024 14:17:17 +0400 Subject: [PATCH 13/15] Addressed to reviewer comments --- src/libs/API/parameters/UpdatePolicyRoomNameParams.ts | 2 +- src/libs/actions/Report.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/API/parameters/UpdatePolicyRoomNameParams.ts b/src/libs/API/parameters/UpdatePolicyRoomNameParams.ts index 74f936cbbb46..65b858b7c20f 100644 --- a/src/libs/API/parameters/UpdatePolicyRoomNameParams.ts +++ b/src/libs/API/parameters/UpdatePolicyRoomNameParams.ts @@ -1,6 +1,6 @@ type UpdatePolicyRoomNameParams = { reportID: string; - policyRoomName?: string; + policyRoomName: string; }; export default UpdatePolicyRoomNameParams; diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 3d375ec26413..221c7f8d4f88 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -1852,7 +1852,7 @@ function updatePolicyRoomNameAndNavigate(policyRoomReport: Report, policyRoomNam }, ]; - const parameters: UpdatePolicyRoomNameParams = {reportID, policyRoomName: policyRoomName ?? ''}; + const parameters: UpdatePolicyRoomNameParams = {reportID, policyRoomName}; API.write(WRITE_COMMANDS.UPDATE_POLICY_ROOM_NAME, parameters, {optimisticData, successData, failureData}); Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(reportID)); From b742d6642e2c94d6accdbaf9322fd8e6bc77ff4a Mon Sep 17 00:00:00 2001 From: Shahe Shahinyan Date: Sun, 4 Feb 2024 14:23:24 +0400 Subject: [PATCH 14/15] 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} /> From 84317afa371a97711cf2411487436d7f26b6ba0b Mon Sep 17 00:00:00 2001 From: Shahe Shahinyan Date: Mon, 5 Feb 2024 00:54:12 +0400 Subject: [PATCH 15/15] Addressed to reviewer comments --- src/components/DisplayNames/index.tsx | 12 +++++++++++- src/pages/settings/Report/ReportSettingsPage.tsx | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/components/DisplayNames/index.tsx b/src/components/DisplayNames/index.tsx index 155193368cc5..5b8844eb4e99 100644 --- a/src/components/DisplayNames/index.tsx +++ b/src/components/DisplayNames/index.tsx @@ -18,9 +18,19 @@ function DisplayNames({fullTitle, tooltipEnabled, textStyles, numberOfLines, sho ); } + if (shouldUseFullTitle) { + return ( + + ); + } + return ( {translate(`newRoomPage.visibilityOptions.${report.visibility}`)} - {report.visibility && translate(`newRoomPage.${report.visibility}Description`)} + {translate(`newRoomPage.${report.visibility}Description`)} )}