32 lines
871 B
TypeScript

import { createReducer, createSlice } from '@reduxjs/toolkit';
import { getAccountInfoThunk } from './thunk';
import { DeliveryPartnerProfileResponse } from '@interfaces';
interface ProfileState {
profile: DeliveryPartnerProfileResponse | null;
loading: boolean;
error: string | null;
}
const initialState: ProfileState = {
profile: null,
loading: false,
error: null,
};
export const profileReducer = createReducer(initialState, builder => {
builder
.addCase(getAccountInfoThunk.pending, state => {
state.loading = true;
state.error = null;
})
.addCase(getAccountInfoThunk.fulfilled, (state, action) => {
state.loading = false;
state.profile = action.payload;
})
.addCase(getAccountInfoThunk.rejected, (state, action) => {
state.loading = false;
state.error = action.payload as string;
});
});