From c06b770f02a888cf6a956d8bf6af9920665a119b Mon Sep 17 00:00:00 2001 From: truph01 Date: Tue, 22 Oct 2024 15:18:54 +0700 Subject: [PATCH 1/3] fix: Members are unselected when refresh Add message page and go back --- src/pages/workspace/WorkspaceInvitePage.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/pages/workspace/WorkspaceInvitePage.tsx b/src/pages/workspace/WorkspaceInvitePage.tsx index ad48d15aa9df..23a90b4afd3e 100644 --- a/src/pages/workspace/WorkspaceInvitePage.tsx +++ b/src/pages/workspace/WorkspaceInvitePage.tsx @@ -1,3 +1,4 @@ +import {useNavigation} from '@react-navigation/native'; import type {StackScreenProps} from '@react-navigation/stack'; import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; import type {SectionListData} from 'react-native'; @@ -59,6 +60,7 @@ type WorkspaceInvitePageProps = WithPolicyAndFullscreenLoadingProps & function WorkspaceInvitePage({route, betas, invitedEmailsToAccountIDsDraft, policy}: WorkspaceInvitePageProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); + const navigation = useNavigation(); const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState(''); const [selectedOptions, setSelectedOptions] = useState([]); const [personalDetails, setPersonalDetails] = useState([]); @@ -76,11 +78,12 @@ function WorkspaceInvitePage({route, betas, invitedEmailsToAccountIDsDraft, poli }); useEffect(() => { - return () => { + const unsubscribe = navigation.addListener('beforeRemove', () => { Member.setWorkspaceInviteMembersDraft(route.params.policyID, {}); - }; - // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps - }, [route.params.policyID]); + }); + + return unsubscribe; + }, [navigation, route.params.policyID]); useEffect(() => { Policy.clearErrors(route.params.policyID); From fbc8be1a9166f752667f0d448c7a2e47e605f0ee Mon Sep 17 00:00:00 2001 From: truph01 Date: Thu, 7 Nov 2024 10:33:59 +0700 Subject: [PATCH 2/3] fix: remove withOnyx --- src/pages/workspace/WorkspaceInvitePage.tsx | 32 ++++----------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/src/pages/workspace/WorkspaceInvitePage.tsx b/src/pages/workspace/WorkspaceInvitePage.tsx index 23a90b4afd3e..ce3dc37d52b9 100644 --- a/src/pages/workspace/WorkspaceInvitePage.tsx +++ b/src/pages/workspace/WorkspaceInvitePage.tsx @@ -2,7 +2,7 @@ import {useNavigation} from '@react-navigation/native'; import type {StackScreenProps} from '@react-navigation/stack'; import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; import type {SectionListData} from 'react-native'; -import {useOnyx, withOnyx} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import type {OnyxEntry} from 'react-native-onyx'; import FormAlertWithSubmitButton from '@components/FormAlertWithSubmitButton'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; @@ -44,20 +44,9 @@ import type {WithPolicyAndFullscreenLoadingProps} from './withPolicyAndFullscree type MembersSection = SectionListData>; -type WorkspaceInvitePageOnyxProps = { - /** Beta features list */ - betas: OnyxEntry; +type WorkspaceInvitePageProps = WithPolicyAndFullscreenLoadingProps & WithNavigationTransitionEndProps & StackScreenProps; - /** An object containing the accountID for every invited user email */ - invitedEmailsToAccountIDsDraft: OnyxEntry; -}; - -type WorkspaceInvitePageProps = WithPolicyAndFullscreenLoadingProps & - WithNavigationTransitionEndProps & - WorkspaceInvitePageOnyxProps & - StackScreenProps; - -function WorkspaceInvitePage({route, betas, invitedEmailsToAccountIDsDraft, policy}: WorkspaceInvitePageProps) { +function WorkspaceInvitePage({route, policy}: WorkspaceInvitePageProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); const navigation = useNavigation(); @@ -68,6 +57,8 @@ function WorkspaceInvitePage({route, betas, invitedEmailsToAccountIDsDraft, poli const [didScreenTransitionEnd, setDidScreenTransitionEnd] = useState(false); const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false}); const firstRenderRef = useRef(true); + const [betas] = useOnyx(ONYXKEYS.BETAS); + const [invitedEmailsToAccountIDsDraft] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MEMBERS_DRAFT}${route.params.policyID.toString()}`); const openWorkspaceInvitePage = () => { const policyMemberEmailsToAccountIDs = PolicyUtils.getMemberAccountIDsForWorkspace(policy?.employeeList); @@ -357,15 +348,4 @@ function WorkspaceInvitePage({route, betas, invitedEmailsToAccountIDsDraft, poli WorkspaceInvitePage.displayName = 'WorkspaceInvitePage'; -export default withNavigationTransitionEnd( - withPolicyAndFullscreenLoading( - withOnyx({ - betas: { - key: ONYXKEYS.BETAS, - }, - invitedEmailsToAccountIDsDraft: { - key: ({route}) => `${ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MEMBERS_DRAFT}${route.params.policyID.toString()}`, - }, - })(WorkspaceInvitePage), - ), -); +export default withNavigationTransitionEnd(withPolicyAndFullscreenLoading(WorkspaceInvitePage)); From 7960b7dec48353d95f2155938da69d28ee0c4dbb Mon Sep 17 00:00:00 2001 From: truph01 Date: Thu, 7 Nov 2024 10:35:47 +0700 Subject: [PATCH 3/3] fix: lint --- src/pages/workspace/WorkspaceInvitePage.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/workspace/WorkspaceInvitePage.tsx b/src/pages/workspace/WorkspaceInvitePage.tsx index ce3dc37d52b9..3e63ae7cbe79 100644 --- a/src/pages/workspace/WorkspaceInvitePage.tsx +++ b/src/pages/workspace/WorkspaceInvitePage.tsx @@ -3,7 +3,6 @@ import type {StackScreenProps} from '@react-navigation/stack'; import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; import type {SectionListData} from 'react-native'; import {useOnyx} from 'react-native-onyx'; -import type {OnyxEntry} from 'react-native-onyx'; import FormAlertWithSubmitButton from '@components/FormAlertWithSubmitButton'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import {useOptionsList} from '@components/OptionListContextProvider'; @@ -35,7 +34,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; -import type {Beta, InvitedEmailsToAccountIDs} from '@src/types/onyx'; +import type {InvitedEmailsToAccountIDs} from '@src/types/onyx'; import type {Errors} from '@src/types/onyx/OnyxCommon'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import AccessOrNotFoundWrapper from './AccessOrNotFoundWrapper';