'use client' import { useState, useEffect } from 'react' import { useRouter } from 'next/navigation' import { Input, Button, Select, toast, Spinner, getAuthErrorMessage, CheckIcon, ZapIcon } from '@ciphera-net/ui' import { useSite } from '@/lib/swr/dashboard' 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' import ScriptSetupBlock from '@/components/sites/ScriptSetupBlock' import VerificationModal from '@/components/sites/VerificationModal' const TIMEZONES = [ { value: 'UTC', label: 'UTC' }, { value: 'Europe/London', label: 'Europe/London (GMT)' }, { value: 'Europe/Brussels', label: 'Europe/Brussels (CET)' }, { value: 'Europe/Berlin', label: 'Europe/Berlin (CET)' }, { value: 'Europe/Paris', label: 'Europe/Paris (CET)' }, { value: 'Europe/Amsterdam', label: 'Europe/Amsterdam (CET)' }, { value: 'America/New_York', label: 'America/New York (EST)' }, { value: 'America/Chicago', label: 'America/Chicago (CST)' }, { value: 'America/Denver', label: 'America/Denver (MST)' }, { value: 'America/Los_Angeles', label: 'America/Los Angeles (PST)' }, { value: 'Asia/Tokyo', label: 'Asia/Tokyo (JST)' }, { value: 'Asia/Shanghai', label: 'Asia/Shanghai (CST)' }, { value: 'Asia/Kolkata', label: 'Asia/Kolkata (IST)' }, { value: 'Australia/Sydney', label: 'Australia/Sydney (AEST)' }, ] 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 [showDeleteModal, setShowDeleteModal] = useState(false) const [showVerificationModal, setShowVerificationModal] = useState(false) const canEdit = user?.role === 'owner' || user?.role === 'admin' useEffect(() => { if (site) { setName(site.name || '') setTimezone(site.timezone || 'UTC') } }, [site]) const handleSave = async () => { if (!site) return setSaving(true) try { await updateSite(siteId, { name, timezone }) await mutate() toast.success('Site updated') } catch { toast.error('Failed to save') } finally { setSaving(false) } } 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') } } if (!site) { return (
Update your site details and tracking script.
Domain cannot be changed after creation.
Add this to your website to start tracking visitors. Choose your framework for setup instructions.
{site.is_verified ? 'Your site is sending data correctly.' : 'Check if your site is sending data correctly.'}
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.