Added delete functionality 🚮

This commit is contained in:
Manik Maity
2024-11-10 15:48:41 +05:30
parent 439ba997ab
commit 1f7b71e004
2 changed files with 26 additions and 10 deletions

View File

@@ -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 && (
<div className="fixed inset-0 bg-gray-800 bg-opacity-75 flex items-center justify-center z-50">
{/* Poll Edit Form Component would go here */}
</div>
)}
<tr>
<th>{index + 1}</th>
<td className="text-white">{poll.title}</td>

View File

@@ -0,0 +1,7 @@
import axiosInstance from "../helper/axiosInstance.js"
async function deletePollService(pollId) {
const response = await axiosInstance.delete(`/poll/delete/${pollId}`);
return response.data;
}
export default deletePollService