import { useState, useEffect } from "react" import { useNavigate, Link } from "react-router" import { Plus, Search } from "lucide-react" import { Navbar } from "@/components/shared/navbar" import { Footer } from "@/components/shared/footer" import { FormInput } from "@/components/shared/form-input" import { FormButton } from "@/components/shared/form-button" import { FormCard } from "@/components/forms/form-card" import { useAuth } from "@/app/context/auth-context" import { getForms } from "@/lib/api" import type { FormSummary } from "@/lib/types" export default function FormsPage() { const { user, loading } = useAuth() const navigate = useNavigate() const [search, setSearch] = useState("") const [forms, setForms] = useState([]) const [loadingForms, setLoadingForms] = useState(true) const [error, setError] = useState(null) useEffect(() => { if (!loading && !user) { navigate("/login") } }, [user, loading, navigate]) useEffect(() => { if (!user) return async function fetchForms() { try { const data = await getForms() setForms(data) } catch { setError("Failed to load forms. Please try again.") } finally { setLoadingForms(false) } } fetchForms() }, [user]) if (loading || loadingForms) { return (

Loading...

) } if (!user) return null const filtered = forms.filter((form) => { return ( form.title.toLowerCase().includes(search.toLowerCase()) || form.description.toLowerCase().includes(search.toLowerCase()) ) }) return (

My Forms

Manage and preview all your forms in one place

New Form
setSearch(e.target.value)} className="pl-9" />

Showing {filtered.length} of {forms.length} forms

{error ? (

{error}

window.location.reload()} > Retry
) : filtered.length > 0 ? (
{filtered.map((form) => ( ))}
) : (

No forms found matching your criteria.

setSearch("")} > Clear filters
)}
) }