diff --git a/src/actions/compose.ts b/src/actions/compose.ts index 44aa179b3..e0128af1e 100644 --- a/src/actions/compose.ts +++ b/src/actions/compose.ts @@ -299,8 +299,15 @@ const validateSchedule = (state: RootState, composeId: string) => { return schedule.getTime() > fiveMinutesFromNow.getTime(); }; -const submitCompose = (composeId: string, routerHistory?: History, force = false) => +interface SubmitComposeOpts { + history?: History; + force?: boolean; +} + +const submitCompose = (composeId: string, opts: SubmitComposeOpts = {}) => (dispatch: AppDispatch, getState: () => RootState) => { + const { history, force = false } = opts; + if (!isLoggedIn(getState)) return; const state = getState(); @@ -324,7 +331,7 @@ const submitCompose = (composeId: string, routerHistory?: History, force = false dispatch(openModal('MISSING_DESCRIPTION', { onContinue: () => { dispatch(closeModal('MISSING_DESCRIPTION')); - dispatch(submitCompose(composeId, routerHistory, true)); + dispatch(submitCompose(composeId, { history, force: true })); }, })); return; @@ -361,8 +368,8 @@ const submitCompose = (composeId: string, routerHistory?: History, force = false } dispatch(createStatus(params, idempotencyKey, statusId)).then(function(data) { - if (!statusId && data.visibility === 'direct' && getState().conversations.mounted <= 0 && routerHistory) { - routerHistory.push('/messages'); + if (!statusId && data.visibility === 'direct' && getState().conversations.mounted <= 0 && history) { + history.push('/messages'); } handleComposeSubmit(dispatch, getState, composeId, data, status, !!statusId); }).catch(function(error) { diff --git a/src/features/compose/components/compose-form.tsx b/src/features/compose/components/compose-form.tsx index 5ffdb734c..456dab69a 100644 --- a/src/features/compose/components/compose-form.tsx +++ b/src/features/compose/components/compose-form.tsx @@ -152,7 +152,7 @@ const ComposeForm = ({ id, shouldCondense, autoFocus, clickab return; } - dispatch(submitCompose(id, history)); + dispatch(submitCompose(id, { history })); editorRef.current?.dispatchCommand(CLEAR_EDITOR_COMMAND, undefined); };