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

Fix previous invite message showing on every type #50618

Merged
Changes from all commits
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
17 changes: 7 additions & 10 deletions src/pages/workspace/WorkspaceInviteMessagePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import INPUT_IDS from '@src/types/form/WorkspaceInviteMessageForm';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
import AccessOrNotFoundWrapper from './AccessOrNotFoundWrapper';
import withPolicyAndFullscreenLoading from './withPolicyAndFullscreenLoading';
import type {WithPolicyAndFullscreenLoadingProps} from './withPolicyAndFullscreenLoading';
Expand All @@ -52,8 +53,9 @@ function WorkspaceInviteMessagePage({policy, route, currentUserPersonalDetails}:
const {inputCallbackRef, inputRef} = useAutoFocusInput();

const [invitedEmailsToAccountIDsDraft] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MEMBERS_DRAFT}${route.params.policyID.toString()}`);
const [workspaceInviteMessageDraft] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MESSAGE_DRAFT}${route.params.policyID.toString()}`);
const [workspaceInviteMessageDraft, workspaceInviteMessageDraftResult] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MESSAGE_DRAFT}${route.params.policyID.toString()}`);
const [allPersonalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const isWorkspaceInviteMessageDraftLoading = isLoadingOnyxValue(workspaceInviteMessageDraftResult);

const welcomeNoteSubject = useMemo(
() => `# ${currentUserPersonalDetails?.displayName ?? ''} invited you to ${policy?.name ?? 'a workspace'}`,
Expand All @@ -75,6 +77,9 @@ function WorkspaceInviteMessagePage({policy, route, currentUserPersonalDetails}:
}, [workspaceInviteMessageDraft, policy, translate]);

useEffect(() => {
if (isWorkspaceInviteMessageDraftLoading) {
return;
}
if (!isEmptyObject(invitedEmailsToAccountIDsDraft)) {
setWelcomeNote(getDefaultWelcomeNote());
return;
Expand All @@ -84,14 +89,7 @@ function WorkspaceInviteMessagePage({policy, route, currentUserPersonalDetails}:
}
Navigation.goBack(ROUTES.WORKSPACE_INVITE.getRoute(route.params.policyID), true);
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, []);

useEffect(() => {
if (isEmptyObject(invitedEmailsToAccountIDsDraft) || !welcomeNote) {
return;
}
setWelcomeNote(getDefaultWelcomeNote());
}, [getDefaultWelcomeNote, invitedEmailsToAccountIDsDraft, welcomeNote]);
}, [isWorkspaceInviteMessageDraftLoading]);

const debouncedSaveDraft = lodashDebounce((newDraft: string | null) => {
Policy.setWorkspaceInviteMessageDraft(route.params.policyID, newDraft);
Expand Down Expand Up @@ -189,7 +187,6 @@ function WorkspaceInviteMessagePage({policy, route, currentUserPersonalDetails}:
autoCorrect={false}
autoGrowHeight
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
defaultValue={getDefaultWelcomeNote()}
value={welcomeNote}
onChangeText={(text: string) => {
setWelcomeNote(text);
Expand Down
Loading