'use client' import { useState, useEffect } from 'react' import { Button, Input, Toggle, toast, Spinner } from '@ciphera-net/ui' import { Copy, CheckCircle, Lock } from '@phosphor-icons/react' import { AnimatePresence, motion } from 'framer-motion' import { useSite } from '@/lib/swr/dashboard' import { updateSite } from '@/lib/api/sites' const APP_URL = process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:3003' export default function SiteVisibilityTab({ siteId }: { siteId: string }) { const { data: site, mutate } = useSite(siteId) const [isPublic, setIsPublic] = useState(false) const [password, setPassword] = useState('') const [passwordEnabled, setPasswordEnabled] = useState(false) const [saving, setSaving] = useState(false) const [linkCopied, setLinkCopied] = useState(false) useEffect(() => { if (site) { setIsPublic(site.is_public ?? false) setPasswordEnabled(site.has_password ?? false) } }, [site]) const handleSave = async () => { setSaving(true) try { await updateSite(siteId, { name: site?.name || '', is_public: isPublic, password: passwordEnabled ? password : undefined, clear_password: !passwordEnabled, }) setPassword('') await mutate() toast.success('Visibility updated') } catch { toast.error('Failed to save') } finally { setSaving(false) } } const copyLink = () => { navigator.clipboard.writeText(`${APP_URL}/share/${siteId}`) setLinkCopied(true) toast.success('Link copied') setTimeout(() => setLinkCopied(false), 2000) } if (!site) return
Control who can see your analytics dashboard.
Public Dashboard
Allow anyone with the link to view this dashboard.
Password Protection
Require a password to view the public dashboard.