Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Form Provider Refactor] WorkspaceInviteMessagePage #32139

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix input value and space placement
  • Loading branch information
cdOut committed Dec 19, 2023
commit 14d38208d4e28e30798f7b6990e7c3fe93c56a96
31 changes: 17 additions & 14 deletions src/pages/workspace/WorkspaceInviteMessagePage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {isEmpty} from 'lodash';
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import React, {useEffect} from 'react';
import React, {useEffect, useState} from 'react';
import {Keyboard, View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
Expand Down Expand Up @@ -75,30 +75,32 @@ function WorkspaceInviteMessagePage(props) {
const styles = useThemeStyles();
const {translate} = useLocalize();

const [welcomeNote, setWelcomeNote] = useState();

const {inputCallbackRef} = useAutoFocusInput();

const getDefaultWelcomeNote = () =>
props.workspaceInviteMessageDraft ||
translate('workspace.inviteMessage.welcomeNote', {
workspaceName: props.policy.name,
});

useEffect(() => {
if (!_.isEmpty(props.invitedEmailsToAccountIDsDraft)) {
setWelcomeNote(getDefaultWelcomeNote());
return;
}
Navigation.goBack(ROUTES.WORKSPACE_INVITE.getRoute(props.route.params.policyID), true);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const saveDraft = (newDraft) => {
const debouncedSaveDraft = _.debounce((newDraft) => {
Policy.setWorkspaceInviteMessageDraft(props.route.params.policyID, newDraft);
};

const getDefaultWelcomeNote = () =>
translate('workspace.inviteMessage.welcomeNote', {
workspaceName: props.policy.name,
});

const welcomeMessage = props.workspaceInviteMessageDraft || getDefaultWelcomeNote();
});

const sendInvitation = () => {
Keyboard.dismiss();
Policy.addMembersToWorkspace(props.invitedEmailsToAccountIDsDraft, welcomeMessage, props.route.params.policyID);
Policy.addMembersToWorkspace(props.invitedEmailsToAccountIDsDraft, welcomeNote, props.route.params.policyID);
Policy.setWorkspaceInviteMembersDraft(props.route.params.policyID, {});
SearchInputManager.searchInput = '';
// Pop the invite message page before navigating to the members page.
Expand Down Expand Up @@ -187,11 +189,12 @@ function WorkspaceInviteMessagePage(props) {
autoCompleteType="off"
autoCorrect={false}
autoGrowHeight
inputStyle={[styles.verticalAlignTop]}
containerStyles={[styles.autoGrowHeightMultilineInput]}
value={welcomeMessage}
defaultValue={getDefaultWelcomeNote()}
value={welcomeNote}
onChangeText={(text) => {
saveDraft(text);
setWelcomeNote(text);
debouncedSaveDraft(text);
}}
ref={(el) => {
if (!el) {
Expand Down
Loading