Skip to content

Commit

Permalink
fix: add more skeleton loading
Browse files Browse the repository at this point in the history
  • Loading branch information
NLNM-0-0 committed Jan 15, 2024
1 parent 85181e4 commit dd24882
Show file tree
Hide file tree
Showing 13 changed files with 385 additions and 11 deletions.
32 changes: 31 additions & 1 deletion frontend/app/customer/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { withAuth } from "@/lib/role/withAuth";
import TableLayout from "@/components/customer/table-layout";
import CreateDialog from "@/components/customer/create";
import { Button } from "@/components/ui/button";
import TableSkeleton from "@/components/skeleton/table-skeleton";
export const metadata: Metadata = {
title: "Quản lý nhà cung cấp",
};
Expand All @@ -28,7 +29,36 @@ function CustomerManage({
</div>

<div className="my-3 p-3 sha bg-white shadow-[0_1px_3px_0_rgba(0,0,0,0.2)]">
<Suspense fallback={<Loading />}>
<Suspense
fallback={
<TableSkeleton
isHasExtensionAction={false}
isHasFilter={true}
isHasSearch={true}
isHasChooseVisibleRow={true}
isHasCheckBox={false}
isHasPaging={true}
numberRow={5}
cells={[
{
percent: 1,
},
{
percent: 2,
},
{
percent: 1,
},
{
percent: 1,
},
{
percent: 1,
},
]}
/>
}
>
<TableLayout searchParams={searchParams} />
</Suspense>
</div>
Expand Down
35 changes: 34 additions & 1 deletion frontend/app/invoice/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import TableLayout from "@/components/invoice/table-layout";
import Loading from "@/components/loading";
import TableSkeleton from "@/components/skeleton/table-skeleton";
import { withAuth } from "@/lib/role/withAuth";
import { Metadata } from "next";
import { Suspense } from "react";
Expand All @@ -19,7 +20,39 @@ const Invoice = ({
</div>

<div className="my-3 p-3 sha bg-white shadow-[0_1px_3px_0_rgba(0,0,0,0.2)]">
<Suspense fallback={<Loading />}>
<Suspense
fallback={
<TableSkeleton
isHasExtensionAction={false}
isHasFilter={true}
isHasSearch={true}
isHasChooseVisibleRow={true}
isHasCheckBox={false}
isHasPaging={true}
numberRow={5}
cells={[
{
percent: 1,
},
{
percent: 2,
},
{
percent: 1,
},
{
percent: 1,
},
{
percent: 1,
},
{
percent: 1,
},
]}
/>
}
>
<TableLayout searchParams={searchParams} />
</Suspense>
</div>
Expand Down
3 changes: 2 additions & 1 deletion frontend/app/product/books/[bookId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import updateBook from "@/lib/book/updateBook";
import { BookTitle } from "@/types";
import BookTitleSelectEdit from "@/components/book-manage/book-title-select-edit";
import { useLoading } from "@/hooks/loading-context";
import BookDetailSkeleton from "@/components/skeleton/book-detail-skeleton";

const FormSchema = z.object({
bookTitleId: z.string().min(1, "Vui lòng chọn một đầu sách"),
Expand Down Expand Up @@ -193,7 +194,7 @@ const EditBook = ({ params }: { params: { bookId: string } }) => {

const { currentUser } = useCurrentUser();
if (!currentUser || isLoading) {
return <Loading></Loading>;
return <BookDetailSkeleton/>;
} else if (
currentUser &&
!includesRoles({
Expand Down
3 changes: 2 additions & 1 deletion frontend/app/product/books/add/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { useCurrentUser } from "@/hooks/use-user";
import { includesRoles } from "@/lib/utils";
import NoRole from "@/components/no-role";
import { useLoading } from "@/hooks/loading-context";
import BookAddSkeleton from "@/components/skeleton/book-add-skeleton";

const FormSchema = z.object({
bookTitleId: z.string().min(1, "Vui lòng chọn một đầu sách"),
Expand Down Expand Up @@ -182,7 +183,7 @@ const InsertNewBook = () => {
};
const { currentUser } = useCurrentUser();
if (!currentUser) {
return <Loading />;
return <BookAddSkeleton />;
} else if (
currentUser &&
!includesRoles({
Expand Down
38 changes: 37 additions & 1 deletion frontend/app/product/books/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import React, { Suspense } from "react";
import { Metadata } from "next";
import { withAuth } from "@/lib/role/withAuth";
import { FaPlus } from "react-icons/fa";
import TableSkeleton from "@/components/skeleton/table-skeleton";
export const metadata: Metadata = {
title: "Sách",
};
Expand All @@ -31,7 +32,42 @@ function BookManagement({
</div>
<div className="flex flex-row flex-wrap gap-2"></div>
<div className="mb-4 p-3 sha bg-white shadow-[0_1px_3px_0_rgba(0,0,0,0.2)]">
<Suspense fallback={<Loading />}>
<Suspense
fallback={
<TableSkeleton
isHasExtensionAction={true}
isHasFilter={true}
isHasSearch={true}
isHasChooseVisibleRow={true}
isHasCheckBox={true}
isHasPaging={true}
numberRow={5}
cells={[
{
percent: 1,
},
{
percent: 5,
},
{
percent: 1,
},
{
percent: 1,
},
{
percent: 1,
},
{
percent: 1,
},
{
percent: 1,
},
]}
/>
}
>
<TableLayout searchParams={searchParams} />
</Suspense>
</div>
Expand Down
23 changes: 22 additions & 1 deletion frontend/app/product/categories/table-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { CategoryTable } from "@/components/book-manage/category-table";
import CreateCategory from "@/components/book-manage/create-category";
import Loading from "@/components/loading";
import TableSkeleton from "@/components/skeleton/table-skeleton";
import { Button } from "@/components/ui/button";
import { toast } from "@/components/ui/use-toast";
import { endPoint } from "@/constants";
Expand Down Expand Up @@ -81,7 +82,27 @@ const TableLayout = ({
</div>
<div className="flex flex-row flex-wrap gap-2"></div>
<div className="mb-4 p-3 sha bg-white shadow-[0_1px_3px_0_rgba(0,0,0,0.2)]">
<Suspense fallback={<Loading />}>
<Suspense
fallback={
<TableSkeleton
isHasExtensionAction={false}
isHasFilter={false}
isHasSearch={true}
isHasChooseVisibleRow={false}
isHasCheckBox={false}
isHasPaging={true}
numberRow={5}
cells={[
{
percent: 5,
},
{
percent: 1,
},
]}
/>
}
>
<CategoryTable
searchParams={searchParams}
currentUser={currentUser}
Expand Down
23 changes: 22 additions & 1 deletion frontend/app/product/publishers/table-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import CreatePublisher from "@/components/book-manage/create-publisher";
import { PublisherTable } from "@/components/book-manage/publisher-table";
import Loading from "@/components/loading";
import TableSkeleton from "@/components/skeleton/table-skeleton";
import { Button } from "@/components/ui/button";
import { endPoint } from "@/constants";
import { useCurrentUser } from "@/hooks/use-user";
Expand Down Expand Up @@ -45,7 +46,27 @@ const TableLayout = ({
</div>
<div className="flex flex-row flex-wrap gap-2"></div>
<div className="mb-4 p-3 sha bg-white shadow-[0_1px_3px_0_rgba(0,0,0,0.2)]">
<Suspense fallback={<Loading />}>
<Suspense
fallback={
<TableSkeleton
isHasExtensionAction={false}
isHasFilter={false}
isHasSearch={true}
isHasChooseVisibleRow={false}
isHasCheckBox={false}
isHasPaging={true}
numberRow={5}
cells={[
{
percent: 5,
},
{
percent: 1,
},
]}
/>
}
>
<PublisherTable
searchParams={searchParams}
currentUser={currentUser}
Expand Down
38 changes: 37 additions & 1 deletion frontend/app/staff/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Loading from "@/components/loading";
import TableSkeleton from "@/components/skeleton/table-skeleton";
import CreateStaffDialog from "@/components/staff/create-staff-dialog";
import TableLayout from "@/components/staff/table-layout";
import { withAuth } from "@/lib/role/withAuth";
Expand All @@ -20,7 +21,42 @@ const StaffManage = ({
<CreateStaffDialog />
</div>
<div className="mb-4 p-3 sha bg-white shadow-[0_1px_3px_0_rgba(0,0,0,0.2)]">
<Suspense fallback={<Loading />}>
<Suspense
fallback={
<TableSkeleton
isHasExtensionAction={true}
isHasFilter={true}
isHasSearch={true}
isHasChooseVisibleRow={true}
isHasCheckBox={true}
isHasPaging={true}
numberRow={5}
cells={[
{
percent: 1,
},
{
percent: 2,
},
{
percent: 2,
},
{
percent: 1,
},
{
percent: 2,
},
{
percent: 1,
},
{
percent: 1,
},
]}
/>
}
>
<TableLayout searchParams={searchParams} />
</Suspense>
</div>
Expand Down
32 changes: 31 additions & 1 deletion frontend/app/supplier/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Suspense } from "react";
import { Metadata } from "next";
import { withAuth } from "@/lib/role/withAuth";
import { includesRoles } from "@/lib/utils";
import TableSkeleton from "@/components/skeleton/table-skeleton";
export const metadata: Metadata = {
title: "Quản lý nhà cung cấp",
};
Expand All @@ -24,7 +25,36 @@ function SupplierManage({
</div>

<div className="my-3 p-3 sha bg-white shadow-[0_1px_3px_0_rgba(0,0,0,0.2)]">
<Suspense fallback={<Loading />}>
<Suspense
fallback={
<TableSkeleton
isHasExtensionAction={true}
isHasFilter={true}
isHasSearch={true}
isHasChooseVisibleRow={true}
isHasCheckBox={true}
isHasPaging={true}
numberRow={5}
cells={[
{
percent: 1,
},
{
percent: 2,
},
{
percent: 2,
},
{
percent: 1,
},
{
percent: 1,
},
]}
/>
}
>
<TableLayout searchParams={searchParams} />
</Suspense>
</div>
Expand Down
3 changes: 2 additions & 1 deletion frontend/components/book-manage/book-title-select-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { FaPlus } from "react-icons/fa";
import CreateTitleDialog from "./create-title-dialog";
import { useCurrentUser } from "@/hooks/use-user";
import getAllTitleList from "@/lib/book/getAllTitleList";
import ListSkeleton from "../skeleton/list_skeleton";
export interface Props {
handleTitleSet: (titleId: string) => void;
titleId: string;
Expand All @@ -46,7 +47,7 @@ const BookTitleSelect = ({ handleTitleSet, titleId, readOnly }: Props) => {
const { currentUser } = useCurrentUser();
if (isError) return <div>Failed to load</div>;
if (!titles || isLoading) {
<Loading />;
<ListSkeleton numberRow={5} />;
} else
return (
<div className="flex flex-col gap-3">
Expand Down
3 changes: 2 additions & 1 deletion frontend/components/book-manage/book-title-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { FaPlus } from "react-icons/fa";
import CreateTitleDialog from "./create-title-dialog";
import { useCurrentUser } from "@/hooks/use-user";
import getAllTitleList from "@/lib/book/getAllTitleList";
import ListSkeleton from "../skeleton/list_skeleton";

const BookTitleSelect = ({ handleTitleSet }: TitleListProps) => {
const [open, setOpen] = useState(false);
Expand All @@ -38,7 +39,7 @@ const BookTitleSelect = ({ handleTitleSet }: TitleListProps) => {
const { currentUser } = useCurrentUser();
if (isError) return <div>Failed to load</div>;
if (!titles || isLoading) {
<Loading />;
<ListSkeleton numberRow={5} />;
} else
return (
<div className="flex flex-col gap-3">
Expand Down
Loading

0 comments on commit dd24882

Please sign in to comment.