Closed binfask closed 7 months ago
Hey @binfask, please share your code too Check this
the code from my cellAction component :
"use client"; import { AlertModal } from "@/components/modal/alert-modal"; import { Button } from "@/components/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Car } from "@/constants/data"; import { deleteCar } from "@/lib/actions/car.actions"; import { Edit, MoreHorizontal, Trash } from "lucide-react"; import { useRouter } from 'next/navigation'; import { useState } from "react"; import { useToast } from "../../ui/use-toast"; import { refreshcarpage } from "./refresh";
interface CellActionProps { data: Car; }
export const CellAction: React.FC
const handleNavigate = async () => { // Optional: Perform any actions before navigation await router.push('/admin/car'); };
const onConfirm = async () => { setLoading(true); try { await deleteCar(data._id); toast({ title: "Success", description: "Car deleted successfully", }); setOpen(false);
router.prefetch(`/admin/car`);
} catch (error) {
console.error("Error deleting car:", error);
toast({
title: "Error",
description: "Error deleting car",
});
} finally {
setLoading(false);
}
};
return ( <> <AlertModal isOpen={open} onClose={() => setOpen(false)} onConfirm={onConfirm} loading={loading} />
You need to revalidate the data or refetch it to obtain the latest updated data.
You need to revalidate the data or refetch it to obtain the latest updated data.
revalidatePath or router.refresh also works
in my case i deleted data from data base by calling API from onConfirm() but the data is not removing from data table