import { useState } from 'react' import { useRouter } from "next/router"; import axiosInstance from '../../src/axiosSecure'; import { TrashIcon } from "@heroicons/react/24/outline"; export default function LocationCard({ location }) { const router = useRouter(); const [isCardVisible, setIsCardVisible] = useState(true); const handleDelete = async (id) => { try { console.log("card: deleting location = ", id, "url: ", `/locations/${id}`); const response = await axiosInstance.delete(`/api/data/locations/${id}`); if (response.status === 200) { document.getElementById(`location-card-${id}`).classList.add('cardFadeOut'); setTimeout(() => setIsCardVisible(false), 300); } } catch (error) { console.log(JSON.stringify(error)); } }; return isCardVisible ? ( <>
router.push(`/cart/locations/edit/${location.id}`)} >
{location.name} ({location.isactive ? "active" : "inactive"})

{location.address}

{ e.stopPropagation(); // This should now work as expected handleDelete(location.id); }} className="absolute bottom-2 right-2 z-20" >
) : null; }