From 9c127db94faaf1057d564a47c52e612c8c6c8f41 Mon Sep 17 00:00:00 2001 From: Shivansh Date: Sat, 26 Oct 2024 18:15:31 +0530 Subject: [PATCH] deletion is not functional --- actions/wishlist-actions.tsx | 23 +++++++++++++++++++ .../WishList/components/wishlistItem.tsx | 20 +++++++++++++--- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/actions/wishlist-actions.tsx b/actions/wishlist-actions.tsx index 0d490bc..b0a09be 100644 --- a/actions/wishlist-actions.tsx +++ b/actions/wishlist-actions.tsx @@ -63,7 +63,30 @@ export async function WishlistGetByUser( } } +export async function WishlistDeleteProduct( + Id: string, +): Promise<{ success: boolean; error?: string }> { + + // console.log(Id); + try { + const res = await prismadb.wishlist.deleteMany({ + where: { + id:Id + }, + }); + if(res.count==0){ + return {success:false, error:"item does not exist on the wishlist"} + } + console.log(res); + // console.log(res) + return { success: true}; // Include success and return the data + } catch (err) { + // console.log(err); + + return { success: false, error: "An unexpected error occurred while deleting" }; + } +} export async function WishlistSpecificEntry( userId:string diff --git a/app/(Customer)/WishList/components/wishlistItem.tsx b/app/(Customer)/WishList/components/wishlistItem.tsx index 75615fb..bd4a451 100644 --- a/app/(Customer)/WishList/components/wishlistItem.tsx +++ b/app/(Customer)/WishList/components/wishlistItem.tsx @@ -1,6 +1,8 @@ import { Button } from "@/components/ui/button"; import Image from "next/image"; import { productWithImages } from "../page"; +import { WishlistDeleteProduct } from "@/actions/wishlist-actions"; +import toast from "react-hot-toast"; interface wishlistItemProps{ item:productWithImages @@ -8,9 +10,21 @@ interface wishlistItemProps{ onRemove: (id: string) => void; } // WishlistItem.js -const WishlistItem:React.FC = ({ item, }) => { +const WishlistItem:React.FC = ({ item,onRemove,Id }) => { - + const onDelete=async()=>{ + + const res=await WishlistDeleteProduct(Id); + + if(res.success){ + toast.success("removed from wishlist"); + onRemove(Id); + } + else{ + toast.error(res.error||"error occured"); + } + + } // console.log(item); return (
@@ -18,7 +32,7 @@ const WishlistItem:React.FC = ({ item, }) => {

{item.name}

₹{item.price}

- +