diff --git a/components/settings/unified/tabs/SiteGeneralTab.tsx b/components/settings/unified/tabs/SiteGeneralTab.tsx index b6c0e9e..d88c245 100644 --- a/components/settings/unified/tabs/SiteGeneralTab.tsx +++ b/components/settings/unified/tabs/SiteGeneralTab.tsx @@ -1,10 +1,14 @@ 'use client' import { useState, useEffect } from 'react' -import { Input, Button, Select, toast, Spinner } from '@ciphera-net/ui' +import { useRouter } from 'next/navigation' +import { Input, Button, Select, toast, Spinner, getAuthErrorMessage } from '@ciphera-net/ui' import { Copy, CheckCircle } from '@phosphor-icons/react' import { useSite } from '@/lib/swr/dashboard' -import { updateSite } from '@/lib/api/sites' +import { updateSite, resetSiteData } from '@/lib/api/sites' +import { useAuth } from '@/lib/auth/context' +import { useUnifiedSettings } from '@/lib/unified-settings-context' +import DeleteSiteModal from '@/components/sites/DeleteSiteModal' const TIMEZONES = [ { value: 'UTC', label: 'UTC' }, @@ -27,11 +31,17 @@ const API_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8082' const APP_URL = process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:3003' export default function SiteGeneralTab({ siteId }: { siteId: string }) { + const router = useRouter() + const { user } = useAuth() + const { closeUnifiedSettings: closeSettings } = useUnifiedSettings() const { data: site, mutate } = useSite(siteId) const [name, setName] = useState('') const [timezone, setTimezone] = useState('UTC') const [saving, setSaving] = useState(false) const [copied, setCopied] = useState(false) + const [showDeleteModal, setShowDeleteModal] = useState(false) + + const canEdit = user?.role === 'owner' || user?.role === 'admin' useEffect(() => { if (site) { @@ -54,6 +64,16 @@ export default function SiteGeneralTab({ siteId }: { siteId: string }) { } } + const handleResetData = async () => { + if (!confirm('Are you sure you want to delete ALL data for this site? This action cannot be undone.')) return + try { + await resetSiteData(siteId) + toast.success('All site data has been reset') + } catch (error: unknown) { + toast.error(getAuthErrorMessage(error) || 'Failed to reset site data') + } + } + const trackingScript = `` const frustrationScript = `` @@ -132,6 +152,57 @@ export default function SiteGeneralTab({ siteId }: { siteId: string }) { {saving ? 'Saving...' : 'Save Changes'} + + {/* Danger Zone */} + {canEdit && ( +
+
+

Danger Zone

+

Irreversible actions for your site.

+
+ +
+
+
+

Reset Data

+

Delete all stats and events. This cannot be undone.

+
+ +
+
+ +
+
+
+

Delete Site

+

Schedule this site for deletion with a 7-day grace period.

+
+ +
+
+
+ )} + + setShowDeleteModal(false)} + onDeleted={() => { router.push('/'); closeSettings(); }} + siteName={site?.name || ''} + siteDomain={site?.domain || ''} + siteId={siteId} + /> ) }