45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import {
|
|
DeliveryPartnerLocationResponse,
|
|
ToggleStatusResponse,
|
|
} from '@interfaces';
|
|
import { createReducer } from '@reduxjs/toolkit';
|
|
import { toggleStatus, updateDeliveryPartnerLocation } from './thunk';
|
|
|
|
export interface ToggleState {
|
|
loading: boolean;
|
|
error: string | null;
|
|
availabiltyStatus: ToggleStatusResponse | null;
|
|
deliveryPartnerLocation: DeliveryPartnerLocationResponse | null;
|
|
deliveryLocError: string | null;
|
|
}
|
|
|
|
export const initialState: ToggleState = {
|
|
loading: false,
|
|
error: null,
|
|
availabiltyStatus: null,
|
|
deliveryPartnerLocation: null,
|
|
deliveryLocError: 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;
|
|
})
|
|
.addCase(updateDeliveryPartnerLocation.fulfilled, (state, action) => {
|
|
state.deliveryPartnerLocation = action.payload;
|
|
})
|
|
.addCase(updateDeliveryPartnerLocation.rejected, (state, action) => {
|
|
state.deliveryLocError = action.payload as string;
|
|
});
|
|
});
|