Skip to content

Commit

Permalink
Merge pull request #52524 from Krishna2323/krishna2323/issue/51096
Browse files Browse the repository at this point in the history
Update: Default / Custom Workspace Invite Behavior
  • Loading branch information
jasperhuangg authored Nov 19, 2024
2 parents 763215e + b9ba307 commit 6e8590d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/pages/workspace/WorkspaceInviteMessagePage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {StackScreenProps} from '@react-navigation/stack';
import lodashDebounce from 'lodash/debounce';
import React, {useCallback, useEffect, useMemo, useState} from 'react';
import {Keyboard, View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
Expand All @@ -20,6 +19,7 @@ import useAutoFocusInput from '@hooks/useAutoFocusInput';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import useViewportOffsetTop from '@hooks/useViewportOffsetTop';
import * as FormActions from '@libs/actions/FormActions';
import Navigation from '@libs/Navigation/Navigation';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import Parser from '@libs/Parser';
Expand Down Expand Up @@ -48,6 +48,7 @@ type WorkspaceInviteMessagePageProps = WithPolicyAndFullscreenLoadingProps &
function WorkspaceInviteMessagePage({policy, route, currentUserPersonalDetails}: WorkspaceInviteMessagePageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const [formData] = useOnyx(ONYXKEYS.FORMS.WORKSPACE_INVITE_MESSAGE_FORM_DRAFT);

const viewportOffsetTop = useViewportOffsetTop();
const [welcomeNote, setWelcomeNote] = useState<string>();
Expand All @@ -66,17 +67,19 @@ function WorkspaceInviteMessagePage({policy, route, currentUserPersonalDetails}:

const getDefaultWelcomeNote = useCallback(() => {
return (
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
formData?.[INPUT_IDS.WELCOME_MESSAGE] ??
// workspaceInviteMessageDraft can be an empty string
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
workspaceInviteMessageDraft ||
workspaceInviteMessageDraft ??
// policy?.description can be an empty string
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Parser.htmlToMarkdown(policy?.description ?? '') ||
translate('workspace.common.welcomeNote', {
workspaceName: policy?.name ?? '',
})
(Parser.htmlToMarkdown(policy?.description ?? '') ||
translate('workspace.common.welcomeNote', {
workspaceName: policy?.name ?? '',
}))
);
}, [workspaceInviteMessageDraft, policy, translate]);
}, [workspaceInviteMessageDraft, policy, translate, formData]);

useEffect(() => {
if (isOnyxLoading) {
Expand All @@ -93,16 +96,13 @@ function WorkspaceInviteMessagePage({policy, route, currentUserPersonalDetails}:
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [isOnyxLoading]);

const debouncedSaveDraft = lodashDebounce((newDraft: string | null) => {
Policy.setWorkspaceInviteMessageDraft(route.params.policyID, newDraft);
});

const sendInvitation = () => {
Keyboard.dismiss();
const policyMemberAccountIDs = Object.values(PolicyUtils.getMemberAccountIDsForWorkspace(policy?.employeeList, false, false));
// Please see https://github.com/Expensify/App/blob/main/README.md#Security for more details
Member.addMembersToWorkspace(invitedEmailsToAccountIDsDraft ?? {}, `${welcomeNoteSubject}\n\n${welcomeNote}`, route.params.policyID, policyMemberAccountIDs);
debouncedSaveDraft(null);
Policy.setWorkspaceInviteMessageDraft(route.params.policyID, welcomeNote ?? null);
FormActions.clearDraftValues(ONYXKEYS.FORMS.WORKSPACE_INVITE_MESSAGE_FORM);
Navigation.dismissModal();
};

Expand Down Expand Up @@ -194,7 +194,6 @@ function WorkspaceInviteMessagePage({policy, route, currentUserPersonalDetails}:
value={welcomeNote}
onChangeText={(text: string) => {
setWelcomeNote(text);
debouncedSaveDraft(text);
}}
ref={(element: AnimatedTextInputRef) => {
if (!element) {
Expand All @@ -205,6 +204,7 @@ function WorkspaceInviteMessagePage({policy, route, currentUserPersonalDetails}:
}
inputCallbackRef(element);
}}
shouldSaveDraft
/>
</View>
</FormProvider>
Expand Down
2 changes: 2 additions & 0 deletions src/pages/workspace/WorkspaceInvitePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ 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 @@ -70,6 +71,7 @@ function WorkspaceInvitePage({route, policy}: WorkspaceInvitePageProps) {
useEffect(() => {
const unsubscribe = navigation.addListener('beforeRemove', () => {
Member.setWorkspaceInviteMembersDraft(route.params.policyID, {});
FormActions.clearDraftValues(ONYXKEYS.FORMS.WORKSPACE_INVITE_MESSAGE_FORM);
});

return unsubscribe;
Expand Down
2 changes: 2 additions & 0 deletions src/pages/workspace/WorkspaceMembersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ 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 Log from '@libs/Log';
Expand Down Expand Up @@ -417,6 +418,7 @@ function WorkspaceMembersPage({personalDetails, route, policy, currentUserPerson
const invitedEmails = Object.values(invitedEmailsToAccountIDsDraft).map(String);
selectionListRef.current?.scrollAndHighlightItem?.(invitedEmails, 1500);
Member.setWorkspaceInviteMembersDraft(route.params.policyID, {});
FormActions.clearDraftValues(ONYXKEYS.FORMS.WORKSPACE_INVITE_MESSAGE_FORM);
}, [invitedEmailsToAccountIDsDraft, route.params.policyID, isFocused, accountIDs, prevAccountIDs]);

const getHeaderMessage = () => {
Expand Down

0 comments on commit 6e8590d

Please sign in to comment.