chore: codify React component style
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { MantineProvider } from "@mantine/core";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { renderHook, waitFor } from "@testing-library/react";
|
||||
import type { ReactNode } from "react";
|
||||
import type { FC, PropsWithChildren } from "react";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { configureAuthClient } from "@/shared/api";
|
||||
import {
|
||||
@@ -25,11 +25,15 @@ describe("useBrokerageOperations", () => {
|
||||
}),
|
||||
).toEqual({ categories: ["income", "tax"], cursor: "next" });
|
||||
const client = new QueryClient();
|
||||
const wrapper = ({ children }: { children: ReactNode }) => (
|
||||
<MantineProvider>
|
||||
<QueryClientProvider client={client}>{children}</QueryClientProvider>
|
||||
</MantineProvider>
|
||||
);
|
||||
const wrapper: FC<PropsWithChildren> = (props) => {
|
||||
const { children } = props;
|
||||
|
||||
return (
|
||||
<MantineProvider>
|
||||
<QueryClientProvider client={client}>{children}</QueryClientProvider>
|
||||
</MantineProvider>
|
||||
);
|
||||
};
|
||||
|
||||
const { result } = renderHook(
|
||||
() => useBrokerageOperations("account-1", { limit: 5 }),
|
||||
|
||||
@@ -4,14 +4,14 @@ import type { paths } from "@/shared/api/generated/schema";
|
||||
type OperationsEndpoint =
|
||||
paths["/api/v1/brokerage-accounts/{accountId}/operations"]["get"];
|
||||
|
||||
export type BrokerageOperation =
|
||||
type BrokerageOperation =
|
||||
OperationsEndpoint["responses"][200]["content"]["application/json"]["items"][number];
|
||||
type BrokerageOperationsQuery = NonNullable<
|
||||
OperationsEndpoint["parameters"]["query"]
|
||||
>;
|
||||
export type OperationCategory = BrokerageOperation["category"];
|
||||
type OperationCategory = BrokerageOperation["category"];
|
||||
|
||||
export const operationCategories = [
|
||||
const operationCategories = [
|
||||
"trade",
|
||||
"income",
|
||||
"tax",
|
||||
@@ -20,9 +20,7 @@ export const operationCategories = [
|
||||
"other",
|
||||
] as const satisfies readonly OperationCategory[];
|
||||
|
||||
export function brokerageOperationsQueryParams(
|
||||
query: BrokerageOperationsQuery,
|
||||
) {
|
||||
function brokerageOperationsQueryParams(query: BrokerageOperationsQuery) {
|
||||
return {
|
||||
...(query.from ? { from: query.from } : {}),
|
||||
...(query.to ? { to: query.to } : {}),
|
||||
@@ -34,7 +32,7 @@ export function brokerageOperationsQueryParams(
|
||||
};
|
||||
}
|
||||
|
||||
export function useBrokerageOperations(
|
||||
function useBrokerageOperations(
|
||||
accountId: string | undefined,
|
||||
query: BrokerageOperationsQuery = {},
|
||||
) {
|
||||
@@ -50,3 +48,11 @@ export function useBrokerageOperations(
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
type BrokerageOperation,
|
||||
brokerageOperationsQueryParams,
|
||||
type OperationCategory,
|
||||
operationCategories,
|
||||
useBrokerageOperations,
|
||||
};
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
export type {
|
||||
BrokerageOperation,
|
||||
OperationCategory,
|
||||
} from "./api/useBrokerageOperations";
|
||||
export {
|
||||
type BrokerageOperation,
|
||||
type OperationCategory,
|
||||
operationCategories,
|
||||
useBrokerageOperations,
|
||||
} from "./api/useBrokerageOperations";
|
||||
|
||||
Reference in New Issue
Block a user