From 34ebb5d622b6a15fa96aa5b2553d021bc7b86e2f Mon Sep 17 00:00:00 2001 From: Malini Date: Fri, 6 Feb 2026 07:59:38 +0530 Subject: [PATCH] added popup for delete --- .../dashboard/SubmissionHistory.jsx | 67 ++++++-- .../src/pages/Overview/Overview.jsx | 144 +++++++++++++----- 2 files changed, 165 insertions(+), 46 deletions(-) diff --git a/ipi-survey-platform/src/components/dashboard/SubmissionHistory.jsx b/ipi-survey-platform/src/components/dashboard/SubmissionHistory.jsx index 2dcaecd..7ccd52b 100644 --- a/ipi-survey-platform/src/components/dashboard/SubmissionHistory.jsx +++ b/ipi-survey-platform/src/components/dashboard/SubmissionHistory.jsx @@ -1,11 +1,13 @@ -import React from 'react'; +// import React from 'react'; import { useNavigate } from 'react-router-dom'; +import React, { useState } from 'react'; import Table from '@/components/common/Table'; import Footer from '../common/Footer'; import HeaderBar from '@/components/layout/HeaderBar'; import DetailedOverview from '@/components/overview/DetailedOverview'; import { deleteDraftSubmission } from '@/services/submissions/submissionService'; import { HiMiniArrowPathRoundedSquare } from "react-icons/hi2"; +import CustomToast from '@/components/common/CustomToast'; const searchIconSrc = '/assets/images/material-symbols_search-rounded.svg'; const pencilIconSrc = '/assets/images/PencilSimple.svg'; @@ -145,7 +147,8 @@ export const SubmissionHistory = ({ history = [], loading = false, error = '' }) const [currentPage, setCurrentPage] = React.useState(1); const [hoveredDelete, setHoveredDelete] = React.useState(null); const [toast, setToast] = React.useState({ show: false, message: '', type: 'success' }); - + const [showDeleteConfirm, setShowDeleteConfirm] = useState(false); + const [draftToDelete, setDraftToDelete] = useState(null); const showToast = (message, type = 'success') => { setToast({ show: true, message, type }); setTimeout(() => { @@ -180,6 +183,12 @@ export const SubmissionHistory = ({ history = [], loading = false, error = '' }) } }; +const handleDeleteClick = (e, item) => { + e.stopPropagation(); + setDraftToDelete(item); + setShowDeleteConfirm(true); +}; + const handleDeleteDraft = async (e, submission) => { e.preventDefault(); e.stopPropagation(); @@ -188,19 +197,20 @@ const handleDeleteDraft = async (e, submission) => { throw new Error('No submission ID provided'); } - if (!window.confirm('Are you sure you want to delete this draft?')) { - return; - } - await deleteDraftSubmission(submission.id); - showToast('Draft deleted successfully', 'success'); - + showToast('Draft deleted successfully', 'error'); + + // Close the confirmation modal + setShowDeleteConfirm(false); + setDraftToDelete(null); // Optionally reload the page or refresh data + setTimeout(() => { window.location.reload(); + }, 1000); } catch (error) { console.error('Error deleting submission:', error); - alert(error.message || 'Failed to delete draft'); + showToast(error.message || 'Failed to delete draft', 'error'); } }; @@ -270,8 +280,11 @@ const handleDeleteDraft = async (e, submission) => { className="h-5 w-5 opacity-60 hover:opacity-100 transition-opacity" /> - + + + + + +)}