aboutsummaryrefslogtreecommitdiff
path: root/jb-ui/src/models/cashoutRequests.ts
blob: 985b949af26f08167d6bc9e969744d3e455d8a6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { createApi, fakeBaseQuery } from "@reduxjs/toolkit/query/react";
import { WalletApi } from "@/api_fsb";
import type { CashoutRequestSummary } from "@/api_fsb";

const walletApi = new WalletApi();

// /<product-id>/cashout/

export const cashoutRequests = createApi({
  reducerPath: "cashoutRequests",
  baseQuery: fakeBaseQuery<string>(),
  endpoints: (builder) => ({
    getUserCashouts: builder.query<
      CashoutRequestSummary[],
      { bpid: string; productUserId: string }
    >({
      queryFn: async ({ bpid, productUserId }) => {
        try {
          const res = await walletApi.filterUserCashoutsProductIdCashoutGet(
            bpid,
            productUserId,
          );
          return { data: res.data.cashouts as CashoutRequestSummary[] };
        } catch (e) {
          return { error: e instanceof Error ? e.message : "Request failed" };
        }
      },
    }),
  }),
});

export const { useGetUserCashoutsQuery } = cashoutRequests;