Skip to content

Commit

Permalink
fix: supplier select
Browse files Browse the repository at this point in the history
  • Loading branch information
kimthu09 committed Jan 15, 2024
1 parent 3b2b2dc commit b641122
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 67 deletions.
5 changes: 2 additions & 3 deletions frontend/app/stockmanage/check/add/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ import { useSWRConfig } from "swr";
import CheckInsert from "@/components/stock-manage/check-insert";
import createCheckNote from "@/lib/check/createCheckNote";
import { useCurrentUser } from "@/hooks/use-user";
import Loading from "@/components/loading";
import { includesRoles } from "@/lib/utils";
import NoRole from "@/components/no-role";
import ImportSheet from "@/components/book-manage/import-sheet";
import getAllBookForSale from "@/lib/book/getAllBookForSale";
import { useLoading } from "@/hooks/loading-context";
import ImportNoteAddSkeleton from "@/components/skeleton/import-note-add-skeleton";
import InventoryCheckNoteAddSkeleton from "@/components/skeleton/inventory-check-note-add-skeleton";

export const FormSchema = z.object({
id: z.string().max(12, "Tối đa 12 ký tự"),
Expand Down Expand Up @@ -168,7 +167,7 @@ const AddNote = () => {
};
const { currentUser } = useCurrentUser();
if (!currentUser) {
return <ImportNoteAddSkeleton />;
return <InventoryCheckNoteAddSkeleton />;
} else if (
currentUser &&
!includesRoles({
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/stockmanage/import/[importId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const ImportDetail = ({ params }: { params: { importId: string } }) => {
});
if (isError) return <div>Failed to load</div>;
else if (!currentUser || isLoading) {
return <ImportNoteDetailSkeleton/>;
return <ImportNoteDetailSkeleton />;
} else if (
currentUser &&
!includesRoles({
Expand All @@ -75,7 +75,7 @@ const ImportDetail = ({ params }: { params: { importId: string } }) => {
<span className="font-light">Mã phiếu nhập</span>
<span>{data.id}</span>
</div>
<div className="flex gap-2 flex-nowrap">
<div className="flex gap-2 flex-wrap justify-end">
<Button
variant={"outline"}
className="p-2"
Expand Down
10 changes: 7 additions & 3 deletions frontend/app/stockmanage/import/add/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ import createImportNote from "@/lib/import/createImportNote";
import { Switch } from "@/components/ui/switch";
import { useSWRConfig } from "swr";
import { useCurrentUser } from "@/hooks/use-user";
import Loading from "@/components/loading";
import { includesRoles } from "@/lib/utils";
import NoRole from "@/components/no-role";
import ImportSheet from "@/components/book-manage/import-sheet";
import getAllBookForSale from "@/lib/book/getAllBookForSale";
import { useLoading } from "@/hooks/loading-context";
import InventoryCheckNoteAddSkeleton from "@/components/skeleton/inventory-check-note-add-skeleton";
import ImportNoteAddSkeleton from "@/components/skeleton/import-note-add-skeleton";

export const FormSchema = z.object({
id: z.string().max(12, "Tối đa 12 ký tự"),
Expand Down Expand Up @@ -128,7 +127,7 @@ const AddNote = () => {

const { currentUser } = useCurrentUser();
if (!currentUser) {
return <InventoryCheckNoteAddSkeleton />;
return <ImportNoteAddSkeleton />;
} else if (
currentUser &&
!includesRoles({
Expand Down Expand Up @@ -225,8 +224,13 @@ const AddNote = () => {
<div className="flex-1">
<Label>Nhà cung cấp</Label>
<SupplierList
canAdd
supplierId={supplierId}
setSupplierId={handleSupplierIdSet}
handleSupplierAdded={(supplierId) => {
mutate(`${endPoint}/v1/suppliers/all`);
handleSupplierIdSet(supplierId);
}}
/>
{errors.supplierId && (
<span className="error___message">
Expand Down
7 changes: 6 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 { Button } from "@/components/ui/button";
export const metadata: Metadata = {
title: "Quản lý nhà cung cấp",
};
Expand All @@ -19,7 +20,11 @@ function SupplierManage({
<div className="flex flex-row justify-between ">
<h1>Danh sách nhà cung cấp</h1>
<div className="flex gap-4">
<CreateDialog />
<CreateDialog>
<Button className="lg:px-4 px-2 whitespace-nowrap">
Thêm nhà cung cấp
</Button>
</CreateDialog>
</div>
</div>

Expand Down
4 changes: 2 additions & 2 deletions frontend/components/customer/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ const CreateDialog = ({
const onSubmit: SubmitHandler<z.infer<typeof SupplierSchema>> = async (
data
) => {
setOpen(false);

const response: Promise<any> = createCustomer(data);
showLoading();
const responseData = await response;
Expand All @@ -67,6 +65,8 @@ const CreateDialog = ({
title: "Thành công",
description: "Thêm khách hàng thành công",
});
setOpen(false);

if (handleCustomerAdded) {
handleCustomerAdded(responseData.data);
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/invoice/table-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const TableLayout = async ({
search: search?.toString(),
});
const staffs = await staffsData;

console.log(staffs);
const totalPage = Math.ceil(staffs.paging.total / staffs.paging.limit);
return <InvoiceTable data={staffs.data} totalPage={totalPage} />;
};
Expand Down
6 changes: 3 additions & 3 deletions frontend/components/skeleton/table-skeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type TableSkeletonProps = {
isHasSearch: boolean;
isHasChooseVisibleRow: boolean;
isHasCheckBox: boolean;
isHasPaging:boolean;
isHasPaging: boolean;
numberRow: number;
cells: TableSkeletonCell[];
};
Expand All @@ -33,7 +33,7 @@ const TableSkeleton: React.FC<TableSkeletonProps> = ({
{isHasSearch && <Skeleton className="w-full h-8 flex-1" />}
{isHasChooseVisibleRow && <Skeleton className="w-24 h-8" />}
</div>
<div className="flex flex-col rounded-md border">
<div className="flex flex-col rounded-md border overflow-x-auto">
{[...Array(numberRow + 1)].map((_, index) => (
<div
key={index}
Expand Down Expand Up @@ -63,7 +63,7 @@ const TableSkeleton: React.FC<TableSkeletonProps> = ({
<div className="flex flex-row gap-2">
<Skeleton className="w-8 h-8" />
<Skeleton className="w-8 h-8" />
<Skeleton className="w-24 h-8" />
<Skeleton className="flex-1 h-8" />
<Skeleton className="w-8 h-8" />
<Skeleton className="w-8 h-8" />
</div>
Expand Down
37 changes: 0 additions & 37 deletions frontend/components/stock-manage/check-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import { Input } from "../ui/input";
import { statusNoteToString } from "@/lib/utils";
import { toast } from "../ui/use-toast";
import { useRouter, useSearchParams } from "next/navigation";
import Loading from "../loading";
import Paging, { PagingProps } from "../paging";
import {
Controller,
Expand All @@ -53,10 +52,7 @@ import { Label } from "../ui/label";
import { AiOutlineClose } from "react-icons/ai";
import { FilterDatePicker } from "./date-picker";
import StaffList from "../staff-list";
import getAllImportNoteForExcel from "@/lib/import/getAllImportNoteForExcel";
import SupplierList from "../supplier-list";
import ExportDialog from "../supplier-manage/export-dialog";
import StatusNoteList from "../status-note-list";
import getAllCheckNote from "@/lib/check/getAllImport";
import { ExportCheckNote } from "./excel-check-list";
import getAllCheckNoteForExcel from "@/lib/import/getAllCheckNoteForExcel";
Expand Down Expand Up @@ -385,13 +381,6 @@ export function CheckTable() {
type="text"
required
></Input>
) : item.type.includes("Price") ? (
<Input
{...register(`filters.${index}.value`)}
className="flex-1"
type="number"
required
></Input>
) : item.type.includes("At") ? (
<Controller
control={control}
Expand Down Expand Up @@ -438,32 +427,6 @@ export function CheckTable() {
});
}}
/>
) : item.type === "supplier" ? (
<div className="flex-1">
<SupplierList
supplierId={supplierId}
setSupplierId={(value) => {
setSupplierId(value);
update(index, {
type: item.type,
value: value,
});
}}
/>
</div>
) : item.type === "status" ? (
<div className="flex-1">
<StatusNoteList
status={status}
setStatus={(value) => {
setStatus(value);
update(index, {
type: item.type,
value: value,
});
}}
/>
</div>
) : null}
<Button
variant={"ghost"}
Expand Down
12 changes: 8 additions & 4 deletions frontend/components/supplier-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ import {
import { cn } from "@/lib/utils";
import getAllSupplier from "@/lib/supplier/getAllSupplier";
import DropdownSkeleton from "./skeleton/dropdown-skeleton";
import CreateDialog from "./supplier-manage/create";
import { FaPlus } from "react-icons/fa";

export interface SupplierListProps {
supplierId: string;
setSupplierId: (id: string) => void;
canAdd?: boolean;
handleSupplierAdded?: (customerId: string) => void;
}
const SupplierList = ({
supplierId,
setSupplierId,
canAdd,
handleSupplierAdded,
}: SupplierListProps) => {
const [open, setOpen] = useState(false);
const { suppliers, isLoading, isError, mutate } = getAllSupplier();
Expand Down Expand Up @@ -87,13 +91,13 @@ const SupplierList = ({
</Command>
</DropdownMenuContent>
</DropdownMenu>
{/* {canAdd ? (
<CreatePublisher handlePublisherAdded={handlePublisherAdded}>
{canAdd ? (
<CreateDialog handleSupplierAdded={handleSupplierAdded}>
<Button type="button" size={"icon"} className="px-3">
<FaPlus />
</Button>
</CreatePublisher>
) : null} */}
</CreateDialog>
) : null}
</div>
);
};
Expand Down
29 changes: 19 additions & 10 deletions frontend/components/supplier-manage/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ const SupplierSchema = z.object({
}),
});

const CreateDialog = () => {
const CreateDialog = ({
children,
handleSupplierAdded,
}: {
children: React.ReactNode;
handleSupplierAdded?: (supplierId: string) => void;
}) => {
const { currentUser } = useCurrentUser();
const {
register,
Expand All @@ -55,24 +61,29 @@ const CreateDialog = () => {
const onSubmit: SubmitHandler<z.infer<typeof SupplierSchema>> = async (
data
) => {
setOpen(false);

const response: Promise<any> = createSupplier(data);
showLoading();
const responseData = await response;
hideLoading();
if (responseData.hasOwnProperty("errorKey")) {
console.log("hi");
toast({
variant: "destructive",
title: "Có lỗi",
description: responseData.message,
});
} else {
console.log("there");

toast({
variant: "success",
title: "Thành công",
description: "Thêm nhà cung cấp thành công",
});
setOpen(false);
if (handleSupplierAdded) {
handleSupplierAdded(responseData.data);
}
router.refresh();
}
};
Expand Down Expand Up @@ -103,16 +114,12 @@ const CreateDialog = () => {
setOpen(open);
}}
>
<DialogTrigger asChild>
<Button className="lg:px-4 px-2 whitespace-nowrap">
Thêm nhà cung cấp
</Button>
</DialogTrigger>
<DialogTrigger asChild>{children}</DialogTrigger>
<DialogContent className="xl:max-w-[720px] max-w-[472px] p-0 bg-white">
<DialogHeader>
<DialogTitle className="p-6 pb-0">Thêm nhà cung cấp</DialogTitle>
</DialogHeader>
<form onSubmit={handleSubmit(onSubmit)}>
<form>
<div className="p-6 flex flex-col gap-4 border-y-[1px]">
<div>
<Label htmlFor="idNcc">Mã nhà cung cấp</Label>
Expand Down Expand Up @@ -172,7 +179,9 @@ const CreateDialog = () => {
Huỷ
</Button>

<Button type="submit">Thêm</Button>
<Button type="button" onClick={() => handleSubmit(onSubmit)()}>
Thêm
</Button>
</div>
</div>
</form>
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/supplier-manage/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ export function SupplierTable({
</DropdownMenu>
</div>
<div className="rounded-md border overflow-x-auto min-w-full max-w-[50vw]">
<Table>
<Table className="min-w-full w-max">
<TableHeader>
{table.getHeaderGroups().map((headerGroup) => (
<TableRow key={headerGroup.id}>
Expand Down

0 comments on commit b641122

Please sign in to comment.