fix: improve code quality in soft-delete frontend (loading state, imports, confirm dialog)
This commit is contained in:
25
app/page.tsx
25
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<Site | null>(null)
|
||||
const [deletedSites, setDeletedSites] = useState<Site[]>([])
|
||||
const [permanentDeleteSiteModal, setPermanentDeleteSiteModal] = useState<Site | null>(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 || ''}
|
||||
/>
|
||||
|
||||
<DeleteSiteModal
|
||||
open={!!permanentDeleteSiteModal}
|
||||
onClose={() => setPermanentDeleteSiteModal(null)}
|
||||
onDeleted={loadSites}
|
||||
siteName={permanentDeleteSiteModal?.name || ''}
|
||||
siteDomain={permanentDeleteSiteModal?.domain || ''}
|
||||
siteId={permanentDeleteSiteModal?.id || ''}
|
||||
permanentOnly
|
||||
/>
|
||||
|
||||
{deletedSites.length > 0 && (
|
||||
<div className="mt-8">
|
||||
<h3 className="text-sm font-medium text-neutral-500 dark:text-neutral-400 mb-4">Scheduled for Deletion</h3>
|
||||
|
||||
Reference in New Issue
Block a user