Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine report name routes #42369

Merged
merged 4 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,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',
Expand Down
3 changes: 1 addition & 2 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,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',
Expand Down
4 changes: 2 additions & 2 deletions src/components/TextInput/BaseTextInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ function BaseTextInput(
defaultValue={defaultValue}
markdownStyle={markdownStyle}
/>
{isFocused && !isReadOnly && shouldShowClearButton && value && <TextInputClearButton onPressButton={() => setValue('')} />}
{isFocused && !isReadOnly && shouldShowClearButton && !!value && <TextInputClearButton onPressButton={() => setValue('')} />}
{inputProps.isLoading && (
<ActivityIndicator
size="small"
Expand All @@ -422,7 +422,7 @@ function BaseTextInput(
/>
</Checkbox>
)}
{!inputProps.secureTextEntry && icon && (
{!inputProps.secureTextEntry && !!icon && (
<View style={[styles.textInputIconContainer, !isReadOnly ? styles.cursorPointer : styles.pointerEventsNone]}>
<Icon
src={icon}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ const ReportDetailsModalStackNavigator = createModalStackNavigator<ReportDetails

const ReportSettingsModalStackNavigator = createModalStackNavigator<ReportSettingsNavigatorParamList>({
[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,
Expand Down
7 changes: 2 additions & 5 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,11 +518,8 @@ const config: LinkingOptions<RootStackParamList>['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,
Expand Down
13 changes: 5 additions & 8 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,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 = {
Expand All @@ -425,11 +423,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;
};
Expand Down
14 changes: 9 additions & 5 deletions src/pages/GroupChatNameEditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,31 @@ 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 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 as ReportOnyxType} from '@src/types/onyx';
import type NewGroupChatDraft from '@src/types/onyx/NewGroupChatDraft';
import type {Errors} from '@src/types/onyx/OnyxCommon';

type GroupChatNameEditPageOnyxProps = {
groupChatDraft: NewGroupChatDraft | null;
};

type GroupChatNameEditPageProps = StackScreenProps<NewChatNavigatorParamList, typeof SCREENS.NEW_CHAT.NEW_CHAT_EDIT_NAME> & GroupChatNameEditPageOnyxProps;
type GroupChatNameEditPageProps = GroupChatNameEditPageOnyxProps &
Partial<StackScreenProps<NewChatNavigatorParamList, typeof SCREENS.NEW_CHAT.NEW_CHAT_EDIT_NAME>> & {
report?: ReportOnyxType;
};

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();
Expand Down
22 changes: 22 additions & 0 deletions src/pages/settings/Report/NamePage.tsx
Original file line number Diff line number Diff line change
@@ -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<ReportSettingsNavigatorParamList, typeof SCREENS.REPORT_SETTINGS.NAME>;

function NamePage({report}: NamePageProps) {
if (ReportUtils.isGroupChat(report)) {
return <GroupChatNameEditPage report={report} />;
}
return <RoomNamePage report={report} />;
}

NamePage.displayName = 'NamePage';

export default withReportOrNotFound()(NamePage);
6 changes: 1 addition & 5 deletions src/pages/settings/Report/ReportSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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))}
/>
)}
</OfflineWithFeedback>
Expand Down
27 changes: 11 additions & 16 deletions src/pages/settings/Report/RoomNamePage.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';

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

type RoomNamePageProps = RoomNamePageOnyxProps & WithReportOrNotFoundProps & StackScreenProps<ReportSettingsNavigatorParamList, typeof SCREENS.REPORT_SETTINGS.ROOM_NAME>;
type RoomNamePageProps = RoomNamePageOnyxProps & {
report: Report;
};

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

RoomNamePage.displayName = 'RoomNamePage';

export default withReportOrNotFound()(
withOnyx<RoomNamePageProps, RoomNamePageOnyxProps>({
reports: {
key: ONYXKEYS.COLLECTION.REPORT,
},
policy: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`,
},
})(RoomNamePage),
);
export default withOnyx<RoomNamePageProps, RoomNamePageOnyxProps>({
reports: {
key: ONYXKEYS.COLLECTION.REPORT,
},
policy: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`,
},
})(RoomNamePage);
Loading