55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
import { createAction, createReducer } from '@reduxjs/toolkit';
|
|
import { GetBankAccountsResponse } from '@interfaces';
|
|
import { addBankAccount, fetchBankAccounts } from './thunk';
|
|
|
|
export interface AddBankDetailsState {
|
|
isLoading: boolean;
|
|
error: string | null;
|
|
success: boolean;
|
|
bankAccounts: GetBankAccountsResponse | null;
|
|
}
|
|
|
|
const initialState: AddBankDetailsState = {
|
|
isLoading: false,
|
|
error: null,
|
|
success: false,
|
|
bankAccounts: null,
|
|
};
|
|
export const resetAddBankState = createAction('addBankDetails/reset');
|
|
|
|
export const addBankDetailsReducer = createReducer(initialState, builder =>
|
|
builder
|
|
.addCase(addBankAccount.pending, state => {
|
|
state.isLoading = true;
|
|
state.error = null;
|
|
state.success = false;
|
|
})
|
|
.addCase(addBankAccount.fulfilled, (state, action) => {
|
|
state.isLoading = false;
|
|
state.success = true;
|
|
state.bankAccounts = action.payload;
|
|
})
|
|
.addCase(addBankAccount.rejected, (state, action) => {
|
|
state.isLoading = false;
|
|
state.error = action.payload as string;
|
|
state.success = false;
|
|
})
|
|
.addCase(fetchBankAccounts.pending, state => {
|
|
state.isLoading = true;
|
|
state.error = null;
|
|
})
|
|
.addCase(fetchBankAccounts.fulfilled, (state, action) => {
|
|
state.isLoading = false;
|
|
state.bankAccounts = action.payload;
|
|
})
|
|
.addCase(fetchBankAccounts.rejected, (state, action) => {
|
|
state.isLoading = false;
|
|
state.error = action.payload as string;
|
|
})
|
|
.addCase(resetAddBankState, state => {
|
|
state.isLoading = false;
|
|
state.error = null;
|
|
state.success = false;
|
|
}),
|
|
);
|