From 648f9c2d6c352e425922de2982251e94395714c6 Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Sat, 18 May 2024 19:37:29 +0100 Subject: [PATCH 1/2] Combine report name routes --- src/ROUTES.ts | 10 +++---- src/SCREENS.ts | 3 +-- .../TextInput/BaseTextInput/index.tsx | 4 +-- .../ModalStackNavigators/index.tsx | 3 +-- src/libs/Navigation/linkingConfig/config.ts | 7 ++--- src/libs/Navigation/types.ts | 13 ++++----- src/pages/GroupChatNameEditPage.tsx | 20 ++++++++------ src/pages/settings/Report/NamePage.tsx | 22 +++++++++++++++ .../settings/Report/ReportSettingsPage.tsx | 6 +---- src/pages/settings/Report/RoomNamePage.tsx | 27 ++++++++----------- 10 files changed, 60 insertions(+), 55 deletions(-) create mode 100644 src/pages/settings/Report/NamePage.tsx diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 2bc04c4a99ea4..f2647da7cd91b 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -262,13 +262,9 @@ const ROUTES = { route: 'r/:reportID/settings', getRoute: (reportID: string) => `r/${reportID}/settings` as const, }, - REPORT_SETTINGS_ROOM_NAME: { - route: 'r/:reportID/settings/room-name', - getRoute: (reportID: string) => `r/${reportID}/settings/room-name` as const, - }, - REPORT_SETTINGS_GROUP_NAME: { - route: 'r/:reportID/settings/group-name', - getRoute: (reportID: string) => `r/${reportID}/settings/group-name` as const, + REPORT_SETTINGS_NAME: { + route: 'r/:reportID/settings/name', + getRoute: (reportID: string) => `r/${reportID}/settings/name` as const, }, REPORT_SETTINGS_NOTIFICATION_PREFERENCES: { route: 'r/:reportID/settings/notification-preferences', diff --git a/src/SCREENS.ts b/src/SCREENS.ts index f740023126235..7412a8ca9bdb7 100644 --- a/src/SCREENS.ts +++ b/src/SCREENS.ts @@ -184,8 +184,7 @@ const SCREENS = { REPORT_SETTINGS: { ROOT: 'Report_Settings_Root', - ROOM_NAME: 'Report_Settings_Room_Name', - GROUP_NAME: 'Report_Settings_Group_Name', + NAME: 'Report_Settings_Name', NOTIFICATION_PREFERENCES: 'Report_Settings_Notification_Preferences', WRITE_CAPABILITY: 'Report_Settings_Write_Capability', VISIBILITY: 'Report_Settings_Visibility', diff --git a/src/components/TextInput/BaseTextInput/index.tsx b/src/components/TextInput/BaseTextInput/index.tsx index c73509aa7b8f4..600d0f24a6292 100644 --- a/src/components/TextInput/BaseTextInput/index.tsx +++ b/src/components/TextInput/BaseTextInput/index.tsx @@ -397,7 +397,7 @@ function BaseTextInput( defaultValue={defaultValue} markdownStyle={markdownStyle} /> - {isFocused && !isReadOnly && shouldShowClearButton && value && setValue('')} />} + {isFocused && !isReadOnly && shouldShowClearButton && !!value && setValue('')} />} {inputProps.isLoading && ( )} - {!inputProps.secureTextEntry && icon && ( + {!inputProps.secureTextEntry && !!icon && ( ({ [SCREENS.REPORT_SETTINGS.ROOT]: () => require('../../../../pages/settings/Report/ReportSettingsPage').default as React.ComponentType, - [SCREENS.REPORT_SETTINGS.ROOM_NAME]: () => require('../../../../pages/settings/Report/RoomNamePage').default as React.ComponentType, - [SCREENS.REPORT_SETTINGS.GROUP_NAME]: () => require('../../../../pages/GroupChatNameEditPage').default as React.ComponentType, + [SCREENS.REPORT_SETTINGS.NAME]: () => require('../../../../pages/settings/Report/NamePage').default as React.ComponentType, [SCREENS.REPORT_SETTINGS.NOTIFICATION_PREFERENCES]: () => require('../../../../pages/settings/Report/NotificationPreferencePage').default as React.ComponentType, [SCREENS.REPORT_SETTINGS.WRITE_CAPABILITY]: () => require('../../../../pages/settings/Report/WriteCapabilityPage').default as React.ComponentType, [SCREENS.REPORT_SETTINGS.VISIBILITY]: () => require('../../../../pages/settings/Report/VisibilityPage').default as React.ComponentType, diff --git a/src/libs/Navigation/linkingConfig/config.ts b/src/libs/Navigation/linkingConfig/config.ts index a093b778360e0..6a25a595e5dd7 100644 --- a/src/libs/Navigation/linkingConfig/config.ts +++ b/src/libs/Navigation/linkingConfig/config.ts @@ -517,11 +517,8 @@ const config: LinkingOptions['config'] = { [SCREENS.REPORT_SETTINGS.ROOT]: { path: ROUTES.REPORT_SETTINGS.route, }, - [SCREENS.REPORT_SETTINGS.ROOM_NAME]: { - path: ROUTES.REPORT_SETTINGS_ROOM_NAME.route, - }, - [SCREENS.REPORT_SETTINGS.GROUP_NAME]: { - path: ROUTES.REPORT_SETTINGS_GROUP_NAME.route, + [SCREENS.REPORT_SETTINGS.NAME]: { + path: ROUTES.REPORT_SETTINGS_NAME.route, }, [SCREENS.REPORT_SETTINGS.NOTIFICATION_PREFERENCES]: { path: ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.route, diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index e4820df10df92..9d61b7702a5a7 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -390,9 +390,7 @@ type SettingsNavigatorParamList = { type NewChatNavigatorParamList = { [SCREENS.NEW_CHAT.ROOT]: undefined; - [SCREENS.NEW_CHAT.NEW_CHAT_EDIT_NAME]: { - reportID?: string; - }; + [SCREENS.NEW_CHAT.NEW_CHAT_EDIT_NAME]: undefined; }; type DetailsNavigatorParamList = { @@ -418,11 +416,10 @@ type ReportDetailsNavigatorParamList = { }; type ReportSettingsNavigatorParamList = { - [SCREENS.REPORT_SETTINGS.ROOT]: undefined; - [SCREENS.REPORT_SETTINGS.ROOM_NAME]: undefined; - [SCREENS.REPORT_SETTINGS.GROUP_NAME]: undefined; - [SCREENS.REPORT_SETTINGS.NOTIFICATION_PREFERENCES]: undefined; - [SCREENS.REPORT_SETTINGS.WRITE_CAPABILITY]: undefined; + [SCREENS.REPORT_SETTINGS.ROOT]: {reportID: string}; + [SCREENS.REPORT_SETTINGS.NAME]: {reportID: string}; + [SCREENS.REPORT_SETTINGS.NOTIFICATION_PREFERENCES]: {reportID: string}; + [SCREENS.REPORT_SETTINGS.WRITE_CAPABILITY]: {reportID: string}; [SCREENS.REPORT_SETTINGS.VISIBILITY]: { reportID: string; }; diff --git a/src/pages/GroupChatNameEditPage.tsx b/src/pages/GroupChatNameEditPage.tsx index 87218fbb89cd5..70b7f2b11da33 100644 --- a/src/pages/GroupChatNameEditPage.tsx +++ b/src/pages/GroupChatNameEditPage.tsx @@ -11,15 +11,16 @@ import useAutoFocusInput from '@hooks/useAutoFocusInput'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; +import type {NewChatNavigatorParamList} from '@libs/Navigation/types'; import * as ReportUtils from '@libs/ReportUtils'; import * as ValidationUtils from '@libs/ValidationUtils'; -import type {NewChatNavigatorParamList} from '@navigation/types'; -import * as Report from '@userActions/Report'; +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 INPUT_IDS from '@src/types/form/NewChatNameForm'; +import type {Report} from '@src/types/onyx'; import type NewGroupChatDraft from '@src/types/onyx/NewGroupChatDraft'; import type {Errors} from '@src/types/onyx/OnyxCommon'; @@ -27,11 +28,14 @@ type GroupChatNameEditPageOnyxProps = { groupChatDraft: NewGroupChatDraft | null; }; -type GroupChatNameEditPageProps = StackScreenProps & GroupChatNameEditPageOnyxProps; +type GroupChatNameEditPageProps = GroupChatNameEditPageOnyxProps & + Partial> & { + report?: Report; + }; -function GroupChatNameEditPage({groupChatDraft, route}: GroupChatNameEditPageProps) { - // If we have a reportID this means we are using this page to update an existing Group Chat name - const reportID = route.params?.reportID ?? ''; +function GroupChatNameEditPage({groupChatDraft, report}: GroupChatNameEditPageProps) { + // If we have a report this means we are using this page to update an existing Group Chat name + const reportID = report?.reportID ?? ''; const isUpdatingExistingReport = Boolean(reportID); const styles = useThemeStyles(); @@ -66,13 +70,13 @@ function GroupChatNameEditPage({groupChatDraft, route}: GroupChatNameEditPagePro (values: FormOnyxValues) => { if (isUpdatingExistingReport) { if (values[INPUT_IDS.NEW_CHAT_NAME] !== currentChatName) { - Report.updateGroupChatName(reportID, values[INPUT_IDS.NEW_CHAT_NAME] ?? ''); + ReportActions.updateGroupChatName(reportID, values[INPUT_IDS.NEW_CHAT_NAME] ?? ''); } Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(reportID)); return; } if (values[INPUT_IDS.NEW_CHAT_NAME] !== currentChatName) { - Report.setGroupDraft({reportName: values[INPUT_IDS.NEW_CHAT_NAME]}); + ReportActions.setGroupDraft({reportName: values[INPUT_IDS.NEW_CHAT_NAME]}); } Navigation.goBack(ROUTES.NEW_CHAT_CONFIRM); }, diff --git a/src/pages/settings/Report/NamePage.tsx b/src/pages/settings/Report/NamePage.tsx new file mode 100644 index 0000000000000..de73e59bb7daa --- /dev/null +++ b/src/pages/settings/Report/NamePage.tsx @@ -0,0 +1,22 @@ +import type {StackScreenProps} from '@react-navigation/stack'; +import React from 'react'; +import * as ReportUtils from '@libs/ReportUtils'; +import type {ReportSettingsNavigatorParamList} from '@navigation/types'; +import GroupChatNameEditPage from '@pages/GroupChatNameEditPage'; +import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; +import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound'; +import type SCREENS from '@src/SCREENS'; +import RoomNamePage from './RoomNamePage'; + +type NamePageProps = WithReportOrNotFoundProps & StackScreenProps; + +function NamePage({report}: NamePageProps) { + if (ReportUtils.isGroupChat(report)) { + return ; + } + return ; +} + +NamePage.displayName = 'NamePage'; + +export default withReportOrNotFound()(NamePage); diff --git a/src/pages/settings/Report/ReportSettingsPage.tsx b/src/pages/settings/Report/ReportSettingsPage.tsx index aabd8d2fe376f..132ae06d4867b 100644 --- a/src/pages/settings/Report/ReportSettingsPage.tsx +++ b/src/pages/settings/Report/ReportSettingsPage.tsx @@ -96,11 +96,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { shouldShowRightIcon title={report?.reportName === '' ? reportName : report?.reportName} description={isGroupChat ? translate('common.name') : translate('newRoomPage.roomName')} - onPress={() => - isGroupChat - ? Navigation.navigate(ROUTES.REPORT_SETTINGS_GROUP_NAME.getRoute(reportID)) - : Navigation.navigate(ROUTES.REPORT_SETTINGS_ROOM_NAME.getRoute(reportID)) - } + onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_NAME.getRoute(reportID))} /> )} diff --git a/src/pages/settings/Report/RoomNamePage.tsx b/src/pages/settings/Report/RoomNamePage.tsx index 5ba85961e5baf..13c853674b4b5 100644 --- a/src/pages/settings/Report/RoomNamePage.tsx +++ b/src/pages/settings/Report/RoomNamePage.tsx @@ -1,5 +1,4 @@ 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'; @@ -18,14 +17,10 @@ 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 INPUT_IDS from '@src/types/form/RoomNameForm'; import type {Policy, Report} from '@src/types/onyx'; @@ -37,7 +32,9 @@ type RoomNamePageOnyxProps = { policy: OnyxEntry; }; -type RoomNamePageProps = RoomNamePageOnyxProps & WithReportOrNotFoundProps & StackScreenProps; +type RoomNamePageProps = RoomNamePageOnyxProps & { + report: Report; +}; function RoomNamePage({report, policy, reports}: RoomNamePageProps) { const styles = useThemeStyles(); @@ -111,13 +108,11 @@ function RoomNamePage({report, policy, reports}: RoomNamePageProps) { RoomNamePage.displayName = 'RoomNamePage'; -export default withReportOrNotFound()( - withOnyx({ - reports: { - key: ONYXKEYS.COLLECTION.REPORT, - }, - policy: { - key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`, - }, - })(RoomNamePage), -); +export default withOnyx({ + reports: { + key: ONYXKEYS.COLLECTION.REPORT, + }, + policy: { + key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`, + }, +})(RoomNamePage); From affc749fd2325b22739734fcc5cd0bb580302767 Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Wed, 29 May 2024 22:45:17 +0100 Subject: [PATCH 2/2] Revert rename userActions/Report --- src/pages/GroupChatNameEditPage.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pages/GroupChatNameEditPage.tsx b/src/pages/GroupChatNameEditPage.tsx index 70b7f2b11da33..b3e5e9bb119ca 100644 --- a/src/pages/GroupChatNameEditPage.tsx +++ b/src/pages/GroupChatNameEditPage.tsx @@ -14,13 +14,13 @@ import Navigation from '@libs/Navigation/Navigation'; import type {NewChatNavigatorParamList} from '@libs/Navigation/types'; import * as ReportUtils from '@libs/ReportUtils'; import * as ValidationUtils from '@libs/ValidationUtils'; -import * as ReportActions from '@userActions/Report'; +import * as Report 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 INPUT_IDS from '@src/types/form/NewChatNameForm'; -import type {Report} from '@src/types/onyx'; +import type {Report as ReportOnyxType} from '@src/types/onyx'; import type NewGroupChatDraft from '@src/types/onyx/NewGroupChatDraft'; import type {Errors} from '@src/types/onyx/OnyxCommon'; @@ -30,7 +30,7 @@ type GroupChatNameEditPageOnyxProps = { type GroupChatNameEditPageProps = GroupChatNameEditPageOnyxProps & Partial> & { - report?: Report; + report?: ReportOnyxType; }; function GroupChatNameEditPage({groupChatDraft, report}: GroupChatNameEditPageProps) { @@ -70,13 +70,13 @@ function GroupChatNameEditPage({groupChatDraft, report}: GroupChatNameEditPagePr (values: FormOnyxValues) => { if (isUpdatingExistingReport) { if (values[INPUT_IDS.NEW_CHAT_NAME] !== currentChatName) { - ReportActions.updateGroupChatName(reportID, values[INPUT_IDS.NEW_CHAT_NAME] ?? ''); + Report.updateGroupChatName(reportID, values[INPUT_IDS.NEW_CHAT_NAME] ?? ''); } Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(reportID)); return; } if (values[INPUT_IDS.NEW_CHAT_NAME] !== currentChatName) { - ReportActions.setGroupDraft({reportName: values[INPUT_IDS.NEW_CHAT_NAME]}); + Report.setGroupDraft({reportName: values[INPUT_IDS.NEW_CHAT_NAME]}); } Navigation.goBack(ROUTES.NEW_CHAT_CONFIRM); },