import { ReduxActionTypes } from "constants/ReduxActionConstants"; import { SubmissionError } from "redux-form"; export type LoginFormValues = { username?: string; password?: string; remember?: string; }; export type SignupFormValues = { email?: string; password?: string; name?: string; }; export type ResetPasswordFormValues = { password?: string; token?: string; email?: string; }; export type ForgotPasswordFormValues = { email?: string; }; export const signupFormSubmitHandler = ( values: SignupFormValues, dispatch: any, ): Promise => { const { email, password } = values; return new Promise((resolve, reject) => { dispatch({ type: ReduxActionTypes.CREATE_USER_INIT, payload: { resolve, reject, email, password, }, }); }).catch(error => { throw new SubmissionError(error); }); }; export const resetPasswordSubmitHandler = ( values: ResetPasswordFormValues, dispatch: any, ): Promise => { const { token, email, password } = values; return new Promise((resolve, reject) => { dispatch({ type: ReduxActionTypes.RESET_USER_PASSWORD_INIT, payload: { resolve, reject, token, email, password, }, }); }).catch(error => { throw new SubmissionError(error); }); }; export const forgotPasswordSubmitHandler = ( values: ForgotPasswordFormValues, dispatch: any, ): Promise => { const { email } = values; return new Promise((resolve, reject) => { dispatch({ type: ReduxActionTypes.FORGOT_PASSWORD_INIT, payload: { resolve, reject, email, }, }); }).catch(error => { error.email = ""; throw new SubmissionError(error); }); };