32 lines
854 B
TypeScript
32 lines
854 B
TypeScript
import { ToggleStatusResponse } from '@interfaces';
|
|
import { createReducer } from '@reduxjs/toolkit';
|
|
import { toggleStatus } from './thunk';
|
|
|
|
export interface ToggleState {
|
|
loading: boolean;
|
|
error: string | null;
|
|
availabiltyStatus: ToggleStatusResponse | null;
|
|
}
|
|
|
|
export const initialState: ToggleState = {
|
|
loading: false,
|
|
error: null,
|
|
availabiltyStatus: null,
|
|
};
|
|
|
|
export const dashBoardReducer = createReducer(initialState, builder => {
|
|
builder
|
|
.addCase(toggleStatus.pending, state => {
|
|
state.loading = true;
|
|
state.error = null;
|
|
})
|
|
.addCase(toggleStatus.fulfilled, (state, action) => {
|
|
state.loading = false;
|
|
state.availabiltyStatus = action.payload;
|
|
})
|
|
.addCase(toggleStatus.rejected, (state, action) => {
|
|
state.loading = false;
|
|
state.error = action.payload as string;
|
|
});
|
|
});
|