fix fix fi x fix
This commit is contained in:
@@ -2,6 +2,7 @@ import { useState, useEffect, useCallback } from 'react';
|
||||
import PageMeta from '../../components/common/PageMeta';
|
||||
import SiteCard from '../../components/common/SiteCard';
|
||||
import FormModal, { FormField } from '../../components/common/FormModal';
|
||||
import ConfirmDialog from '../../components/common/ConfirmDialog';
|
||||
import Button from '../../components/ui/button/Button';
|
||||
import { useToast } from '../../components/ui/toast/ToastContainer';
|
||||
import Alert from '../../components/ui/alert/Alert';
|
||||
@@ -39,6 +40,9 @@ export default function Sites() {
|
||||
const [showSiteModal, setShowSiteModal] = useState(false);
|
||||
const [showSectorsModal, setShowSectorsModal] = useState(false);
|
||||
const [showDetailsModal, setShowDetailsModal] = useState(false);
|
||||
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
|
||||
const [siteToDelete, setSiteToDelete] = useState<Site | null>(null);
|
||||
const [isDeleting, setIsDeleting] = useState(false);
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
const [togglingSiteId, setTogglingSiteId] = useState<number | null>(null);
|
||||
const [industries, setIndustries] = useState<Industry[]>([]);
|
||||
@@ -293,13 +297,17 @@ export default function Sites() {
|
||||
};
|
||||
|
||||
|
||||
const handleDeleteSite = async (site: Site) => {
|
||||
if (!window.confirm(`Are you sure you want to delete "${site.name}"? This action cannot be undone.`)) {
|
||||
return;
|
||||
}
|
||||
const handleDeleteSite = (site: Site) => {
|
||||
setSiteToDelete(site);
|
||||
setShowDeleteConfirm(true);
|
||||
};
|
||||
|
||||
const confirmDeleteSite = async () => {
|
||||
if (!siteToDelete) return;
|
||||
|
||||
setIsDeleting(true);
|
||||
try {
|
||||
await deleteSite(site.id);
|
||||
await deleteSite(siteToDelete.id);
|
||||
toast.success('Site deleted successfully');
|
||||
await loadSites();
|
||||
if (showDetailsModal) {
|
||||
@@ -307,6 +315,10 @@ export default function Sites() {
|
||||
}
|
||||
} catch (error: any) {
|
||||
toast.error(`Failed to delete site: ${error.message}`);
|
||||
} finally {
|
||||
setIsDeleting(false);
|
||||
setShowDeleteConfirm(false);
|
||||
setSiteToDelete(null);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -604,6 +616,22 @@ export default function Sites() {
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Delete Confirmation Dialog */}
|
||||
<ConfirmDialog
|
||||
isOpen={showDeleteConfirm}
|
||||
onClose={() => {
|
||||
setShowDeleteConfirm(false);
|
||||
setSiteToDelete(null);
|
||||
}}
|
||||
onConfirm={confirmDeleteSite}
|
||||
title="Delete Site"
|
||||
message={`Are you sure you want to delete "${siteToDelete?.name}"? This action cannot be undone.`}
|
||||
confirmText="Delete"
|
||||
cancelText="Cancel"
|
||||
variant="danger"
|
||||
isLoading={isDeleting}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user