45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { DeliveryDetailsResponse, OrderHistoryResponse } from '@interfaces';
|
|
import { createReducer } from '@reduxjs/toolkit';
|
|
import { getAllActiveDeliveries, getCompletedDeliveries } from './thunk';
|
|
|
|
export interface ActiveDeliveriesState {
|
|
activeDeliveries: DeliveryDetailsResponse | null;
|
|
loading: boolean;
|
|
error: string | null;
|
|
completedDeliveries: OrderHistoryResponse | null;
|
|
}
|
|
|
|
const initialState: ActiveDeliveriesState = {
|
|
activeDeliveries: null,
|
|
loading: false,
|
|
error: null,
|
|
completedDeliveries: null,
|
|
};
|
|
|
|
export const activeDeliveriesReducer = createReducer(initialState, builder => {
|
|
builder
|
|
.addCase(getAllActiveDeliveries.pending, state => {
|
|
state.loading = true;
|
|
})
|
|
.addCase(getAllActiveDeliveries.fulfilled, (state, action) => {
|
|
state.loading = false;
|
|
state.activeDeliveries = action.payload;
|
|
// console.log(action.payload);
|
|
})
|
|
.addCase(getAllActiveDeliveries.rejected, (state, action) => {
|
|
state.loading = false;
|
|
state.error = action.payload as string;
|
|
})
|
|
.addCase(getCompletedDeliveries.pending, state => {
|
|
state.loading = true;
|
|
})
|
|
.addCase(getCompletedDeliveries.fulfilled, (state, action) => {
|
|
state.loading = false;
|
|
state.completedDeliveries = action.payload;
|
|
})
|
|
.addCase(getCompletedDeliveries.rejected, (state, action) => {
|
|
state.loading = false;
|
|
state.error = action.payload as string;
|
|
});
|
|
});
|