import React, { useState } from "react"; import { useDeleteFarmMutation } from "../../../store/api/farmApi"; const EditFarm = ({ _id, onDelete }) => { const [modalOpen, setModalOpen] = useState(false); const [deleteFarm] = useDeleteFarmMutation(); // This function will run when the "Yes, I'm sure" button is clicked. const handleDeleteFarm = async () => { try { const res = await deleteFarm(_id); // const response = await fetch(`http://localhost:8000/api/v1/farm/${_id}`, { // method: "DELETE", // credentials: "include", // }); // const data = await response.json(); if (!res) { return null; } setModalOpen(false); // Close the modal after the operation } catch (error) { console.error("Error deleting farm:", error); } }; return ( <> {modalOpen && ( )} ); }; export default EditFarm;