import { createFileRoute, Link } from "@tanstack/react-router" import { useState } from "react" import { useTranslation } from "react-i18next" import { ChevronDown, ChevronRight, Plus, Settings, Sparkles } from "lucide-react" import { Button } from "@/components/ui/button" import { ProfileView, ProfileSkeleton } from "@/components/profile-view" import { useAuth } from "@/components/auth-provider" import { useWrapUps } from "@/hooks/use-wrapup" import { useUserProfile } from "@/hooks/use-users" import { useDeleteGoal } from "@/hooks/use-goals" import { GoalCard } from "@/components/goal-card" import { GoalSheet } from "@/components/goal-sheet" import { toast } from "sonner" import { useDocumentTitle } from "@/hooks/use-document-title" import type { GoalDto } from "@/lib/api/users" export const Route = createFileRoute("/_app/profile")({ component: ProfilePage, }) function ProfilePage() { const { t } = useTranslation() const { auth } = useAuth() useDocumentTitle(t("profile.title")) const { data, isPending } = useUserProfile(auth?.user_id ?? "", { view: "trends", }) const [search, setSearch] = useState("") if (!auth) return null if (isPending) return if (!data) return null return (

{t("profile.title")}

} />
) } function GoalSection({ goals }: { goals: GoalDto[] }) { const { t } = useTranslation() const [sheetOpen, setSheetOpen] = useState(false) const [editGoal, setEditGoal] = useState(null) const deleteMutation = useDeleteGoal() function handleEdit(goal: GoalDto) { setEditGoal(goal) setSheetOpen(true) } function handleDelete(year: number) { deleteMutation.mutate(year, { onSuccess: () => toast.success(t("goals.deleted")), }) } function handleSheetClose(open: boolean) { setSheetOpen(open) if (!open) setEditGoal(null) } return (
{goals.map((g) => ( handleEdit(g)} onDelete={() => handleDelete(g.year)} /> ))}
) } function wrapupYear(startDate: string): string { return startDate.slice(0, 4) } function WrapUpLinks() { const { t } = useTranslation() const { data } = useWrapUps() const ready = (data?.items?.filter((w) => w.status === "Ready") ?? []) .sort((a, b) => b.start_date.localeCompare(a.start_date)) const [expanded, setExpanded] = useState(false) if (!ready.length) return null if (ready.length === 1) { return ( ) } return (
{expanded && ready.map((w) => ( ))}
) }