diff --git a/src/pages/workspace/WorkspaceInviteMessagePage.tsx b/src/pages/workspace/WorkspaceInviteMessagePage.tsx index e18b315b2dd0..dd2ab151b658 100644 --- a/src/pages/workspace/WorkspaceInviteMessagePage.tsx +++ b/src/pages/workspace/WorkspaceInviteMessagePage.tsx @@ -1,7 +1,7 @@ import type {StackScreenProps} from '@react-navigation/stack'; import ExpensiMark from 'expensify-common/lib/ExpensiMark'; import lodashDebounce from 'lodash/debounce'; -import React, {useEffect, useState} from 'react'; +import React, {useEffect, useMemo, useState} from 'react'; import {Keyboard, View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import type {OnyxEntry} from 'react-native-onyx'; @@ -17,6 +17,8 @@ import type {AnimatedTextInputRef} from '@components/RNTextInput'; import ScreenWrapper from '@components/ScreenWrapper'; import Text from '@components/Text'; import TextInput from '@components/TextInput'; +import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails'; +import withCurrentUserPersonalDetails from '@components/withCurrentUserPersonalDetails'; import useAutoFocusInput from '@hooks/useAutoFocusInput'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; @@ -50,12 +52,20 @@ type WorkspaceInviteMessagePageOnyxProps = { }; type WorkspaceInviteMessagePageProps = WithPolicyAndFullscreenLoadingProps & + WithCurrentUserPersonalDetailsProps & WorkspaceInviteMessagePageOnyxProps & StackScreenProps; const parser = new ExpensiMark(); -function WorkspaceInviteMessagePage({workspaceInviteMessageDraft, invitedEmailsToAccountIDsDraft, policy, route, allPersonalDetails}: WorkspaceInviteMessagePageProps) { +function WorkspaceInviteMessagePage({ + workspaceInviteMessageDraft, + invitedEmailsToAccountIDsDraft, + policy, + route, + allPersonalDetails, + currentUserPersonalDetails, +}: WorkspaceInviteMessagePageProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); @@ -63,6 +73,11 @@ function WorkspaceInviteMessagePage({workspaceInviteMessageDraft, invitedEmailsT const {inputCallbackRef} = useAutoFocusInput(); + const welcomeNoteSubject = useMemo( + () => `# ${currentUserPersonalDetails?.displayName ?? ''} invited you to ${policy?.name ?? 'a workspace'}`, + [policy?.name, currentUserPersonalDetails?.displayName], + ); + const getDefaultWelcomeNote = () => // workspaceInviteMessageDraft can be an empty string // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing @@ -95,7 +110,7 @@ function WorkspaceInviteMessagePage({workspaceInviteMessageDraft, invitedEmailsT const sendInvitation = () => { Keyboard.dismiss(); // Please see https://github.com/Expensify/App/blob/main/README.md#Security for more details - Policy.addMembersToWorkspace(invitedEmailsToAccountIDsDraft ?? {}, welcomeNote ?? '', route.params.policyID); + Policy.addMembersToWorkspace(invitedEmailsToAccountIDsDraft ?? {}, `${welcomeNoteSubject}\n\n${welcomeNote}`, route.params.policyID); debouncedSaveDraft(null); SearchInputManager.searchInput = ''; // Pop the invite message page before navigating to the members page. @@ -211,15 +226,17 @@ function WorkspaceInviteMessagePage({workspaceInviteMessageDraft, invitedEmailsT WorkspaceInviteMessagePage.displayName = 'WorkspaceInviteMessagePage'; export default withPolicyAndFullscreenLoading( - withOnyx({ - allPersonalDetails: { - key: ONYXKEYS.PERSONAL_DETAILS_LIST, - }, - invitedEmailsToAccountIDsDraft: { - key: ({route}) => `${ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MEMBERS_DRAFT}${route.params.policyID.toString()}`, - }, - workspaceInviteMessageDraft: { - key: ({route}) => `${ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MESSAGE_DRAFT}${route.params.policyID.toString()}`, - }, - })(WorkspaceInviteMessagePage), + withCurrentUserPersonalDetails( + withOnyx({ + allPersonalDetails: { + key: ONYXKEYS.PERSONAL_DETAILS_LIST, + }, + invitedEmailsToAccountIDsDraft: { + key: ({route}) => `${ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MEMBERS_DRAFT}${route.params.policyID.toString()}`, + }, + workspaceInviteMessageDraft: { + key: ({route}) => `${ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MESSAGE_DRAFT}${route.params.policyID.toString()}`, + }, + })(WorkspaceInviteMessagePage), + ), );