From 6d3b019eb773eac594c326ed8f614a122c2b4be8 Mon Sep 17 00:00:00 2001 From: Duckinm Date: Tue, 11 Jul 2023 02:58:22 +0700 Subject: [PATCH] chore: add button to toast to immediately look into it --- src/components/forms/update-product-form.tsx | 15 ++++++- src/components/toast-with-button.tsx | 46 ++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 src/components/toast-with-button.tsx diff --git a/src/components/forms/update-product-form.tsx b/src/components/forms/update-product-form.tsx index 1cfc4f833..3b19b152e 100644 --- a/src/components/forms/update-product-form.tsx +++ b/src/components/forms/update-product-form.tsx @@ -35,6 +35,7 @@ import { import { Textarea } from "@/components/ui/textarea" import { FileDialog } from "@/components/file-dialog" import { Icons } from "@/components/icons" +import { ToastWithButton } from "@/components/toast-with-button" import { checkProductAction, deleteProductAction, @@ -89,7 +90,7 @@ export function UpdateProductForm({ product }: UpdateProductFormProps) { const subcategories = getSubcategories(form.watch("category")) function onSubmit(data: Inputs) { - console.log(data) + // console.log(data) startTransition(async () => { try { @@ -119,7 +120,17 @@ export function UpdateProductForm({ product }: UpdateProductFormProps) { images: images ?? product.images, }) - toast.success("Product updated successfully.") + const handleToastAction = () => { + router.push(`/product/${product.storeId}`) + toast.dismiss(`update-product-success-${product.id}`) + } + + toast( + View, + { + id: `update-product-success-${product.id}`, + } + ) setFiles(null) } catch (error) { error instanceof Error diff --git a/src/components/toast-with-button.tsx b/src/components/toast-with-button.tsx new file mode 100644 index 000000000..6a0a3555d --- /dev/null +++ b/src/components/toast-with-button.tsx @@ -0,0 +1,46 @@ +import type { ButtonHTMLAttributes } from "react" + +import { Button } from "@/components/ui/button" + +export function ToastWithButton({ + children, + ...props +}: ButtonHTMLAttributes) { + return ( +
+
+ + Product updated successfully. +
+ +
+ ) +} + +export const SonnerSuccessIcon = () => { + return ( +
+ + + +
+ ) +}