import { Dispatch } from "redux" ; import { signIn as signInToApi , signOut as signOutFromApi } from "../../api/authenticationApi" ; import IStoreState from "../../store/IStoreState" ; import keys from "../ActionTypeKeys" ; import { ISignInFailAction , ISignInInProgressAction , ISignInSuccessAction } from "./signin" ; import { ISignOutFailAction , ISignOutInProgressAction , ISignOutSuccessAction } from "./signout" ; export function signIn ( ) { return async ( dispatch ) => { dispatch ( signInInProgress ( ) ) ; try { await signInToApi ( ) ; dispatch ( signInSuccess ( ) ) ; } catch ( err ) { dispatch ( signInFail ( err ) ) ; } } ; } export function signOut ( ) { return async ( dispatch ) => { dispatch ( signOutInProgress ( ) ) ; try { await signOutFromApi ( ) ; dispatch ( signOutSuccess ( ) ) ; } catch ( err ) { dispatch ( signOutFail ( err ) ) ; } } ; } function signInInProgress ( ) { return { type : keys . SIGNIN_INPROGRESS } ; } function signInSuccess ( ) { return { type : keys . SIGNIN_SUCCESS } ; } function signInFail ( error ) { return { payload : { error } , type : keys . SIGNIN_FAIL } ; } function signOutInProgress ( ) { return { type : keys . SIGNOUT_INPROGRESS } ; } function signOutSuccess ( ) { return { type : keys . SIGNOUT_SUCCESS } ; } function signOutFail ( error ) { return { payload : { error } , type : keys . SIGNOUT_FAIL } ; }