35 lines
946 B
TypeScript
35 lines
946 B
TypeScript
import { UserProfile } from '@interfaces';
|
|
import { completeOnboard } from './thunk';
|
|
import { createReducer } from '@reduxjs/toolkit';
|
|
|
|
export interface completeProfileState {
|
|
isLoading: boolean;
|
|
isSubmitting?: boolean;
|
|
error: string | null;
|
|
submitError: string | null;
|
|
userProfile: UserProfile | null;
|
|
}
|
|
|
|
const initialState: completeProfileState = {
|
|
isLoading: false,
|
|
error: null,
|
|
submitError: null,
|
|
userProfile: null,
|
|
};
|
|
|
|
export const completeProfileReducer = createReducer(initialState, builder => {
|
|
builder
|
|
.addCase(completeOnboard.pending, state => {
|
|
state.isLoading = true;
|
|
state.submitError = null;
|
|
})
|
|
.addCase(completeOnboard.fulfilled, (state, action) => {
|
|
state.isLoading = false;
|
|
state.userProfile = action.payload;
|
|
})
|
|
.addCase(completeOnboard.rejected, (state, action) => {
|
|
state.isLoading = false;
|
|
state.submitError = action.payload as string;
|
|
});
|
|
});
|