From 0f29dafa7a5c0a1e7c7b6f7fa8cb3011535a9156 Mon Sep 17 00:00:00 2001 From: Vxrcel Date: Mon, 29 Jul 2024 14:41:41 +0100 Subject: [PATCH 1/4] redeploy --- .../products/[productId]/form-images/project-logo.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/dashboard/(user-dashboard)/products/[productId]/form-images/project-logo.tsx b/src/app/dashboard/(user-dashboard)/products/[productId]/form-images/project-logo.tsx index aa5009f02..0acddc8c4 100644 --- a/src/app/dashboard/(user-dashboard)/products/[productId]/form-images/project-logo.tsx +++ b/src/app/dashboard/(user-dashboard)/products/[productId]/form-images/project-logo.tsx @@ -5,7 +5,7 @@ import { UseFormReturn } from "react-hook-form"; import BlurImage from "~/components/miscellaneous/blur-image"; import { Button } from "~/components/ui/button"; import { cn } from "~/lib/utils"; -import { NewProduct } from "../schema/schema"; +import { NewProduct } from "../../_components/schema/schema"; type Properties = { form: UseFormReturn; From bb9ced1e860ff4ade14724690d724b1ebdbaa027 Mon Sep 17 00:00:00 2001 From: Vxrcel Date: Mon, 29 Jul 2024 21:09:35 +0100 Subject: [PATCH 2/4] Products details page --- .../[productId]/form-images/project-logo.tsx | 13 +- .../[productId]/product-details-component.tsx | 554 ++++++++++++------ .../[productId]/product-details-content.tsx | 2 +- .../_components/new-product-modal.tsx | 2 +- .../_components/product-body-shadcn.tsx | 6 +- .../products/_components/schema/schema.ts | 75 ++- ...{categories.moct.ts => categories.mock.ts} | 5 + .../products/data/stocks.mock.ts | 39 ++ src/app/globals.css | 4 + 9 files changed, 495 insertions(+), 205 deletions(-) rename src/app/dashboard/(user-dashboard)/products/data/{categories.moct.ts => categories.mock.ts} (62%) create mode 100644 src/app/dashboard/(user-dashboard)/products/data/stocks.mock.ts diff --git a/src/app/dashboard/(user-dashboard)/products/[productId]/form-images/project-logo.tsx b/src/app/dashboard/(user-dashboard)/products/[productId]/form-images/project-logo.tsx index 0acddc8c4..6490e506e 100644 --- a/src/app/dashboard/(user-dashboard)/products/[productId]/form-images/project-logo.tsx +++ b/src/app/dashboard/(user-dashboard)/products/[productId]/form-images/project-logo.tsx @@ -5,10 +5,10 @@ import { UseFormReturn } from "react-hook-form"; import BlurImage from "~/components/miscellaneous/blur-image"; import { Button } from "~/components/ui/button"; import { cn } from "~/lib/utils"; -import { NewProduct } from "../../_components/schema/schema"; +import { EditProduct } from "../../_components/schema/schema"; type Properties = { - form: UseFormReturn; + form: UseFormReturn; name: string; }; const handleImageChange = (event: React.ChangeEvent) => { @@ -72,12 +72,15 @@ const ProjectLogo = ({ form, name }: Properties) => { )} /> - + ) : (
{ const { addProduct } = useProducts(); const [isLoading, startTransition] = useTransition(); + const router = useRouter(); - const new_product_form = useForm>({ + const new_product_form = useForm>({ defaultValues: { - product_name: "", - description: "", + product_name: product.name || "", + description: product.description || "", price: "", category: "", quantity: "", media: { - url: "", + url: product.image || "", id: "", }, + stocks: [ + { + id: "P0001", + size: "Small", + stock: "0", + price: "", + }, + { + id: "P0002", + size: "Standard", + stock: String(product.stock) || "0", + price: String(product.price) || "", + }, + { + id: "P0003", + size: "Large", + stock: "0", + price: "", + }, + ], }, - resolver: zodResolver(NewProductSchema), + resolver: zodResolver(EditProductSchema), }); + const FORM_STOCKS = new_product_form.getValues("stocks"); + const handleAddNewStock = () => { + const previousStocks = FORM_STOCKS; + new_product_form.setValue("stocks", [ + ...previousStocks, + { + id: `S${generateId(5)}`, + size: "", + stock: "", + price: "", + }, + ]); + }; const hasProjectLogo = new_product_form.getValues("media.url"); - - const onSubmit = async (values: z.infer) => { + new_product_form.watch("stocks"); + // DISABLE + const disableAddStockButton = shouldDisableAddStocksButton({ + stocks: FORM_STOCKS, + }); + const onSubmit = async (values: z.infer) => { startTransition(async () => { const date_data = getCurrentDateTime(); await simulateDelay(3); @@ -83,219 +121,347 @@ const ProductDetailsComponent = ({ }; return ( -
-
-
- - - - - {product.name} - - +
+ +
+
+ + + + + {product.name} + - {product.status === "in_stock" && "In Stock"} - {product.status === "low_on_stock" && "Low on Stock"} - {product.status === "out_of_stock" && "Out of Stock"} - -
-
- - -
-
- - -
- {" "} - ( - - - Title* - - - - - - + className={cn( + "flex items-center gap-x-1 whitespace-nowrap rounded-full pl-2 text-sm leading-5 text-neutral-dark-1 md:gap-x-2", )} - /> - ( - - - Description - - -
-