refactor(frontend): replace confirm() with modern confirmation modals
Replaced all confirm() dialogs with reusable ConfirmationModal component for better UX. Modal dialogs provide clearer context, visual consistency, and prevent accidental confirmations. Changes: - MatchesPage: Reject match request confirmation modal - DashboardPage: Decline and cancel request confirmation modals - ContactMessagesPage: Delete message confirmation modal All modals support loading states during async operations and provide clear action descriptions with destructive action styling.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import toast from 'react-hot-toast';
|
||||
import { Mail, User, Calendar, Trash2, Check, Eye, AlertCircle, Loader2, Filter } from 'lucide-react';
|
||||
import Layout from '../../components/layout/Layout';
|
||||
import ConfirmationModal from '../../components/modals/ConfirmationModal';
|
||||
|
||||
// This would normally come from an admin API module, but for now we'll add it inline
|
||||
const adminContactAPI = {
|
||||
@@ -73,6 +75,8 @@ export default function ContactMessagesPage() {
|
||||
const [total, setTotal] = useState(0);
|
||||
const [statusFilter, setStatusFilter] = useState('all');
|
||||
const [selectedMessage, setSelectedMessage] = useState(null);
|
||||
const [showDeleteModal, setShowDeleteModal] = useState(false);
|
||||
const [messageToDelete, setMessageToDelete] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const userData = localStorage.getItem('user');
|
||||
@@ -115,19 +119,27 @@ export default function ContactMessagesPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = async (id) => {
|
||||
if (!confirm('Are you sure you want to delete this message?')) {
|
||||
return;
|
||||
}
|
||||
const handleDelete = (id) => {
|
||||
setMessageToDelete(id);
|
||||
setShowDeleteModal(true);
|
||||
};
|
||||
|
||||
const confirmDelete = async () => {
|
||||
if (!messageToDelete) return;
|
||||
|
||||
try {
|
||||
await adminContactAPI.deleteMessage(id);
|
||||
await adminContactAPI.deleteMessage(messageToDelete);
|
||||
await fetchMessages();
|
||||
if (selectedMessage?.id === id) {
|
||||
if (selectedMessage?.id === messageToDelete) {
|
||||
setSelectedMessage(null);
|
||||
}
|
||||
toast.success('Message deleted successfully');
|
||||
} catch (error) {
|
||||
console.error('Failed to delete message:', error);
|
||||
toast.error('Failed to delete message. Please try again.');
|
||||
} finally {
|
||||
setShowDeleteModal(false);
|
||||
setMessageToDelete(null);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -343,6 +355,20 @@ export default function ContactMessagesPage() {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Delete Confirmation Modal */}
|
||||
<ConfirmationModal
|
||||
isOpen={showDeleteModal}
|
||||
onClose={() => {
|
||||
setShowDeleteModal(false);
|
||||
setMessageToDelete(null);
|
||||
}}
|
||||
onConfirm={confirmDelete}
|
||||
title="Delete Message"
|
||||
message="Are you sure you want to delete this contact message? This action cannot be undone."
|
||||
confirmText="Delete"
|
||||
cancelText="Cancel"
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user