49 lines
1.3 KiB
TypeScript

import { createReducer } from '@reduxjs/toolkit';
import { KycDocUploadResponse } from '@interfaces';
import { fetchMyKyc, uploadKyc } from './thunk';
import { MyKycResponse } from '@interfaces';
export interface KycState {
isLoading: boolean;
error: string | null;
uploadResponse: KycDocUploadResponse | null;
myKycResponse: MyKycResponse | null;
}
const initialState: KycState = {
isLoading: false,
error: null,
uploadResponse: null,
myKycResponse: null,
};
export const kycReducer = createReducer(initialState, builder => {
builder
.addCase(uploadKyc.pending, state => {
state.isLoading = true;
state.error = null;
})
.addCase(uploadKyc.fulfilled, (state, action) => {
state.isLoading = false;
state.uploadResponse = action.payload;
})
.addCase(uploadKyc.rejected, (state, action) => {
state.isLoading = false;
state.error = action.payload as string;
});
builder
.addCase(fetchMyKyc.pending, state => {
state.isLoading = true;
state.error = null;
})
.addCase(fetchMyKyc.fulfilled, (state, action) => {
state.isLoading = false;
state.myKycResponse = action.payload;
})
.addCase(fetchMyKyc.rejected, (state, action) => {
state.isLoading = false;
state.error = action.payload as string;
});
});