34 lines
925 B
TypeScript

import { createReducer } from '@reduxjs/toolkit';
import { Product } from '@interfaces';
import { getProductDetailsThunk } from './thunk';
export interface ProviderDetailsState {
product: Product | null;
isLoading: boolean;
error: string | null;
}
const initialState: ProviderDetailsState = {
product: null,
isLoading: false,
error: null,
};
const providerDetailsReducer = createReducer(initialState, builder => {
builder
.addCase(getProductDetailsThunk.pending, state => {
state.isLoading = true;
state.error = null;
})
.addCase(getProductDetailsThunk.fulfilled, (state, action) => {
state.product = action.payload;
state.isLoading = false;
})
.addCase(getProductDetailsThunk.rejected, (state, action) => {
state.isLoading = false;
state.error = action.payload || 'Failed to fetch product details';
});
});
export default providerDetailsReducer;