Skip to content

Commit

Permalink
Merge pull request #54777 from daledah/fix/54604
Browse files Browse the repository at this point in the history
fix: clear invite data after leave on workspace profile page
  • Loading branch information
techievivek authored Jan 8, 2025
2 parents 4d0472f + dac37eb commit 26fe49d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
7 changes: 7 additions & 0 deletions src/libs/actions/Policy/Member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as PhoneNumber from '@libs/PhoneNumber';
import {getDefaultApprover} from '@libs/PolicyUtils';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import * as FormActions from '@userActions/FormActions';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {InvitedEmailsToAccountIDs, PersonalDetailsList, Policy, PolicyEmployee, PolicyOwnershipChangeChecks, Report, ReportAction} from '@src/types/onyx';
Expand Down Expand Up @@ -1002,6 +1003,11 @@ function downloadMembersCSV(policyID: string, onDownloadFailed: () => void) {
fileDownload(ApiUtils.getCommandURL({command: WRITE_COMMANDS.EXPORT_MEMBERS_CSV}), fileName, '', false, formData, CONST.NETWORK.METHOD.POST, onDownloadFailed);
}

function clearInviteDraft(policyID: string) {
setWorkspaceInviteMembersDraft(policyID, {});
FormActions.clearDraftValues(ONYXKEYS.FORMS.WORKSPACE_INVITE_MESSAGE_FORM);
}

export {
removeMembers,
updateWorkspaceMembersRole,
Expand All @@ -1019,6 +1025,7 @@ export {
isApprover,
importPolicyMembers,
downloadMembersCSV,
clearInviteDraft,
};

export type {NewCustomUnit};
16 changes: 5 additions & 11 deletions src/pages/workspace/WorkspaceMembersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import usePrevious from '@hooks/usePrevious';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as FormActions from '@libs/actions/FormActions';
import {turnOffMobileSelectionMode} from '@libs/actions/MobileSelectionMode';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import * as LocalePhoneNumber from '@libs/LocalePhoneNumber';
Expand Down Expand Up @@ -198,18 +197,13 @@ 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();
const inviteUser = useCallback(() => {
Member.clearInviteDraft(route.params.policyID);
Navigation.navigate(ROUTES.WORKSPACE_INVITE.getRoute(route.params.policyID, Navigation.getActiveRouteWithoutParams()));
};
}, [route.params.policyID]);

/**
* Remove selected users from the workspace
Expand Down Expand Up @@ -426,8 +420,8 @@ function WorkspaceMembersPage({personalDetails, route, policy, currentUserPerson
}
const invitedEmails = Object.values(invitedEmailsToAccountIDsDraft).map(String);
selectionListRef.current?.scrollAndHighlightItem?.(invitedEmails);
clearInviteDraft();
}, [invitedEmailsToAccountIDsDraft, isFocused, accountIDs, prevAccountIDs, clearInviteDraft]);
Member.clearInviteDraft(route.params.policyID);
}, [invitedEmailsToAccountIDsDraft, isFocused, accountIDs, prevAccountIDs, route.params.policyID]);

const getHeaderMessage = () => {
if (isOfflineAndNoMemberDataAvailable) {
Expand Down
6 changes: 5 additions & 1 deletion src/pages/workspace/WorkspaceProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import * as PolicyUtils from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import StringUtils from '@libs/StringUtils';
import * as UserUtils from '@libs/UserUtils';
import * as Member from '@userActions/Policy/Member';
import * as Policy from '@userActions/Policy/Policy';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -356,7 +357,10 @@ function WorkspaceProfilePage({policyDraft, policy: policyProp, route}: Workspac
<Button
accessibilityLabel={translate('common.invite')}
text={translate('common.invite')}
onPress={() => Navigation.navigate(ROUTES.WORKSPACE_INVITE.getRoute(route.params.policyID, Navigation.getActiveRouteWithoutParams()))}
onPress={() => {
Member.clearInviteDraft(route.params.policyID);
Navigation.navigate(ROUTES.WORKSPACE_INVITE.getRoute(route.params.policyID, Navigation.getActiveRouteWithoutParams()));
}}
icon={Expensicons.UserPlus}
style={[styles.mr2]}
/>
Expand Down

0 comments on commit 26fe49d

Please sign in to comment.