38 lines
1.1 KiB
TypeScript

import { createAsyncThunk } from '@reduxjs/toolkit';
import { addAccountApi, fetchBankAccountsApi } from '@api';
import { AddBankDetailsPayload, GetBankAccountsResponse } from '@interfaces';
export const addBankAccount = createAsyncThunk<
GetBankAccountsResponse,
AddBankDetailsPayload | FormData,
{ rejectValue: string }
>('addBankDetails/addBankAccount', async (payload, { rejectWithValue }) => {
try {
const response = await addAccountApi(payload);
return response;
} catch (error: any) {
const message =
error?.response?.data?.message ||
error?.message ||
'Failed to add bank account';
return rejectWithValue(message);
}
});
export const fetchBankAccounts = createAsyncThunk<
GetBankAccountsResponse,
void,
{ rejectValue: string }
>('addBankDetails/fetchBankAccounts', async (_, { rejectWithValue }) => {
try {
const response = await fetchBankAccountsApi();
return response;
} catch (error: any) {
const message =
error?.response?.data?.message ||
error?.message ||
'Failed to fetch bank accounts';
return rejectWithValue(message);
}
});