From 527be86fb0b2edd0edb2aa0550074935d9300cf3 Mon Sep 17 00:00:00 2001 From: Blazej Kustra <blazej.kustra@swmansion.com> Date: Wed, 8 Jan 2025 16:24:28 +0100 Subject: [PATCH 01/11] Add trip room check to disable rename functionality --- src/libs/ReportUtils.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 9c6377474e78..a51ed898b416 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7471,7 +7471,8 @@ function shouldDisableRename(report: OnyxEntry<Report>): boolean { isPolicyExpenseChat(report) || isInvoiceRoom(report) || isInvoiceReport(report) || - isSystemChat(report) + isSystemChat(report) || + isTripRoom(report) ) { return true; } From f37454766a454e480030772144552292988a06c9 Mon Sep 17 00:00:00 2001 From: Blazej Kustra <blazej.kustra@swmansion.com> Date: Thu, 9 Jan 2025 15:29:39 +0100 Subject: [PATCH 02/11] Reuse group name edit functionality --- src/languages/en.ts | 4 +-- src/languages/es.ts | 4 +-- .../ModalStackNavigators/index.tsx | 2 +- ...tNameEditPage.tsx => ChatNameEditPage.tsx} | 26 +++++++------------ src/pages/NewChatConfirmPage.tsx | 2 +- src/pages/ReportDetailsPage.tsx | 4 +-- src/pages/settings/Report/NamePage.tsx | 7 ++--- 7 files changed, 20 insertions(+), 29 deletions(-) rename src/pages/{GroupChatNameEditPage.tsx => ChatNameEditPage.tsx} (85%) diff --git a/src/languages/en.ts b/src/languages/en.ts index eda70330d332..df9a24f60698 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -1692,9 +1692,6 @@ const translations = { roomDescriptionOptional: 'Room description (optional)', explainerText: 'Set a custom description for the room.', }, - groupConfirmPage: { - groupName: 'Group name', - }, groupChat: { lastMemberTitle: 'Heads up!', lastMemberWarning: "Since you're the last person here, leaving will make this chat inaccessible to all members. Are you sure you want to leave?", @@ -4562,6 +4559,7 @@ const translations = { }, newRoomPage: { newRoom: 'New room', + groupName: 'Group name', roomName: 'Room name', visibility: 'Visibility', restrictedDescription: 'People in your workspace can find this room', diff --git a/src/languages/es.ts b/src/languages/es.ts index ca12b0447bb6..d6c5816844f2 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -1695,9 +1695,6 @@ const translations = { roomDescriptionOptional: 'Descripción de la sala de chat (opcional)', explainerText: 'Establece una descripción personalizada para la sala de chat.', }, - groupConfirmPage: { - groupName: 'Nombre del grupo', - }, groupChat: { lastMemberTitle: '¡Atención!', lastMemberWarning: 'Ya que eres la última persona aquí, si te vas, este chat quedará inaccesible para todos los miembros. ¿Estás seguro de que quieres salir del chat?', @@ -4609,6 +4606,7 @@ const translations = { }, newRoomPage: { newRoom: 'Nueva sala de chat', + groupName: 'Nombre del grupo', roomName: 'Nombre de la sala', visibility: 'Visibilidad', restrictedDescription: 'Sólo las personas en tu espacio de trabajo pueden encontrar esta sala', diff --git a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx index e05d316bd8ca..52a22d9fe5f4 100644 --- a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx +++ b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx @@ -198,7 +198,7 @@ const RoomMembersModalStackNavigator = createModalStackNavigator<RoomMembersNavi const NewChatModalStackNavigator = createModalStackNavigator<NewChatNavigatorParamList>({ [SCREENS.NEW_CHAT.ROOT]: () => require<ReactComponentModule>('../../../../pages/NewChatSelectorPage').default, [SCREENS.NEW_CHAT.NEW_CHAT_CONFIRM]: () => require<ReactComponentModule>('../../../../pages/NewChatConfirmPage').default, - [SCREENS.NEW_CHAT.NEW_CHAT_EDIT_NAME]: () => require<ReactComponentModule>('../../../../pages/GroupChatNameEditPage').default, + [SCREENS.NEW_CHAT.NEW_CHAT_EDIT_NAME]: () => require<ReactComponentModule>('../../../../pages/ChatNameEditPage').default, }); const NewTaskModalStackNavigator = createModalStackNavigator<NewTaskNavigatorParamList>({ diff --git a/src/pages/GroupChatNameEditPage.tsx b/src/pages/ChatNameEditPage.tsx similarity index 85% rename from src/pages/GroupChatNameEditPage.tsx rename to src/pages/ChatNameEditPage.tsx index 69d7f6c6f8af..1331650c9ff8 100644 --- a/src/pages/GroupChatNameEditPage.tsx +++ b/src/pages/ChatNameEditPage.tsx @@ -1,6 +1,6 @@ import React, {useCallback, useMemo} from 'react'; import type {OnyxEntry} from 'react-native-onyx'; -import {withOnyx} from 'react-native-onyx'; +import {useOnyx, withOnyx} from 'react-native-onyx'; import FormProvider from '@components/Form/FormProvider'; import InputWrapper from '@components/Form/InputWrapper'; import type {FormOnyxValues} from '@components/Form/types'; @@ -25,20 +25,18 @@ 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: OnyxEntry<NewGroupChatDraft>; +type ChatNameEditPageProps = Partial<PlatformStackScreenProps<NewChatNavigatorParamList, typeof SCREENS.NEW_CHAT.NEW_CHAT_EDIT_NAME>> & { + report?: ReportOnyxType; }; -type GroupChatNameEditPageProps = GroupChatNameEditPageOnyxProps & - Partial<PlatformStackScreenProps<NewChatNavigatorParamList, typeof SCREENS.NEW_CHAT.NEW_CHAT_EDIT_NAME>> & { - report?: ReportOnyxType; - }; +function ChatNameEditPage({report}: ChatNameEditPageProps) { + const [groupChatDraft] = useOnyx(ONYXKEYS.NEW_GROUP_CHAT_DRAFT); -function GroupChatNameEditPage({groupChatDraft, report}: GroupChatNameEditPageProps) { // If we have a report this means we are using this page to update an existing Group Chat name // In this case its better to use empty string as the reportID if there is no reportID const reportID = report?.reportID ?? ''; const isUpdatingExistingReport = !!reportID; + const isTripRoom = ReportUtils.isTripRoom(report); const styles = useThemeStyles(); const {translate} = useLocalize(); @@ -84,11 +82,11 @@ function GroupChatNameEditPage({groupChatDraft, report}: GroupChatNameEditPagePr <ScreenWrapper includeSafeAreaPaddingBottom style={[styles.defaultModalContainer]} - testID={GroupChatNameEditPage.displayName} + testID={ChatNameEditPage.displayName} shouldEnableMaxHeight > <HeaderWithBackButton - title={translate('groupConfirmPage.groupName')} + title={translate(isTripRoom ? 'newRoomPage.roomName' : 'newRoomPage.groupName')} onBackButtonPress={() => Navigation.goBack(isUpdatingExistingReport ? ROUTES.REPORT_WITH_ID_DETAILS.getRoute(reportID) : ROUTES.NEW_CHAT_CONFIRM)} /> <FormProvider @@ -115,10 +113,6 @@ function GroupChatNameEditPage({groupChatDraft, report}: GroupChatNameEditPagePr ); } -GroupChatNameEditPage.displayName = 'GroupChatNameEditPage'; +ChatNameEditPage.displayName = 'ChatNameEditPage'; -export default withOnyx<GroupChatNameEditPageProps, GroupChatNameEditPageOnyxProps>({ - groupChatDraft: { - key: ONYXKEYS.NEW_GROUP_CHAT_DRAFT, - }, -})(GroupChatNameEditPage); +export default ChatNameEditPage; diff --git a/src/pages/NewChatConfirmPage.tsx b/src/pages/NewChatConfirmPage.tsx index 85e33cf0c598..5aba6752d2fa 100644 --- a/src/pages/NewChatConfirmPage.tsx +++ b/src/pages/NewChatConfirmPage.tsx @@ -164,7 +164,7 @@ function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmP onPress={navigateToEditChatName} shouldShowRightIcon shouldCheckActionAllowedOnPress={false} - description={translate('groupConfirmPage.groupName')} + description={translate('newRoomPage.groupName')} wrapperStyle={[styles.ph4]} /> <View style={[styles.flex1, styles.mt3]}> diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index 166b12b27751..ee57e61be5c4 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -288,11 +288,11 @@ function ReportDetailsPage({policies, report, route, reportMetadata}: ReportDeta ? chatRoomSubtitle : `${translate('threads.in')} ${chatRoomSubtitle}`; - let roomDescription; + let roomDescription: string | undefined; if (caseID === CASES.MONEY_REQUEST) { roomDescription = translate('common.name'); } else if (isGroupChat) { - roomDescription = translate('groupConfirmPage.groupName'); + roomDescription = translate('newRoomPage.groupName'); } else { roomDescription = translate('newRoomPage.roomName'); } diff --git a/src/pages/settings/Report/NamePage.tsx b/src/pages/settings/Report/NamePage.tsx index f8ee44ccaa5f..f9c0f6c85956 100644 --- a/src/pages/settings/Report/NamePage.tsx +++ b/src/pages/settings/Report/NamePage.tsx @@ -2,7 +2,7 @@ import React from 'react'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import * as ReportUtils from '@libs/ReportUtils'; import type {ReportSettingsNavigatorParamList} from '@navigation/types'; -import GroupChatNameEditPage from '@pages/GroupChatNameEditPage'; +import ChatNameEditPage from '@pages/ChatNameEditPage'; import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound'; import type SCREENS from '@src/SCREENS'; @@ -11,9 +11,10 @@ import RoomNamePage from './RoomNamePage'; type NamePageProps = WithReportOrNotFoundProps & PlatformStackScreenProps<ReportSettingsNavigatorParamList, typeof SCREENS.REPORT_SETTINGS.NAME>; function NamePage({report}: NamePageProps) { - if (ReportUtils.isGroupChat(report)) { - return <GroupChatNameEditPage report={report} />; + if (ReportUtils.isGroupChat(report) || ReportUtils.isTripRoom(report)) { + return <ChatNameEditPage report={report} />; } + return <RoomNamePage report={report} />; } From c31b02d49c12d17dd9bd50225f4a64c452ec869e Mon Sep 17 00:00:00 2001 From: Blazej Kustra <blazej.kustra@swmansion.com> Date: Wed, 29 Jan 2025 11:10:28 +0100 Subject: [PATCH 03/11] Bring back old changes --- .../{ChatNameEditPage.tsx => GroupChatNameEditPage.tsx} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename src/pages/{ChatNameEditPage.tsx => GroupChatNameEditPage.tsx} (96%) diff --git a/src/pages/ChatNameEditPage.tsx b/src/pages/GroupChatNameEditPage.tsx similarity index 96% rename from src/pages/ChatNameEditPage.tsx rename to src/pages/GroupChatNameEditPage.tsx index b33e31405afb..66cc4b0a2329 100644 --- a/src/pages/ChatNameEditPage.tsx +++ b/src/pages/GroupChatNameEditPage.tsx @@ -80,11 +80,11 @@ function GroupChatNameEditPage({report}: GroupChatNameEditPageProps) { <ScreenWrapper includeSafeAreaPaddingBottom style={[styles.defaultModalContainer]} - testID={ChatNameEditPage.displayName} + testID={GroupChatNameEditPage.displayName} shouldEnableMaxHeight > <HeaderWithBackButton - title={translate(isTripRoom ? 'newRoomPage.roomName' : 'newRoomPage.groupName')} + title={translate('groupConfirmPage.groupName')} onBackButtonPress={() => Navigation.goBack(isUpdatingExistingReport ? ROUTES.REPORT_WITH_ID_DETAILS.getRoute(reportID) : ROUTES.NEW_CHAT_CONFIRM)} /> <FormProvider @@ -111,6 +111,6 @@ function GroupChatNameEditPage({report}: GroupChatNameEditPageProps) { ); } -ChatNameEditPage.displayName = 'ChatNameEditPage'; +GroupChatNameEditPage.displayName = 'GroupChatNameEditPage'; export default GroupChatNameEditPage; From 701567e679deabfe1bcc2dfb7893ccd1a0874e9a Mon Sep 17 00:00:00 2001 From: Blazej Kustra <blazej.kustra@swmansion.com> Date: Wed, 29 Jan 2025 13:38:59 +0100 Subject: [PATCH 04/11] Revert shouldDisableRename changes --- src/libs/ReportUtils.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 018a8fe9e696..5e50f69e28fa 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7674,8 +7674,7 @@ function shouldDisableRename(report: OnyxEntry<Report>): boolean { isPolicyExpenseChat(report) || isInvoiceRoom(report) || isInvoiceReport(report) || - isSystemChat(report) || - isTripRoom(report) + isSystemChat(report) ) { return true; } From 104c5f69550605fd5360304900d0af56c20d6199 Mon Sep 17 00:00:00 2001 From: Blazej Kustra <blazej.kustra@swmansion.com> Date: Wed, 29 Jan 2025 13:39:30 +0100 Subject: [PATCH 05/11] Add new command nad params --- .../API/parameters/UpdateChatNameParams.ts | 6 +++ .../parameters/UpdateGroupChatNameParams.ts | 5 -- src/libs/API/parameters/index.ts | 2 +- src/libs/API/types.ts | 4 +- src/libs/actions/Report.ts | 49 ++++++++++++++++++- 5 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 src/libs/API/parameters/UpdateChatNameParams.ts delete mode 100644 src/libs/API/parameters/UpdateGroupChatNameParams.ts diff --git a/src/libs/API/parameters/UpdateChatNameParams.ts b/src/libs/API/parameters/UpdateChatNameParams.ts new file mode 100644 index 000000000000..02ced292dc70 --- /dev/null +++ b/src/libs/API/parameters/UpdateChatNameParams.ts @@ -0,0 +1,6 @@ +type UpdateChatNameParams = { + reportName: string; + reportID: string; +}; + +export default UpdateChatNameParams; diff --git a/src/libs/API/parameters/UpdateGroupChatNameParams.ts b/src/libs/API/parameters/UpdateGroupChatNameParams.ts deleted file mode 100644 index 572548e629b4..000000000000 --- a/src/libs/API/parameters/UpdateGroupChatNameParams.ts +++ /dev/null @@ -1,5 +0,0 @@ -type UpdateGroupChatNameParams = { - reportName: string; - reportID: string; -}; -export default UpdateGroupChatNameParams; diff --git a/src/libs/API/parameters/index.ts b/src/libs/API/parameters/index.ts index ef4e5fee72d8..f5a60b98ab84 100644 --- a/src/libs/API/parameters/index.ts +++ b/src/libs/API/parameters/index.ts @@ -69,7 +69,7 @@ export type {default as UpdateAutomaticTimezoneParams} from './UpdateAutomaticTi export type {default as UpdateChatPriorityModeParams} from './UpdateChatPriorityModeParams'; export type {default as UpdateDateOfBirthParams} from './UpdateDateOfBirthParams'; export type {default as UpdateDisplayNameParams} from './UpdateDisplayNameParams'; -export type {default as UpdateGroupChatNameParams} from './UpdateGroupChatNameParams'; +export type {default as UpdateChatNameParams} from './UpdateChatNameParams'; export type {default as UpdateGroupChatMemberRolesParams} from './UpdateGroupChatMemberRolesParams'; export type {default as UpdateHomeAddressParams} from './UpdateHomeAddressParams'; export type {default as UpdatePolicyAddressParams} from './UpdatePolicyAddressParams'; diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index dda49917f9c5..b6894f57fe20 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -124,6 +124,7 @@ const WRITE_COMMANDS = { LEAVE_GROUP_CHAT: 'LeaveGroupChat', INVITE_TO_ROOM: 'InviteToRoom', INVITE_TO_GROUP_CHAT: 'InviteToGroupChat', + UPDATE_TRIP_ROOM_NAME: 'UpdateTripRoomName', UPDATE_GROUP_CHAT_NAME: 'UpdateGroupChatName', UPDATE_GROUP_CHAT_MEMBER_ROLES: 'UpdateGroupChatMemberRoles', REMOVE_FROM_ROOM: 'RemoveFromRoom', @@ -559,7 +560,8 @@ type WriteCommandParameters = { [WRITE_COMMANDS.LEAVE_GROUP_CHAT]: Parameters.LeaveGroupChatParams; [WRITE_COMMANDS.REMOVE_FROM_GROUP_CHAT]: Parameters.RemoveFromGroupChatParams; [WRITE_COMMANDS.UPDATE_GROUP_CHAT_MEMBER_ROLES]: Parameters.UpdateGroupChatMemberRolesParams; - [WRITE_COMMANDS.UPDATE_GROUP_CHAT_NAME]: Parameters.UpdateGroupChatNameParams; + [WRITE_COMMANDS.UPDATE_TRIP_ROOM_NAME]: Parameters.UpdateChatNameParams; + [WRITE_COMMANDS.UPDATE_GROUP_CHAT_NAME]: Parameters.UpdateChatNameParams; [WRITE_COMMANDS.REMOVE_FROM_ROOM]: Parameters.RemoveFromRoomParams; [WRITE_COMMANDS.FLAG_COMMENT]: Parameters.FlagCommentParams; [WRITE_COMMANDS.UPDATE_REPORT_PRIVATE_NOTE]: Parameters.UpdateReportPrivateNoteParams; diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index fa6046c6baa4..3be18eb34626 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -38,10 +38,10 @@ import type { SearchForReportsParams, SearchForRoomsToMentionParams, TogglePinnedChatParams, + UpdateChatNameParams, UpdateCommentParams, UpdateGroupChatAvatarParams, UpdateGroupChatMemberRolesParams, - UpdateGroupChatNameParams, UpdatePolicyRoomNameParams, UpdateReportNotificationPreferenceParams, UpdateReportPrivateNoteParams, @@ -725,6 +725,50 @@ function reportActionsExist(reportID: string): boolean { return allReportActions?.[reportID] !== undefined; } +function updateTripChatName(reportID: string, reportName: string) { + const optimisticData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: { + reportName, + pendingFields: { + reportName: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + }, + errorFields: { + reportName: null, + }, + }, + }, + ]; + + const successData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: { + pendingFields: { + reportName: null, + }, + }, + }, + ]; + const failureData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: { + reportName: allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]?.reportName ?? null, + pendingFields: { + reportName: null, + }, + }, + }, + ]; + const parameters: UpdateChatNameParams = {reportName, reportID}; + API.write(WRITE_COMMANDS.UPDATE_TRIP_ROOM_NAME, parameters, {optimisticData, successData, failureData}); +} + function updateGroupChatName(reportID: string, reportName: string) { const optimisticData: OnyxUpdate[] = [ { @@ -765,7 +809,7 @@ function updateGroupChatName(reportID: string, reportName: string) { }, }, ]; - const parameters: UpdateGroupChatNameParams = {reportName, reportID}; + const parameters: UpdateChatNameParams = {reportName, reportID}; API.write(WRITE_COMMANDS.UPDATE_GROUP_CHAT_NAME, parameters, {optimisticData, successData, failureData}); } @@ -4733,6 +4777,7 @@ export { updateDescription, updateGroupChatAvatar, updateGroupChatMemberRoles, + updateTripChatName, updateGroupChatName, updateLastVisitTime, updateLoadingInitialReportAction, From 872911e92d581b8621c59240a67a8d1c274481c6 Mon Sep 17 00:00:00 2001 From: Blazej Kustra <blazej.kustra@swmansion.com> Date: Wed, 29 Jan 2025 13:40:25 +0100 Subject: [PATCH 06/11] Update group chat name edit page navigation and translation --- src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx | 2 +- src/pages/GroupChatNameEditPage.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx index eccbaf8af6e1..f96db7a81a02 100644 --- a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx +++ b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx @@ -206,7 +206,7 @@ const RoomMembersModalStackNavigator = createModalStackNavigator<RoomMembersNavi const NewChatModalStackNavigator = createModalStackNavigator<NewChatNavigatorParamList>({ [SCREENS.NEW_CHAT.ROOT]: () => require<ReactComponentModule>('../../../../pages/NewChatSelectorPage').default, [SCREENS.NEW_CHAT.NEW_CHAT_CONFIRM]: () => require<ReactComponentModule>('../../../../pages/NewChatConfirmPage').default, - [SCREENS.NEW_CHAT.NEW_CHAT_EDIT_NAME]: () => require<ReactComponentModule>('../../../../pages/ChatNameEditPage').default, + [SCREENS.NEW_CHAT.NEW_CHAT_EDIT_NAME]: () => require<ReactComponentModule>('../../../../pages/GroupChatNameEditPage').default, }); const NewTaskModalStackNavigator = createModalStackNavigator<NewTaskNavigatorParamList>({ diff --git a/src/pages/GroupChatNameEditPage.tsx b/src/pages/GroupChatNameEditPage.tsx index 66cc4b0a2329..70c8ffc4df09 100644 --- a/src/pages/GroupChatNameEditPage.tsx +++ b/src/pages/GroupChatNameEditPage.tsx @@ -84,7 +84,7 @@ function GroupChatNameEditPage({report}: GroupChatNameEditPageProps) { shouldEnableMaxHeight > <HeaderWithBackButton - title={translate('groupConfirmPage.groupName')} + title={translate('newRoomPage.groupName')} onBackButtonPress={() => Navigation.goBack(isUpdatingExistingReport ? ROUTES.REPORT_WITH_ID_DETAILS.getRoute(reportID) : ROUTES.NEW_CHAT_CONFIRM)} /> <FormProvider From 99d1068481a71b83c9fba5bb5b67d3f4a8db1e91 Mon Sep 17 00:00:00 2001 From: Blazej Kustra <blazej.kustra@swmansion.com> Date: Wed, 29 Jan 2025 13:40:46 +0100 Subject: [PATCH 07/11] Add TripChatNameEditPage for editing trip chat names --- src/pages/TripChatNameEditPage.tsx | 97 ++++++++++++++++++++++++++ src/pages/settings/Report/NamePage.tsx | 11 ++- 2 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 src/pages/TripChatNameEditPage.tsx diff --git a/src/pages/TripChatNameEditPage.tsx b/src/pages/TripChatNameEditPage.tsx new file mode 100644 index 000000000000..2bad42ee051e --- /dev/null +++ b/src/pages/TripChatNameEditPage.tsx @@ -0,0 +1,97 @@ +import React, {useCallback} from 'react'; +import FormProvider from '@components/Form/FormProvider'; +import InputWrapper from '@components/Form/InputWrapper'; +import type {FormOnyxValues} from '@components/Form/types'; +import HeaderWithBackButton from '@components/HeaderWithBackButton'; +import ScreenWrapper from '@components/ScreenWrapper'; +import TextInput from '@components/TextInput'; +import useAutoFocusInput from '@hooks/useAutoFocusInput'; +import useLocalize from '@hooks/useLocalize'; +import useThemeStyles from '@hooks/useThemeStyles'; +import Navigation from '@libs/Navigation/Navigation'; +import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; +import type {NewChatNavigatorParamList} from '@libs/Navigation/types'; +import {getReportName} from '@libs/ReportUtils'; +import {isValidReportName} from '@libs/ValidationUtils'; +import {updateTripChatName} 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 {Errors} from '@src/types/onyx/OnyxCommon'; + +type TripChatNameEditPageProps = Partial<PlatformStackScreenProps<NewChatNavigatorParamList, typeof SCREENS.NEW_CHAT.NEW_CHAT_EDIT_NAME>> & { + report: Report; +}; + +function TripChatNameEditPage({report}: TripChatNameEditPageProps) { + const styles = useThemeStyles(); + const {translate} = useLocalize(); + const {inputCallbackRef} = useAutoFocusInput(); + + const reportID = report?.reportID; + const currentChatName = getReportName(report); + + const validate = useCallback( + (values: FormOnyxValues<typeof ONYXKEYS.FORMS.NEW_CHAT_NAME_FORM>): Errors => { + const errors: Errors = {}; + if (!isValidReportName(values[INPUT_IDS.NEW_CHAT_NAME] ?? '')) { + errors.newChatName = translate('common.error.characterLimit', {limit: CONST.REPORT_NAME_LIMIT}); + } + + return errors; + }, + [translate], + ); + + const editName = useCallback( + (values: FormOnyxValues<typeof ONYXKEYS.FORMS.NEW_CHAT_NAME_FORM>) => { + if (values[INPUT_IDS.NEW_CHAT_NAME] !== currentChatName) { + updateTripChatName(reportID, values[INPUT_IDS.NEW_CHAT_NAME] ?? ''); + } + + return Navigation.setNavigationActionToMicrotaskQueue(() => Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(reportID))); + }, + [reportID, currentChatName], + ); + + return ( + <ScreenWrapper + includeSafeAreaPaddingBottom + style={[styles.defaultModalContainer]} + testID={TripChatNameEditPage.displayName} + shouldEnableMaxHeight + > + <HeaderWithBackButton + title={translate('newRoomPage.roomName')} + onBackButtonPress={() => Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(reportID))} + /> + <FormProvider + formID={ONYXKEYS.FORMS.NEW_CHAT_NAME_FORM} + onSubmit={editName} + submitButtonText={translate('common.save')} + validate={validate} + style={[styles.mh5, styles.flex1]} + enabledWhenOffline + > + <InputWrapper + InputComponent={TextInput} + maxLength={CONST.REPORT_NAME_LIMIT} + defaultValue={currentChatName} + label={translate('common.name')} + accessibilityLabel={translate('common.name')} + inputID={INPUT_IDS.NEW_CHAT_NAME} + role={CONST.ROLE.PRESENTATION} + ref={inputCallbackRef} + shouldShowClearButton + /> + </FormProvider> + </ScreenWrapper> + ); +} + +TripChatNameEditPage.displayName = 'TripChatNameEditPage'; + +export default TripChatNameEditPage; diff --git a/src/pages/settings/Report/NamePage.tsx b/src/pages/settings/Report/NamePage.tsx index f9c0f6c85956..01a19e6f491c 100644 --- a/src/pages/settings/Report/NamePage.tsx +++ b/src/pages/settings/Report/NamePage.tsx @@ -2,17 +2,22 @@ import React from 'react'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import * as ReportUtils from '@libs/ReportUtils'; import type {ReportSettingsNavigatorParamList} from '@navigation/types'; -import ChatNameEditPage from '@pages/ChatNameEditPage'; +import GroupChatNameEditPage from '@pages/GroupChatNameEditPage'; import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound'; +import TripChatNameEditPage from '@pages/TripChatNameEditPage'; import type SCREENS from '@src/SCREENS'; import RoomNamePage from './RoomNamePage'; type NamePageProps = WithReportOrNotFoundProps & PlatformStackScreenProps<ReportSettingsNavigatorParamList, typeof SCREENS.REPORT_SETTINGS.NAME>; function NamePage({report}: NamePageProps) { - if (ReportUtils.isGroupChat(report) || ReportUtils.isTripRoom(report)) { - return <ChatNameEditPage report={report} />; + if (ReportUtils.isTripRoom(report)) { + return <TripChatNameEditPage report={report} />; + } + + if (ReportUtils.isGroupChat(report)) { + return <GroupChatNameEditPage report={report} />; } return <RoomNamePage report={report} />; From f918383eeb5ee5fe239d82c7f52d25460620285a Mon Sep 17 00:00:00 2001 From: Blazej Kustra <blazej.kustra@swmansion.com> Date: Wed, 29 Jan 2025 13:47:58 +0100 Subject: [PATCH 08/11] Refactor chat name update functions to use a single method --- src/libs/actions/Report.ts | 52 +++-------------------------- src/pages/GroupChatNameEditPage.tsx | 17 ++++------ src/pages/TripChatNameEditPage.tsx | 4 +-- 3 files changed, 14 insertions(+), 59 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 3be18eb34626..540298a93824 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -725,7 +725,7 @@ function reportActionsExist(reportID: string): boolean { return allReportActions?.[reportID] !== undefined; } -function updateTripChatName(reportID: string, reportName: string) { +function updateChatName(reportID: string, reportName: string, type: typeof CONST.REPORT.CHAT_TYPE.GROUP | typeof CONST.REPORT.CHAT_TYPE.TRIP_ROOM) { const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -765,52 +765,11 @@ function updateTripChatName(reportID: string, reportName: string) { }, }, ]; - const parameters: UpdateChatNameParams = {reportName, reportID}; - API.write(WRITE_COMMANDS.UPDATE_TRIP_ROOM_NAME, parameters, {optimisticData, successData, failureData}); -} -function updateGroupChatName(reportID: string, reportName: string) { - const optimisticData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - value: { - reportName, - pendingFields: { - reportName: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, - }, - errorFields: { - reportName: null, - }, - }, - }, - ]; - - const successData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - value: { - pendingFields: { - reportName: null, - }, - }, - }, - ]; - const failureData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - value: { - reportName: allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]?.reportName ?? null, - pendingFields: { - reportName: null, - }, - }, - }, - ]; + const command = type === CONST.REPORT.CHAT_TYPE.GROUP ? WRITE_COMMANDS.UPDATE_GROUP_CHAT_NAME : WRITE_COMMANDS.UPDATE_TRIP_ROOM_NAME; const parameters: UpdateChatNameParams = {reportName, reportID}; - API.write(WRITE_COMMANDS.UPDATE_GROUP_CHAT_NAME, parameters, {optimisticData, successData, failureData}); + + API.write(command, parameters, {optimisticData, successData, failureData}); } function updateGroupChatAvatar(reportID: string, file?: File | CustomRNImageManipulatorResult) { @@ -4777,8 +4736,7 @@ export { updateDescription, updateGroupChatAvatar, updateGroupChatMemberRoles, - updateTripChatName, - updateGroupChatName, + updateChatName, updateLastVisitTime, updateLoadingInitialReportAction, updateNotificationPreference, diff --git a/src/pages/GroupChatNameEditPage.tsx b/src/pages/GroupChatNameEditPage.tsx index 70c8ffc4df09..7c4d8aa41d00 100644 --- a/src/pages/GroupChatNameEditPage.tsx +++ b/src/pages/GroupChatNameEditPage.tsx @@ -12,9 +12,9 @@ import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {NewChatNavigatorParamList} from '@libs/Navigation/types'; -import * as ReportUtils from '@libs/ReportUtils'; -import * as ValidationUtils from '@libs/ValidationUtils'; -import * as Report from '@userActions/Report'; +import {getGroupChatName} from '@libs/ReportUtils'; +import {isValidReportName} from '@libs/ValidationUtils'; +import {setGroupDraft, updateChatName} from '@userActions/Report'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -38,17 +38,14 @@ function GroupChatNameEditPage({report}: GroupChatNameEditPageProps) { const {translate} = useLocalize(); const {inputCallbackRef} = useAutoFocusInput(); - const existingReportName = useMemo( - () => (report ? ReportUtils.getGroupChatName(undefined, false, report) : ReportUtils.getGroupChatName(groupChatDraft?.participants)), - [groupChatDraft?.participants, report], - ); + const existingReportName = useMemo(() => (report ? getGroupChatName(undefined, false, report) : getGroupChatName(groupChatDraft?.participants)), [groupChatDraft?.participants, report]); // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const currentChatName = reportID ? existingReportName : groupChatDraft?.reportName || existingReportName; const validate = useCallback( (values: FormOnyxValues<typeof ONYXKEYS.FORMS.NEW_CHAT_NAME_FORM>): Errors => { const errors: Errors = {}; - if (!ValidationUtils.isValidReportName(values[INPUT_IDS.NEW_CHAT_NAME] ?? '')) { + if (!isValidReportName(values[INPUT_IDS.NEW_CHAT_NAME] ?? '')) { errors.newChatName = translate('common.error.characterLimit', {limit: CONST.REPORT_NAME_LIMIT}); } @@ -61,7 +58,7 @@ function GroupChatNameEditPage({report}: GroupChatNameEditPageProps) { (values: FormOnyxValues<typeof ONYXKEYS.FORMS.NEW_CHAT_NAME_FORM>) => { if (isUpdatingExistingReport) { if (values[INPUT_IDS.NEW_CHAT_NAME] !== currentChatName) { - Report.updateGroupChatName(reportID, values[INPUT_IDS.NEW_CHAT_NAME] ?? ''); + updateChatName(reportID, values[INPUT_IDS.NEW_CHAT_NAME] ?? '', CONST.REPORT.CHAT_TYPE.GROUP); } Navigation.setNavigationActionToMicrotaskQueue(() => Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(reportID))); @@ -69,7 +66,7 @@ function GroupChatNameEditPage({report}: GroupChatNameEditPageProps) { return; } if (values[INPUT_IDS.NEW_CHAT_NAME] !== currentChatName) { - Report.setGroupDraft({reportName: values[INPUT_IDS.NEW_CHAT_NAME]}); + setGroupDraft({reportName: values[INPUT_IDS.NEW_CHAT_NAME]}); } Navigation.setNavigationActionToMicrotaskQueue(() => Navigation.goBack(ROUTES.NEW_CHAT_CONFIRM)); }, diff --git a/src/pages/TripChatNameEditPage.tsx b/src/pages/TripChatNameEditPage.tsx index 2bad42ee051e..1a68507f52c5 100644 --- a/src/pages/TripChatNameEditPage.tsx +++ b/src/pages/TripChatNameEditPage.tsx @@ -13,7 +13,7 @@ import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavig import type {NewChatNavigatorParamList} from '@libs/Navigation/types'; import {getReportName} from '@libs/ReportUtils'; import {isValidReportName} from '@libs/ValidationUtils'; -import {updateTripChatName} from '@userActions/Report'; +import {updateChatName} from '@userActions/Report'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -49,7 +49,7 @@ function TripChatNameEditPage({report}: TripChatNameEditPageProps) { const editName = useCallback( (values: FormOnyxValues<typeof ONYXKEYS.FORMS.NEW_CHAT_NAME_FORM>) => { if (values[INPUT_IDS.NEW_CHAT_NAME] !== currentChatName) { - updateTripChatName(reportID, values[INPUT_IDS.NEW_CHAT_NAME] ?? ''); + updateChatName(reportID, values[INPUT_IDS.NEW_CHAT_NAME] ?? '', CONST.REPORT.CHAT_TYPE.TRIP_ROOM); } return Navigation.setNavigationActionToMicrotaskQueue(() => Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(reportID))); From b8c450ddb198de3c93d760f07cad1b180fa33d8d Mon Sep 17 00:00:00 2001 From: Blazej Kustra <blazej.kustra@swmansion.com> Date: Wed, 29 Jan 2025 14:26:48 +0100 Subject: [PATCH 09/11] Refactor NewChatConfirmPage to use hooks and simplify imports --- src/pages/NewChatConfirmPage.tsx | 52 +++++++++----------------- src/pages/settings/Report/NamePage.tsx | 6 +-- 2 files changed, 21 insertions(+), 37 deletions(-) diff --git a/src/pages/NewChatConfirmPage.tsx b/src/pages/NewChatConfirmPage.tsx index 5e77904e126e..063b03db85e7 100644 --- a/src/pages/NewChatConfirmPage.tsx +++ b/src/pages/NewChatConfirmPage.tsx @@ -1,7 +1,6 @@ import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; import {View} from 'react-native'; -import {withOnyx} from 'react-native-onyx'; -import type {OnyxEntry} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import AvatarWithImagePicker from '@components/AvatarWithImagePicker'; import Badge from '@components/Badge'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; @@ -17,25 +16,14 @@ import useThemeStyles from '@hooks/useThemeStyles'; import type {CustomRNImageManipulatorResult} from '@libs/cropOrRotateImage/types'; import * as FileUtils from '@libs/fileDownload/FileUtils'; import Navigation from '@libs/Navigation/Navigation'; -import * as OptionsListUtils from '@libs/OptionsListUtils'; -import * as ReportUtils from '@libs/ReportUtils'; -import * as Report from '@userActions/Report'; +import {getParticipantsOption} from '@libs/OptionsListUtils'; +import {generateReportID, getDefaultGroupAvatar, getGroupChatName} from '@libs/ReportUtils'; +import {navigateToAndOpenReport, setGroupDraft} from '@userActions/Report'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import type * as OnyxTypes from '@src/types/onyx'; import type {Participant} from '@src/types/onyx/IOU'; -type NewChatConfirmPageOnyxProps = { - /** New group chat draft data */ - newGroupDraft: OnyxEntry<OnyxTypes.NewGroupChatDraft>; - - /** All of the personal details for everyone */ - allPersonalDetails: OnyxEntry<OnyxTypes.PersonalDetailsList>; -}; - -type NewChatConfirmPageProps = NewChatConfirmPageOnyxProps; - function navigateBack() { Navigation.goBack(ROUTES.NEW_CHAT); } @@ -44,23 +32,26 @@ function navigateToEditChatName() { Navigation.navigate(ROUTES.NEW_CHAT_EDIT_NAME); } -function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmPageProps) { - const optimisticReportID = useRef<string>(ReportUtils.generateReportID()); +function NewChatConfirmPage() { + const optimisticReportID = useRef<string>(generateReportID()); const [avatarFile, setAvatarFile] = useState<File | CustomRNImageManipulatorResult | undefined>(); const {translate} = useLocalize(); const styles = useThemeStyles(); const personalData = useCurrentUserPersonalDetails(); + const [newGroupDraft] = useOnyx(ONYXKEYS.NEW_GROUP_CHAT_DRAFT); + const [allPersonalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); + const selectedOptions = useMemo((): Participant[] => { if (!newGroupDraft?.participants) { return []; } const options: Participant[] = newGroupDraft.participants.map((participant) => - OptionsListUtils.getParticipantsOption({accountID: participant.accountID, login: participant?.login, reportID: ''}, allPersonalDetails), + getParticipantsOption({accountID: participant.accountID, login: participant?.login, reportID: ''}, allPersonalDetails), ); return options; }, [allPersonalDetails, newGroupDraft?.participants]); - const groupName = newGroupDraft?.reportName ? newGroupDraft?.reportName : ReportUtils.getGroupChatName(newGroupDraft?.participants); + const groupName = newGroupDraft?.reportName ? newGroupDraft?.reportName : getGroupChatName(newGroupDraft?.participants); const sections: ListItem[] = useMemo( () => selectedOptions @@ -93,7 +84,7 @@ function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmP return; } const newSelectedParticipants = (newGroupDraft.participants ?? []).filter((participant) => participant?.login !== option.login); - Report.setGroupDraft({participants: newSelectedParticipants}); + setGroupDraft({participants: newSelectedParticipants}); }, [newGroupDraft], ); @@ -104,7 +95,7 @@ function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmP } const logins: string[] = (newGroupDraft.participants ?? []).map((participant) => participant.login).filter((login): login is string => !!login); - Report.navigateToAndOpenReport(logins, true, undefined, newGroupDraft.reportName ?? '', newGroupDraft.avatarUri ?? '', avatarFile, optimisticReportID.current, true); + navigateToAndOpenReport(logins, true, undefined, newGroupDraft.reportName ?? '', newGroupDraft.avatarUri ?? '', avatarFile, optimisticReportID.current, true); }, [newGroupDraft, avatarFile]); const stashedLocalAvatarImage = newGroupDraft?.avatarUri; @@ -120,7 +111,7 @@ function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmP const onFailure = () => { setAvatarFile(undefined); - Report.setGroupDraft({avatarUri: null, avatarFileName: null, avatarFileType: null}); + setGroupDraft({avatarUri: null, avatarFileName: null, avatarFileType: null}); }; // If the user navigates back to the member selection page and then returns to the confirmation page, the component will re-mount, causing avatarFile to be null. @@ -141,14 +132,14 @@ function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmP <AvatarWithImagePicker isUsingDefaultAvatar={!stashedLocalAvatarImage} // eslint-disable-next-line react-compiler/react-compiler - source={stashedLocalAvatarImage ?? ReportUtils.getDefaultGroupAvatar(optimisticReportID.current)} + source={stashedLocalAvatarImage ?? getDefaultGroupAvatar(optimisticReportID.current)} onImageSelected={(image) => { setAvatarFile(image); - Report.setGroupDraft({avatarUri: image.uri ?? '', avatarFileName: image.name ?? '', avatarFileType: image.type}); + setGroupDraft({avatarUri: image.uri ?? '', avatarFileName: image.name ?? '', avatarFileType: image.type}); }} onImageRemoved={() => { setAvatarFile(undefined); - Report.setGroupDraft({avatarUri: null, avatarFileName: null, avatarFileType: null}); + setGroupDraft({avatarUri: null, avatarFileName: null, avatarFileType: null}); }} size={CONST.AVATAR_SIZE.XLARGE} avatarStyle={styles.avatarXLarge} @@ -185,11 +176,4 @@ function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmP NewChatConfirmPage.displayName = 'NewChatConfirmPage'; -export default withOnyx<NewChatConfirmPageProps, NewChatConfirmPageOnyxProps>({ - newGroupDraft: { - key: ONYXKEYS.NEW_GROUP_CHAT_DRAFT, - }, - allPersonalDetails: { - key: ONYXKEYS.PERSONAL_DETAILS_LIST, - }, -})(NewChatConfirmPage); +export default NewChatConfirmPage; diff --git a/src/pages/settings/Report/NamePage.tsx b/src/pages/settings/Report/NamePage.tsx index 01a19e6f491c..14c557940d37 100644 --- a/src/pages/settings/Report/NamePage.tsx +++ b/src/pages/settings/Report/NamePage.tsx @@ -1,6 +1,6 @@ import React from 'react'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; -import * as ReportUtils from '@libs/ReportUtils'; +import {isGroupChat, isTripRoom} from '@libs/ReportUtils'; import type {ReportSettingsNavigatorParamList} from '@navigation/types'; import GroupChatNameEditPage from '@pages/GroupChatNameEditPage'; import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; @@ -12,11 +12,11 @@ import RoomNamePage from './RoomNamePage'; type NamePageProps = WithReportOrNotFoundProps & PlatformStackScreenProps<ReportSettingsNavigatorParamList, typeof SCREENS.REPORT_SETTINGS.NAME>; function NamePage({report}: NamePageProps) { - if (ReportUtils.isTripRoom(report)) { + if (isTripRoom(report)) { return <TripChatNameEditPage report={report} />; } - if (ReportUtils.isGroupChat(report)) { + if (isGroupChat(report)) { return <GroupChatNameEditPage report={report} />; } From 0c0d85ce08910029f9aaded60f7dfbaf5183eced Mon Sep 17 00:00:00 2001 From: Blazej Kustra <blazej.kustra@swmansion.com> Date: Wed, 29 Jan 2025 15:14:27 +0100 Subject: [PATCH 10/11] Fix lint --- src/pages/NewChatConfirmPage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/NewChatConfirmPage.tsx b/src/pages/NewChatConfirmPage.tsx index 063b03db85e7..5df620d3b9e3 100644 --- a/src/pages/NewChatConfirmPage.tsx +++ b/src/pages/NewChatConfirmPage.tsx @@ -14,7 +14,7 @@ import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails' import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import type {CustomRNImageManipulatorResult} from '@libs/cropOrRotateImage/types'; -import * as FileUtils from '@libs/fileDownload/FileUtils'; +import {readFileAsync} from '@libs/fileDownload/FileUtils'; import Navigation from '@libs/Navigation/Navigation'; import {getParticipantsOption} from '@libs/OptionsListUtils'; import {generateReportID, getDefaultGroupAvatar, getGroupChatName} from '@libs/ReportUtils'; @@ -116,7 +116,7 @@ function NewChatConfirmPage() { // If the user navigates back to the member selection page and then returns to the confirmation page, the component will re-mount, causing avatarFile to be null. // To handle this, we re-read the avatar image file from disk whenever the component re-mounts. - FileUtils.readFileAsync(stashedLocalAvatarImage, newGroupDraft?.avatarFileName ?? '', onSuccess, onFailure, newGroupDraft?.avatarFileType ?? ''); + readFileAsync(stashedLocalAvatarImage, newGroupDraft?.avatarFileName ?? '', onSuccess, onFailure, newGroupDraft?.avatarFileType ?? ''); // we only need to run this when the component re-mounted // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps From 1f1d9c1168a2034092d8127826251af52b08eaec Mon Sep 17 00:00:00 2001 From: Blazej Kustra <blazej.kustra@swmansion.com> Date: Tue, 4 Feb 2025 10:36:56 -0800 Subject: [PATCH 11/11] Add validation for empty chat name in TripChatNameEditPage --- src/pages/TripChatNameEditPage.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/pages/TripChatNameEditPage.tsx b/src/pages/TripChatNameEditPage.tsx index 1a68507f52c5..c41c71292a11 100644 --- a/src/pages/TripChatNameEditPage.tsx +++ b/src/pages/TripChatNameEditPage.tsx @@ -12,6 +12,7 @@ import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {NewChatNavigatorParamList} from '@libs/Navigation/types'; import {getReportName} from '@libs/ReportUtils'; +import StringUtils from '@libs/StringUtils'; import {isValidReportName} from '@libs/ValidationUtils'; import {updateChatName} from '@userActions/Report'; import CONST from '@src/CONST'; @@ -41,6 +42,10 @@ function TripChatNameEditPage({report}: TripChatNameEditPageProps) { errors.newChatName = translate('common.error.characterLimit', {limit: CONST.REPORT_NAME_LIMIT}); } + if (StringUtils.isEmptyString(values[INPUT_IDS.NEW_CHAT_NAME] ?? '')) { + errors.newChatName = translate('common.error.fieldRequired'); + } + return errors; }, [translate],