From b2b6d53308ec45fbfb5d591f94ce458fab861408 Mon Sep 17 00:00:00 2001 From: Stefan Kairinos Date: Fri, 9 Aug 2024 09:55:41 +0300 Subject: [PATCH] fix: Portal frontend 25 (#52) * use query manager * refactor --- src/components/SyncError.tsx | 14 ++++ src/components/TablePagination.tsx | 8 +- src/components/form/ApiAutocompleteField.tsx | 19 +---- src/components/index.ts | 3 + src/hooks/api.ts | 37 --------- src/hooks/api.tsx | 83 ++++++++++++++++++++ src/hooks/index.ts | 4 + src/utils/api.ts | 1 + 8 files changed, 110 insertions(+), 59 deletions(-) create mode 100644 src/components/SyncError.tsx delete mode 100644 src/hooks/api.ts create mode 100644 src/hooks/api.tsx diff --git a/src/components/SyncError.tsx b/src/components/SyncError.tsx new file mode 100644 index 0000000..1a50941 --- /dev/null +++ b/src/components/SyncError.tsx @@ -0,0 +1,14 @@ +import { SyncProblem as SyncProblemIcon } from "@mui/icons-material" +import { Stack, Typography } from "@mui/material" +import { type FC } from "react" + +export interface SyncErrorProps {} + +const SyncError: FC = () => ( + + + Failed to sync data + +) + +export default SyncError diff --git a/src/components/TablePagination.tsx b/src/components/TablePagination.tsx index fd327f2..374217a 100644 --- a/src/components/TablePagination.tsx +++ b/src/components/TablePagination.tsx @@ -1,4 +1,3 @@ -import { SyncProblem as SyncProblemIcon } from "@mui/icons-material" import { CircularProgress, TablePagination as MuiTablePagination, @@ -6,7 +5,6 @@ import { Stack, type StackProps, type TablePaginationBaseProps, - Typography, } from "@mui/material" import type { TypedUseLazyQuery } from "@reduxjs/toolkit/query/react" import { @@ -18,6 +16,7 @@ import { import { type Pagination, usePagination } from "../hooks/api" import type { ListArg, ListResult } from "../utils/api" +import SyncError from "./SyncError" export type TablePaginationProps< QueryArg extends ListArg, @@ -95,10 +94,7 @@ const TablePagination = < {isLoading ? ( ) : error || !data ? ( - <> - - Failed to load data - + ) : ( children(data, { limit, page, offset, count, maxLimit: max_limit }) )} diff --git a/src/components/form/ApiAutocompleteField.tsx b/src/components/form/ApiAutocompleteField.tsx index 479fb38..18202e9 100644 --- a/src/components/form/ApiAutocompleteField.tsx +++ b/src/components/form/ApiAutocompleteField.tsx @@ -1,11 +1,4 @@ -import { SyncProblem as SyncProblemIcon } from "@mui/icons-material" -import { - Button, - CircularProgress, - Stack, - Typography, - type ChipTypeMap, -} from "@mui/material" +import { Button, CircularProgress, type ChipTypeMap } from "@mui/material" import type { TypedUseLazyQuery } from "@reduxjs/toolkit/query/react" import { Children, @@ -21,6 +14,7 @@ import { } from "../../components/form" import { usePagination } from "../../hooks/api" import type { ListArg, ListResult, TagId } from "../../utils/api" +import SyncError from "../SyncError" export interface ApiAutocompleteFieldProps< SearchKey extends keyof Omit, @@ -135,14 +129,7 @@ const ApiAutocompleteField = < const listItems = Children.toArray(children) if (isLoading) listItems.push() else { - if (isError) { - listItems.push( - - - Failed to load data - , - ) - } + if (isError) listItems.push() if (hasMore) { listItems.push(