import { ContactAction , ContactActionTypes , ContactFormData , } from '../../types/redux/contact-reducer-types' ; import { Dispatch } from 'redux' ; import { sendEmailWith } from '../../frontend-rest-client/rest/contact' ; import { getErrorMessage } from '../../utils/getErrorMessage' ; Action function returns { function } export const sendEmailViaSendgrid = ( contactFormData ) => { return async ( dispatch ) : Promise < void > => { dispatch ( { type : ContactActionTypes . SEND_EMAIL } ) ; try { const { data } = await sendEmailWith ( contactFormData ) ; dispatch ( { type : ContactActionTypes . EMAIL_WAS_SENT , payload : data . success , } ) ; } catch ( error ) { dispatch ( { type : ContactActionTypes . EMAIL_SEND_ERROR , payload : getErrorMessage ( error ) , } ) ; } } ; } ; CLEAR CLEAR export const clearEmailState = ( ) => { return async ( dispatch ) : Promise < void > => { dispatch ( { type : ContactActionTypes . CLEAR_EMAIL_STATE } ) ; } ; } ;