import { createReducer } from '@reduxjs/toolkit'; import { getCustomerDetails } from './thunk'; import { CustomerItem } from '@interfaces'; export interface CustomerDetailsState { item: CustomerItem | null; loading: boolean; error: string | null; } const initialState: CustomerDetailsState = { item: null, loading: false, error: null, }; export const customerDetailsReducer = createReducer(initialState, builder => { builder .addCase(getCustomerDetails.pending, acc => { acc.loading = true; acc.error = null; }) .addCase(getCustomerDetails.fulfilled, (acc, action) => { acc.loading = false; acc.item = action.payload; acc.error = null; }) .addCase(getCustomerDetails.rejected, (acc, action) => { acc.loading = false; acc.error = (action.payload as string) ?? action.error.message ?? 'Failed to load customer details'; }); }); export default customerDetailsReducer;