diff --git a/src/components/empty.tsx b/src/components/empty.tsx new file mode 100644 index 0000000..252abcb --- /dev/null +++ b/src/components/empty.tsx @@ -0,0 +1,10 @@ +import * as React from "react" + +interface EmptyProps { + description?: React.ReactNode + icon?: React.ReactNode +} + +export function Empty(props: EmptyProps) { + return
{props.description || "No results"}
+} diff --git a/src/components/loading.tsx b/src/components/loading.tsx new file mode 100644 index 0000000..1df415b --- /dev/null +++ b/src/components/loading.tsx @@ -0,0 +1,12 @@ +import { Icons } from "./icons" + +export function Loading() { + return ( +
+
+ + Loading... +
+
+ ) +} diff --git a/src/hooks/query/use-user.ts b/src/hooks/query/use-user.ts index 2a326e0..6e667cd 100644 --- a/src/hooks/query/use-user.ts +++ b/src/hooks/query/use-user.ts @@ -50,7 +50,7 @@ export function useUserLogoutMutation() { } export function useUsers(pagination: PaginationState) { - const { data } = useQuery({ + const { data, isPending } = useQuery({ queryKey: ["users", pagination.pageIndex, pagination.pageSize], queryFn: async () => apiFetch<{ list: IUsers[] @@ -67,6 +67,7 @@ export function useUsers(pagination: PaginationState) { }) return { + isPending, data: { list: data?.list || [], total: data?.total || 0, diff --git a/src/pages/(admin)/(with-layout)/list/basic-list.tsx b/src/pages/(admin)/(with-layout)/list/basic-list.tsx index b4a65bd..d59fd66 100644 --- a/src/pages/(admin)/(with-layout)/list/basic-list.tsx +++ b/src/pages/(admin)/(with-layout)/list/basic-list.tsx @@ -20,6 +20,8 @@ import { } from "@tanstack/react-table" import * as React from "react" +import { Empty } from "@/components/empty" +import { Loading } from "@/components/loading" import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar" import { Button } from "@/components/ui/button" import { Checkbox } from "@/components/ui/checkbox" @@ -195,7 +197,7 @@ export function Component() { const [columnVisibility, setColumnVisibility] = React.useState({}) const [rowSelection, setRowSelection] = React.useState({}) - const { data: users } = useUsers(pagination) + const { data: users, isPending } = useUsers(pagination) const PAGINATION_STEP = 3 // You can easily change this value to adjust the pagination step @@ -300,7 +302,9 @@ export function Component() { colSpan={columns.length} className="h-24 text-center" > - No results. + { + isPending ? : + } )} diff --git a/src/pages/(admin)/layout.tsx b/src/pages/(admin)/layout.tsx index bb1ca89..5de71f9 100644 --- a/src/pages/(admin)/layout.tsx +++ b/src/pages/(admin)/layout.tsx @@ -46,7 +46,7 @@ export function Component() { -
+