Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
competitionsReducer.ts 1.10 KiB
import { AnyAction } from 'redux'
import Types from '../actions/types'
import { Competition } from '../interfaces/Competition'
import { CompetitionFilterParams } from './../interfaces/CompetitionFilterParams'

interface CompetitionState {
  competitions: Competition[]
  total: number
  count: number
  filterParams: CompetitionFilterParams
}

const initialState: CompetitionState = {
  competitions: [],
  total: 0,
  count: 0,
  filterParams: { pageSize: 10, page: 0 },
}

export default function (state = initialState, action: AnyAction) {
  switch (action.type) {
    case Types.SET_COMPETITIONS:
      return {
        ...state,
        competitions: action.payload as Competition[],
      }
    case Types.SET_COMPETITIONS_FILTER_PARAMS:
      return {
        ...state,
        filterParams: action.payload as CompetitionFilterParams,
      }
    case Types.SET_COMPETITIONS_TOTAL:
      return {
        ...state,
        total: action.payload as number,
      }
    case Types.SET_COMPETITIONS_COUNT:
      return {
        ...state,
        count: action.payload as number,
      }
    default:
      return state
  }
}