diff --git a/packages/pl-fe/src/actions/compose.ts b/packages/pl-fe/src/actions/compose.ts index ebfbbe137..8e766170e 100644 --- a/packages/pl-fe/src/actions/compose.ts +++ b/packages/pl-fe/src/actions/compose.ts @@ -343,11 +343,12 @@ const validateSchedule = (state: RootState, composeId: string) => { interface SubmitComposeOpts { history?: History; force?: boolean; + onSuccess?: () => void; } const submitCompose = (composeId: string, opts: SubmitComposeOpts = {}) => async (dispatch: AppDispatch, getState: () => RootState) => { - const { history, force = false } = opts; + const { history, force = false, onSuccess } = opts; if (!isLoggedIn(getState)) return; const state = getState(); @@ -372,7 +373,7 @@ const submitCompose = (composeId: string, opts: SubmitComposeOpts = {}) => useModalsStore.getState().openModal('MISSING_DESCRIPTION', { onContinue: () => { useModalsStore.getState().closeModal('MISSING_DESCRIPTION'); - dispatch(submitCompose(composeId, { history, force: true })); + dispatch(submitCompose(composeId, { history, force: true, onSuccess })); }, }); return; @@ -444,6 +445,7 @@ const submitCompose = (composeId: string, opts: SubmitComposeOpts = {}) => history.push('/conversations'); } handleComposeSubmit(dispatch, getState, composeId, data, status, !!statusId); + onSuccess?.(); }).catch((error) => { dispatch(submitComposeFail(composeId, error)); }); diff --git a/packages/pl-fe/src/features/compose/components/compose-form.tsx b/packages/pl-fe/src/features/compose/components/compose-form.tsx index d2b9bf2e8..6d443f505 100644 --- a/packages/pl-fe/src/features/compose/components/compose-form.tsx +++ b/packages/pl-fe/src/features/compose/components/compose-form.tsx @@ -142,9 +142,9 @@ const ComposeForm = ({ id, shouldCondense, autoFocus, clickab if (!canSubmit) return; e?.preventDefault(); - dispatch(submitCompose(id, { history })).then(() => { + dispatch(submitCompose(id, { history, onSuccess: () => { editorRef.current?.dispatchCommand(CLEAR_EDITOR_COMMAND, undefined); - }).catch(() => {}); + } })); }; const onSuggestionsClearRequested = () => {