|
1 |
| -import React, {useMemo, useRef} from 'react'; |
| 1 | +import React, {useCallback, useMemo, useRef} from 'react'; |
2 | 2 | import {View} from 'react-native';
|
3 | 3 | import {withOnyx} from 'react-native-onyx';
|
4 | 4 | import type {OnyxEntry} from 'react-native-onyx';
|
@@ -35,6 +35,14 @@ type NewChatConfirmPageOnyxProps = {
|
35 | 35 |
|
36 | 36 | type NewChatConfirmPageProps = NewChatConfirmPageOnyxProps;
|
37 | 37 |
|
| 38 | +function navigateBack() { |
| 39 | + Navigation.goBack(ROUTES.NEW_CHAT); |
| 40 | +} |
| 41 | + |
| 42 | +function navigateToEditChatName() { |
| 43 | + Navigation.navigate(ROUTES.NEW_CHAT_EDIT_NAME); |
| 44 | +} |
| 45 | + |
38 | 46 | function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmPageProps) {
|
39 | 47 | const optimisticReportID = useRef<string>(ReportUtils.generateReportID());
|
40 | 48 | const fileRef = useRef<File | CustomRNImageManipulatorResult | undefined>();
|
@@ -79,30 +87,25 @@ function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmP
|
79 | 87 | /**
|
80 | 88 | * Removes a selected option from list if already selected.
|
81 | 89 | */
|
82 |
| - const unselectOption = (option: ListItem) => { |
83 |
| - if (!newGroupDraft) { |
84 |
| - return; |
85 |
| - } |
86 |
| - const newSelectedParticipants = (newGroupDraft.participants ?? []).filter((participant) => participant.login !== option.login); |
87 |
| - Report.setGroupDraft({participants: newSelectedParticipants}); |
88 |
| - }; |
| 90 | + const unselectOption = useCallback( |
| 91 | + (option: ListItem) => { |
| 92 | + if (!newGroupDraft) { |
| 93 | + return; |
| 94 | + } |
| 95 | + const newSelectedParticipants = (newGroupDraft.participants ?? []).filter((participant) => participant.login !== option.login); |
| 96 | + Report.setGroupDraft({participants: newSelectedParticipants}); |
| 97 | + }, |
| 98 | + [newGroupDraft], |
| 99 | + ); |
89 | 100 |
|
90 |
| - const createGroup = () => { |
| 101 | + const createGroup = useCallback(() => { |
91 | 102 | if (!newGroupDraft) {
|
92 | 103 | return;
|
93 | 104 | }
|
94 | 105 |
|
95 | 106 | const logins: string[] = (newGroupDraft.participants ?? []).map((participant) => participant.login);
|
96 | 107 | Report.navigateToAndOpenReport(logins, true, newGroupDraft.reportName ?? '', newGroupDraft.avatarUri ?? '', fileRef.current, optimisticReportID.current, true);
|
97 |
| - }; |
98 |
| - |
99 |
| - const navigateBack = () => { |
100 |
| - Navigation.goBack(ROUTES.NEW_CHAT); |
101 |
| - }; |
102 |
| - |
103 |
| - const navigateToEditChatName = () => { |
104 |
| - Navigation.navigate(ROUTES.NEW_CHAT_EDIT_NAME); |
105 |
| - }; |
| 108 | + }, [newGroupDraft]); |
106 | 109 |
|
107 | 110 | const stashedLocalAvatarImage = newGroupDraft?.avatarUri;
|
108 | 111 | return (
|
|
0 commit comments