30 lines
805 B
TypeScript

import { PromotionResponse } from '@interfaces';
import { getAllOffersThunk } from './thunk';
import { createReducer } from '@reduxjs/toolkit';
export interface OfferState {
offers: PromotionResponse | null;
isLoading: boolean;
error: string | null;
}
const initialState: OfferState = {
offers: null,
isLoading: false,
error: null,
};
export const offerReducer = createReducer(initialState, builder => {
builder
.addCase(getAllOffersThunk.fulfilled, (state, action) => {
state.offers = action.payload;
state.isLoading = false;
})
.addCase(getAllOffersThunk.pending, state => {
state.isLoading = true;
})
.addCase(getAllOffersThunk.rejected, (state, action) => {
state.isLoading = false;
state.error = action.payload as string;
});
});