Skip to content

Commit

Permalink
Merge pull request #38023 from dukenv0307/fix/37152
Browse files Browse the repository at this point in the history
Update welcome note
  • Loading branch information
Gonals authored Apr 15, 2024
2 parents ad38df4 + 32a844c commit 217b67b
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions src/pages/workspace/WorkspaceInviteMessagePage.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -50,19 +52,32 @@ type WorkspaceInviteMessagePageOnyxProps = {
};

type WorkspaceInviteMessagePageProps = WithPolicyAndFullscreenLoadingProps &
WithCurrentUserPersonalDetailsProps &
WorkspaceInviteMessagePageOnyxProps &
StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.INVITE_MESSAGE>;

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();

const [welcomeNote, setWelcomeNote] = useState<string>();

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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -211,15 +226,17 @@ function WorkspaceInviteMessagePage({workspaceInviteMessageDraft, invitedEmailsT
WorkspaceInviteMessagePage.displayName = 'WorkspaceInviteMessagePage';

export default withPolicyAndFullscreenLoading(
withOnyx<WorkspaceInviteMessagePageProps, WorkspaceInviteMessagePageOnyxProps>({
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<WorkspaceInviteMessagePageProps, WorkspaceInviteMessagePageOnyxProps>({
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),
),
);

0 comments on commit 217b67b

Please sign in to comment.