Skip to content

Commit

Permalink
Merge pull request #43027 from s77rt/group-chat-cleanup
Browse files Browse the repository at this point in the history
Group chat cleanup
  • Loading branch information
marcaaron authored Jun 4, 2024
2 parents 23ee5bc + 2dd3769 commit 9b179ce
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ type SettingsNavigatorParamList = {

type NewChatNavigatorParamList = {
[SCREENS.NEW_CHAT.ROOT]: undefined;
[SCREENS.NEW_CHAT.NEW_CHAT_CONFIRM]: undefined;
[SCREENS.NEW_CHAT.NEW_CHAT_EDIT_NAME]: undefined;
};

Expand Down
39 changes: 21 additions & 18 deletions src/pages/NewChatConfirmPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useMemo, useRef} from 'react';
import React, {useCallback, useMemo, useRef} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
Expand Down Expand Up @@ -35,6 +35,14 @@ type NewChatConfirmPageOnyxProps = {

type NewChatConfirmPageProps = NewChatConfirmPageOnyxProps;

function navigateBack() {
Navigation.goBack(ROUTES.NEW_CHAT);
}

function navigateToEditChatName() {
Navigation.navigate(ROUTES.NEW_CHAT_EDIT_NAME);
}

function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmPageProps) {
const optimisticReportID = useRef<string>(ReportUtils.generateReportID());
const fileRef = useRef<File | CustomRNImageManipulatorResult | undefined>();
Expand Down Expand Up @@ -79,30 +87,25 @@ function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmP
/**
* Removes a selected option from list if already selected.
*/
const unselectOption = (option: ListItem) => {
if (!newGroupDraft) {
return;
}
const newSelectedParticipants = (newGroupDraft.participants ?? []).filter((participant) => participant.login !== option.login);
Report.setGroupDraft({participants: newSelectedParticipants});
};
const unselectOption = useCallback(
(option: ListItem) => {
if (!newGroupDraft) {
return;
}
const newSelectedParticipants = (newGroupDraft.participants ?? []).filter((participant) => participant.login !== option.login);
Report.setGroupDraft({participants: newSelectedParticipants});
},
[newGroupDraft],
);

const createGroup = () => {
const createGroup = useCallback(() => {
if (!newGroupDraft) {
return;
}

const logins: string[] = (newGroupDraft.participants ?? []).map((participant) => participant.login);
Report.navigateToAndOpenReport(logins, true, newGroupDraft.reportName ?? '', newGroupDraft.avatarUri ?? '', fileRef.current, optimisticReportID.current, true);
};

const navigateBack = () => {
Navigation.goBack(ROUTES.NEW_CHAT);
};

const navigateToEditChatName = () => {
Navigation.navigate(ROUTES.NEW_CHAT_EDIT_NAME);
};
}, [newGroupDraft]);

const stashedLocalAvatarImage = newGroupDraft?.avatarUri;
return (
Expand Down
4 changes: 2 additions & 2 deletions src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
/>
) : null;

const renderAvatar = useMemo(() => {
const renderedAvatar = useMemo(() => {
if (isMoneyRequestReport || isInvoiceReport) {
return (
<View style={styles.mb3}>
Expand Down Expand Up @@ -319,7 +319,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
/>
<ScrollView style={[styles.flex1]}>
<View style={styles.reportDetailsTitleContainer}>
{renderAvatar}
{renderedAvatar}
<View style={[styles.reportDetailsRoomInfo, styles.mw100]}>
<View style={[styles.alignSelfCenter, styles.w100, styles.mt1]}>
<DisplayNames
Expand Down
5 changes: 5 additions & 0 deletions src/pages/ReportParticipantDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {PersonalDetails, PersonalDetailsList} from '@src/types/onyx';
import NotFoundPage from './ErrorPage/NotFoundPage';
import withReportOrNotFound from './home/report/withReportOrNotFound';
import type {WithReportOrNotFoundProps} from './home/report/withReportOrNotFound';

Expand Down Expand Up @@ -69,6 +70,10 @@ function ReportParticipantDetails({personalDetails, report, route}: ReportPartic
Navigation.navigate(ROUTES.REPORT_PARTICIPANTS_ROLE_SELECTION.getRoute(report.reportID, accountID));
}, [accountID, report.reportID]);

if (!member) {
return <NotFoundPage />;
}

return (
<ScreenWrapper testID={ReportParticipantDetails.displayName}>
<HeaderWithBackButton
Expand Down

0 comments on commit 9b179ce

Please sign in to comment.