Skip to content

Commit d3e5071

Browse files
authored
Merge pull request #42369 from s77rt/combine-report-name-routes
Combine report name routes
2 parents b0e2361 + 70893ae commit d3e5071

File tree

10 files changed

+57
-52
lines changed

10 files changed

+57
-52
lines changed

src/ROUTES.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,9 @@ const ROUTES = {
280280
route: 'r/:reportID/settings',
281281
getRoute: (reportID: string) => `r/${reportID}/settings` as const,
282282
},
283-
REPORT_SETTINGS_ROOM_NAME: {
284-
route: 'r/:reportID/settings/room-name',
285-
getRoute: (reportID: string) => `r/${reportID}/settings/room-name` as const,
286-
},
287-
REPORT_SETTINGS_GROUP_NAME: {
288-
route: 'r/:reportID/settings/group-name',
289-
getRoute: (reportID: string) => `r/${reportID}/settings/group-name` as const,
283+
REPORT_SETTINGS_NAME: {
284+
route: 'r/:reportID/settings/name',
285+
getRoute: (reportID: string) => `r/${reportID}/settings/name` as const,
290286
},
291287
REPORT_SETTINGS_NOTIFICATION_PREFERENCES: {
292288
route: 'r/:reportID/settings/notification-preferences',

src/SCREENS.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ const SCREENS = {
188188

189189
REPORT_SETTINGS: {
190190
ROOT: 'Report_Settings_Root',
191-
ROOM_NAME: 'Report_Settings_Room_Name',
192-
GROUP_NAME: 'Report_Settings_Group_Name',
191+
NAME: 'Report_Settings_Name',
193192
NOTIFICATION_PREFERENCES: 'Report_Settings_Notification_Preferences',
194193
WRITE_CAPABILITY: 'Report_Settings_Write_Capability',
195194
VISIBILITY: 'Report_Settings_Visibility',

src/components/TextInput/BaseTextInput/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ function BaseTextInput(
399399
defaultValue={defaultValue}
400400
markdownStyle={markdownStyle}
401401
/>
402-
{isFocused && !isReadOnly && shouldShowClearButton && value && <TextInputClearButton onPressButton={() => setValue('')} />}
402+
{isFocused && !isReadOnly && shouldShowClearButton && !!value && <TextInputClearButton onPressButton={() => setValue('')} />}
403403
{inputProps.isLoading && (
404404
<ActivityIndicator
405405
size="small"
@@ -422,7 +422,7 @@ function BaseTextInput(
422422
/>
423423
</Checkbox>
424424
)}
425-
{!inputProps.secureTextEntry && icon && (
425+
{!inputProps.secureTextEntry && !!icon && (
426426
<View style={[styles.textInputIconContainer, !isReadOnly ? styles.cursorPointer : styles.pointerEventsNone]}>
427427
<Icon
428428
src={icon}

src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ const ReportDetailsModalStackNavigator = createModalStackNavigator<ReportDetails
118118

119119
const ReportSettingsModalStackNavigator = createModalStackNavigator<ReportSettingsNavigatorParamList>({
120120
[SCREENS.REPORT_SETTINGS.ROOT]: () => require('../../../../pages/settings/Report/ReportSettingsPage').default as React.ComponentType,
121-
[SCREENS.REPORT_SETTINGS.ROOM_NAME]: () => require('../../../../pages/settings/Report/RoomNamePage').default as React.ComponentType,
122-
[SCREENS.REPORT_SETTINGS.GROUP_NAME]: () => require('../../../../pages/GroupChatNameEditPage').default as React.ComponentType,
121+
[SCREENS.REPORT_SETTINGS.NAME]: () => require('../../../../pages/settings/Report/NamePage').default as React.ComponentType,
123122
[SCREENS.REPORT_SETTINGS.NOTIFICATION_PREFERENCES]: () => require('../../../../pages/settings/Report/NotificationPreferencePage').default as React.ComponentType,
124123
[SCREENS.REPORT_SETTINGS.WRITE_CAPABILITY]: () => require('../../../../pages/settings/Report/WriteCapabilityPage').default as React.ComponentType,
125124
[SCREENS.REPORT_SETTINGS.VISIBILITY]: () => require('../../../../pages/settings/Report/VisibilityPage').default as React.ComponentType,

src/libs/Navigation/linkingConfig/config.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -520,11 +520,8 @@ const config: LinkingOptions<RootStackParamList>['config'] = {
520520
[SCREENS.REPORT_SETTINGS.ROOT]: {
521521
path: ROUTES.REPORT_SETTINGS.route,
522522
},
523-
[SCREENS.REPORT_SETTINGS.ROOM_NAME]: {
524-
path: ROUTES.REPORT_SETTINGS_ROOM_NAME.route,
525-
},
526-
[SCREENS.REPORT_SETTINGS.GROUP_NAME]: {
527-
path: ROUTES.REPORT_SETTINGS_GROUP_NAME.route,
523+
[SCREENS.REPORT_SETTINGS.NAME]: {
524+
path: ROUTES.REPORT_SETTINGS_NAME.route,
528525
},
529526
[SCREENS.REPORT_SETTINGS.NOTIFICATION_PREFERENCES]: {
530527
path: ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.route,

src/libs/Navigation/types.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,7 @@ type SettingsNavigatorParamList = {
404404

405405
type NewChatNavigatorParamList = {
406406
[SCREENS.NEW_CHAT.ROOT]: undefined;
407-
[SCREENS.NEW_CHAT.NEW_CHAT_EDIT_NAME]: {
408-
reportID?: string;
409-
};
407+
[SCREENS.NEW_CHAT.NEW_CHAT_EDIT_NAME]: undefined;
410408
};
411409

412410
type DetailsNavigatorParamList = {
@@ -432,11 +430,10 @@ type ReportDetailsNavigatorParamList = {
432430
};
433431

434432
type ReportSettingsNavigatorParamList = {
435-
[SCREENS.REPORT_SETTINGS.ROOT]: undefined;
436-
[SCREENS.REPORT_SETTINGS.ROOM_NAME]: undefined;
437-
[SCREENS.REPORT_SETTINGS.GROUP_NAME]: undefined;
438-
[SCREENS.REPORT_SETTINGS.NOTIFICATION_PREFERENCES]: undefined;
439-
[SCREENS.REPORT_SETTINGS.WRITE_CAPABILITY]: undefined;
433+
[SCREENS.REPORT_SETTINGS.ROOT]: {reportID: string};
434+
[SCREENS.REPORT_SETTINGS.NAME]: {reportID: string};
435+
[SCREENS.REPORT_SETTINGS.NOTIFICATION_PREFERENCES]: {reportID: string};
436+
[SCREENS.REPORT_SETTINGS.WRITE_CAPABILITY]: {reportID: string};
440437
[SCREENS.REPORT_SETTINGS.VISIBILITY]: {
441438
reportID: string;
442439
};

src/pages/GroupChatNameEditPage.tsx

+9-5
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,31 @@ import useAutoFocusInput from '@hooks/useAutoFocusInput';
1111
import useLocalize from '@hooks/useLocalize';
1212
import useThemeStyles from '@hooks/useThemeStyles';
1313
import Navigation from '@libs/Navigation/Navigation';
14+
import type {NewChatNavigatorParamList} from '@libs/Navigation/types';
1415
import * as ReportUtils from '@libs/ReportUtils';
1516
import * as ValidationUtils from '@libs/ValidationUtils';
16-
import type {NewChatNavigatorParamList} from '@navigation/types';
1717
import * as Report from '@userActions/Report';
1818
import CONST from '@src/CONST';
1919
import ONYXKEYS from '@src/ONYXKEYS';
2020
import ROUTES from '@src/ROUTES';
2121
import type SCREENS from '@src/SCREENS';
2222
import INPUT_IDS from '@src/types/form/NewChatNameForm';
23+
import type {Report as ReportOnyxType} from '@src/types/onyx';
2324
import type NewGroupChatDraft from '@src/types/onyx/NewGroupChatDraft';
2425
import type {Errors} from '@src/types/onyx/OnyxCommon';
2526

2627
type GroupChatNameEditPageOnyxProps = {
2728
groupChatDraft: NewGroupChatDraft | null;
2829
};
2930

30-
type GroupChatNameEditPageProps = StackScreenProps<NewChatNavigatorParamList, typeof SCREENS.NEW_CHAT.NEW_CHAT_EDIT_NAME> & GroupChatNameEditPageOnyxProps;
31+
type GroupChatNameEditPageProps = GroupChatNameEditPageOnyxProps &
32+
Partial<StackScreenProps<NewChatNavigatorParamList, typeof SCREENS.NEW_CHAT.NEW_CHAT_EDIT_NAME>> & {
33+
report?: ReportOnyxType;
34+
};
3135

32-
function GroupChatNameEditPage({groupChatDraft, route}: GroupChatNameEditPageProps) {
33-
// If we have a reportID this means we are using this page to update an existing Group Chat name
34-
const reportID = route.params?.reportID ?? '';
36+
function GroupChatNameEditPage({groupChatDraft, report}: GroupChatNameEditPageProps) {
37+
// If we have a report this means we are using this page to update an existing Group Chat name
38+
const reportID = report?.reportID ?? '';
3539
const isUpdatingExistingReport = Boolean(reportID);
3640

3741
const styles = useThemeStyles();
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type {StackScreenProps} from '@react-navigation/stack';
2+
import React from 'react';
3+
import * as ReportUtils from '@libs/ReportUtils';
4+
import type {ReportSettingsNavigatorParamList} from '@navigation/types';
5+
import GroupChatNameEditPage from '@pages/GroupChatNameEditPage';
6+
import withReportOrNotFound from '@pages/home/report/withReportOrNotFound';
7+
import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound';
8+
import type SCREENS from '@src/SCREENS';
9+
import RoomNamePage from './RoomNamePage';
10+
11+
type NamePageProps = WithReportOrNotFoundProps & StackScreenProps<ReportSettingsNavigatorParamList, typeof SCREENS.REPORT_SETTINGS.NAME>;
12+
13+
function NamePage({report}: NamePageProps) {
14+
if (ReportUtils.isGroupChat(report)) {
15+
return <GroupChatNameEditPage report={report} />;
16+
}
17+
return <RoomNamePage report={report} />;
18+
}
19+
20+
NamePage.displayName = 'NamePage';
21+
22+
export default withReportOrNotFound()(NamePage);

src/pages/settings/Report/ReportSettingsPage.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) {
9696
shouldShowRightIcon
9797
title={report?.reportName === '' ? reportName : report?.reportName}
9898
description={isGroupChat ? translate('common.name') : translate('newRoomPage.roomName')}
99-
onPress={() =>
100-
isGroupChat
101-
? Navigation.navigate(ROUTES.REPORT_SETTINGS_GROUP_NAME.getRoute(reportID))
102-
: Navigation.navigate(ROUTES.REPORT_SETTINGS_ROOM_NAME.getRoute(reportID))
103-
}
99+
onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_NAME.getRoute(reportID))}
104100
/>
105101
)}
106102
</OfflineWithFeedback>

src/pages/settings/Report/RoomNamePage.tsx

+11-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {useIsFocused} from '@react-navigation/native';
2-
import type {StackScreenProps} from '@react-navigation/stack';
32
import React, {useCallback, useRef} from 'react';
43
import {View} from 'react-native';
54
import {withOnyx} from 'react-native-onyx';
@@ -18,14 +17,10 @@ import * as ErrorUtils from '@libs/ErrorUtils';
1817
import Navigation from '@libs/Navigation/Navigation';
1918
import * as ReportUtils from '@libs/ReportUtils';
2019
import * as ValidationUtils from '@libs/ValidationUtils';
21-
import type {ReportSettingsNavigatorParamList} from '@navigation/types';
22-
import withReportOrNotFound from '@pages/home/report/withReportOrNotFound';
23-
import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound';
2420
import * as ReportActions from '@userActions/Report';
2521
import CONST from '@src/CONST';
2622
import ONYXKEYS from '@src/ONYXKEYS';
2723
import ROUTES from '@src/ROUTES';
28-
import type SCREENS from '@src/SCREENS';
2924
import INPUT_IDS from '@src/types/form/RoomNameForm';
3025
import type {Policy, Report} from '@src/types/onyx';
3126

@@ -37,7 +32,9 @@ type RoomNamePageOnyxProps = {
3732
policy: OnyxEntry<Policy>;
3833
};
3934

40-
type RoomNamePageProps = RoomNamePageOnyxProps & WithReportOrNotFoundProps & StackScreenProps<ReportSettingsNavigatorParamList, typeof SCREENS.REPORT_SETTINGS.ROOM_NAME>;
35+
type RoomNamePageProps = RoomNamePageOnyxProps & {
36+
report: Report;
37+
};
4138

4239
function RoomNamePage({report, policy, reports}: RoomNamePageProps) {
4340
const styles = useThemeStyles();
@@ -111,13 +108,11 @@ function RoomNamePage({report, policy, reports}: RoomNamePageProps) {
111108

112109
RoomNamePage.displayName = 'RoomNamePage';
113110

114-
export default withReportOrNotFound()(
115-
withOnyx<RoomNamePageProps, RoomNamePageOnyxProps>({
116-
reports: {
117-
key: ONYXKEYS.COLLECTION.REPORT,
118-
},
119-
policy: {
120-
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`,
121-
},
122-
})(RoomNamePage),
123-
);
111+
export default withOnyx<RoomNamePageProps, RoomNamePageOnyxProps>({
112+
reports: {
113+
key: ONYXKEYS.COLLECTION.REPORT,
114+
},
115+
policy: {
116+
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`,
117+
},
118+
})(RoomNamePage);

0 commit comments

Comments
 (0)