import { Action , ActionType , LoginData } from "../../model/model" ; import createReducer from "../createReducer" ; export interface AuthenticationReducerType { email : string ; password : string ; loading : boolean ; error ? : string ; token : string ; } const defaultState = { email : '' , password : '' , loading : false , error : undefined , token : '' } ; export const authenticationReducer = createReducer < AuthenticationReducerType > ( defaultState , { [ ActionType . LOGIN_USER ] ( state , action ) { return { ... state , loading : true , } ; } , [ ActionType . LOGIN_USER_ERROR ] ( state , action ) { return { ... state , loading : false , error : action . payload , } ; } , [ ActionType . LOGIN_USER_SUCCESS ] ( state , action ) { return { ... state , loading : false , error : null , token : action . payload , } ; } , } ) ;