'use client' import { useCallback, useEffect, useState } from 'react' import { useParams, useRouter } from 'next/navigation' import { listFunnels, deleteFunnel, type Funnel } from '@/lib/api/funnels' import { toast, PlusIcon, ArrowRightIcon, ChevronLeftIcon, TrashIcon, Button } from '@ciphera-net/ui' import { FunnelsListSkeleton, useMinimumLoading } from '@/components/skeletons' import Link from 'next/link' export default function FunnelsPage() { const params = useParams() const router = useRouter() const siteId = params.id as string const [funnels, setFunnels] = useState([]) const [loading, setLoading] = useState(true) const loadFunnels = useCallback(async () => { try { setLoading(true) const data = await listFunnels(siteId) setFunnels(data) } catch (error) { toast.error('Failed to load your funnels') } finally { setLoading(false) } }, [siteId]) useEffect(() => { loadFunnels() }, [loadFunnels]) const handleDelete = async (e: React.MouseEvent, funnelId: string) => { e.preventDefault() // Prevent navigation if (!confirm('Are you sure you want to delete this funnel?')) return try { await deleteFunnel(siteId, funnelId) toast.success('Funnel deleted') loadFunnels() } catch (error) { toast.error('Failed to delete funnel') } } const showSkeleton = useMinimumLoading(loading) if (showSkeleton) { return } return (

Funnels

Track user journeys and identify drop-off points

{funnels.length === 0 ? (

No funnels yet

Create a funnel to track how users move through your site and where they drop off.

) : (
{funnels.map((funnel) => (

{funnel.name}

{funnel.description && (

{funnel.description}

)}
{funnel.steps.map((step, i) => (
{step.name} {i < funnel.steps.length - 1 && ( )}
))}
))}
)}
) }