diff --git a/frontend/src/components/PollTableRow/PollTableRow.jsx b/frontend/src/components/PollTableRow/PollTableRow.jsx index 06c24a0..3898817 100644 --- a/frontend/src/components/PollTableRow/PollTableRow.jsx +++ b/frontend/src/components/PollTableRow/PollTableRow.jsx @@ -1,24 +1,33 @@ -// PollTableRow.js import React, { useState } from "react"; import { FaTrashAlt, FaUserEdit } from "react-icons/fa"; +import {useMutation} from "react-query" +import deletePollService from "../../services/deletePollService"; +import { toast } from "react-toastify"; function PollTableRow({ poll, index, refetch }) { - const [showEditForm, setShowEditForm] = useState(false); + + + const mutation = useMutation(deletePollService, { + onSuccess : (data) => { + console.log(data); + refetch(); + toast.success(data?.message); + }, + onError : (error) => { + toast.error("An unexpected error occurred"); + console.log(error); + } + }) const handleDelete = () => { const sure = window.confirm("Are you sure you want to delete this poll?"); - if (sure) { - console.log(`Poll with ID: ${poll._id} has been deleted.`); - } + if (!sure) return; + mutation.mutate(poll._id); }; return ( <> - {showEditForm && ( -