Skip to content

Commit

Permalink
clears the draft when opening the invite page
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardoj committed Nov 21, 2024
1 parent 950c5f8 commit e99ede5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
16 changes: 0 additions & 16 deletions src/pages/workspace/WorkspaceInvitePage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {useIsFocused, 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';
Expand All @@ -16,7 +15,6 @@ import useDebouncedState from '@hooks/useDebouncedState';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
import * as FormActions from '@libs/actions/FormActions';
import * as ReportActions from '@libs/actions/Report';
import {READ_COMMANDS} from '@libs/API/types';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
Expand Down Expand Up @@ -49,8 +47,6 @@ type WorkspaceInvitePageProps = WithPolicyAndFullscreenLoadingProps & WithNaviga
function WorkspaceInvitePage({route, policy}: WorkspaceInvitePageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const navigation = useNavigation();
const isFocused = useIsFocused();
const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState('');
const [selectedOptions, setSelectedOptions] = useState<MemberForList[]>([]);
const [personalDetails, setPersonalDetails] = useState<OptionData[]>([]);
Expand All @@ -69,18 +65,6 @@ function WorkspaceInvitePage({route, policy}: WorkspaceInvitePageProps) {
shouldInitialize: didScreenTransitionEnd,
});

useEffect(() => {
if (!isFocused) {
return;
}
const unsubscribe = navigation.addListener('beforeRemove', () => {
Member.setWorkspaceInviteMembersDraft(route.params.policyID, {});
FormActions.clearDraftValues(ONYXKEYS.FORMS.WORKSPACE_INVITE_MESSAGE_FORM);
});

return unsubscribe;
}, [isFocused, navigation, route.params.policyID]);

useEffect(() => {
Policy.clearErrors(route.params.policyID);
openWorkspaceInvitePage();
Expand Down
11 changes: 8 additions & 3 deletions src/pages/workspace/WorkspaceMembersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,16 @@ function WorkspaceMembersPage({personalDetails, route, policy, currentUserPerson
getWorkspaceMembers();
}, [isOffline, prevIsOffline, getWorkspaceMembers]);

const clearInviteDraft = useCallback(() => {
Member.setWorkspaceInviteMembersDraft(route.params.policyID, {});
FormActions.clearDraftValues(ONYXKEYS.FORMS.WORKSPACE_INVITE_MESSAGE_FORM);
}, [route.params.policyID]);

/**
* Open the modal to invite a user
*/
const inviteUser = () => {
clearInviteDraft();
Navigation.navigate(ROUTES.WORKSPACE_INVITE.getRoute(route.params.policyID));
};

Expand Down Expand Up @@ -417,9 +423,8 @@ function WorkspaceMembersPage({personalDetails, route, policy, currentUserPerson
}
const invitedEmails = Object.values(invitedEmailsToAccountIDsDraft).map(String);
selectionListRef.current?.scrollAndHighlightItem?.(invitedEmails);
Member.setWorkspaceInviteMembersDraft(route.params.policyID, {});
FormActions.clearDraftValues(ONYXKEYS.FORMS.WORKSPACE_INVITE_MESSAGE_FORM);
}, [invitedEmailsToAccountIDsDraft, route.params.policyID, isFocused, accountIDs, prevAccountIDs]);
clearInviteDraft();
}, [invitedEmailsToAccountIDsDraft, isFocused, accountIDs, prevAccountIDs, clearInviteDraft]);

const getHeaderMessage = () => {
if (isOfflineAndNoMemberDataAvailable) {
Expand Down

0 comments on commit e99ede5

Please sign in to comment.