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