You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
985 B
38 lines
985 B
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
|
import { fetchStoke } from './stock';
|
|
import { Stoke, StockSliceState, Status } from './types';
|
|
|
|
const initialState: StockSliceState = {
|
|
items: [],
|
|
status: Status.LOADING, // loading | success | error
|
|
};
|
|
|
|
const pizzaSlice = createSlice({
|
|
name: 'pizza',
|
|
initialState,
|
|
reducers: {
|
|
setItems(state, action: PayloadAction<Stoke[]>) {
|
|
state.items = action.payload;
|
|
},
|
|
},
|
|
extraReducers: (builder) => {
|
|
builder.addCase(fetchStoke.pending, (state, action) => {
|
|
state.status = Status.LOADING;
|
|
state.items = [];
|
|
});
|
|
|
|
builder.addCase(fetchStoke.fulfilled, (state, action) => {
|
|
state.items = action.payload;
|
|
state.status = Status.SUCCESS;
|
|
});
|
|
|
|
builder.addCase(fetchStoke.rejected, (state, action) => {
|
|
state.status = Status.ERROR;
|
|
state.items = [];
|
|
});
|
|
},
|
|
});
|
|
|
|
export const { setItems } = pizzaSlice.actions;
|
|
|
|
export default pizzaSlice.reducer;
|
|
|