diff --git a/app/page.tsx b/app/page.tsx index e577d7f..b4ac71d 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -5,7 +5,7 @@ import Link from 'next/link' import { motion } from 'framer-motion' import { useAuth } from '@/lib/auth/context' import { initiateOAuthFlow, initiateSignupFlow } from '@/lib/api/oauth' -import { listSites, listDeletedSites, restoreSite, permanentDeleteSite, type Site } from '@/lib/api/sites' +import { listSites, listDeletedSites, restoreSite, type Site } from '@/lib/api/sites' import { getStats } from '@/lib/api/stats' import type { Stats } from '@/lib/api/stats' import { getSubscription, type SubscriptionDetails } from '@/lib/api/billing' @@ -121,6 +121,7 @@ export default function HomePage() { const [showFinishSetupBanner, setShowFinishSetupBanner] = useState(true) const [deleteModalSite, setDeleteModalSite] = useState(null) const [deletedSites, setDeletedSites] = useState([]) + const [permanentDeleteSiteModal, setPermanentDeleteSiteModal] = useState(null) useEffect(() => { if (user?.org_id) { @@ -222,15 +223,9 @@ export default function HomePage() { } } - const handlePermanentDelete = async (id: string) => { - if (!confirm('Permanently delete this site and all data? This cannot be undone.')) return - try { - await permanentDeleteSite(id) - toast.success('Site permanently deleted') - loadSites() - } catch (error: unknown) { - toast.error(getAuthErrorMessage(error) || 'Failed to delete site') - } + const handlePermanentDelete = (id: string) => { + const site = deletedSites.find((s) => s.id === id) + if (site) setPermanentDeleteSiteModal(site) } if (authLoading) { @@ -550,6 +545,16 @@ export default function HomePage() { siteId={deleteModalSite?.id || ''} /> + setPermanentDeleteSiteModal(null)} + onDeleted={loadSites} + siteName={permanentDeleteSiteModal?.name || ''} + siteDomain={permanentDeleteSiteModal?.domain || ''} + siteId={permanentDeleteSiteModal?.id || ''} + permanentOnly + /> + {deletedSites.length > 0 && (

Scheduled for Deletion

diff --git a/components/sites/DeleteSiteModal.tsx b/components/sites/DeleteSiteModal.tsx index 5f01d26..b8f7bb7 100644 --- a/components/sites/DeleteSiteModal.tsx +++ b/components/sites/DeleteSiteModal.tsx @@ -1,11 +1,9 @@ 'use client' -import { useState } from 'react' +import { useState, useEffect } from 'react' import { createPortal } from 'react-dom' import { motion, AnimatePresence } from 'framer-motion' -import { toast } from '@ciphera-net/ui' -import { getAuthErrorMessage } from '@ciphera-net/ui' -import { AlertTriangleIcon, XIcon } from '@ciphera-net/ui' +import { toast, getAuthErrorMessage, AlertTriangleIcon, XIcon } from '@ciphera-net/ui' import { deleteSite, permanentDeleteSite } from '@/lib/api/sites' interface DeleteSiteModalProps { @@ -15,15 +13,22 @@ interface DeleteSiteModalProps { siteName: string siteDomain: string siteId: string + permanentOnly?: boolean } -export default function DeleteSiteModal({ open, onClose, onDeleted, siteName, siteDomain, siteId }: DeleteSiteModalProps) { +export default function DeleteSiteModal({ open, onClose, onDeleted, siteName, siteDomain, siteId, permanentOnly }: DeleteSiteModalProps) { const [deleteConfirm, setDeleteConfirm] = useState('') const [isDeleting, setIsDeleting] = useState(false) - const [showPermanent, setShowPermanent] = useState(false) + const [showPermanent, setShowPermanent] = useState(!!permanentOnly) const [permanentConfirm, setPermanentConfirm] = useState('') const [isPermanentDeleting, setIsPermanentDeleting] = useState(false) + useEffect(() => { + if (open && permanentOnly) { + setShowPermanent(true) + } + }, [open, permanentOnly]) + const handleClose = () => { setDeleteConfirm('') setShowPermanent(false) @@ -43,7 +48,6 @@ export default function DeleteSiteModal({ open, onClose, onDeleted, siteName, si onDeleted() } catch (error: unknown) { toast.error(getAuthErrorMessage(error) || 'Failed to delete site') - } finally { setIsDeleting(false) } } @@ -58,7 +62,6 @@ export default function DeleteSiteModal({ open, onClose, onDeleted, siteName, si onDeleted() } catch (error: unknown) { toast.error(getAuthErrorMessage(error) || 'Failed to permanently delete site') - } finally { setIsPermanentDeleting(false) } } @@ -193,13 +196,17 @@ export default function DeleteSiteModal({ open, onClose, onDeleted, siteName, si