2026-07-16 18:26:01 +05:30

38 lines
923 B
TypeScript

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