import { prisma } from '@ketopath/db'; import Link from 'next/link'; import { redirect } from 'next/navigation'; import { useTranslations } from 'next-intl'; import { setRequestLocale } from 'next-intl/server'; import { Masthead } from '@/components/masthead'; import { Button } from '@/components/ui/button'; import { getServerSession } from '@/lib/auth'; import { fetchCurrentPlan, regeneratePlan } from './actions'; import { PlanWeek } from './plan-week'; export default async function PlanPage({ params: { locale } }: { params: { locale: string } }) { setRequestLocale(locale); const session = await getServerSession(); if (!session?.user) redirect('/sign-in'); const user = await prisma.user.findUnique({ where: { id: session.user.id }, select: { disclaimerAcceptedAt: true, profile: { select: { id: true } } }, }); if (!user?.disclaimerAcceptedAt) redirect('/welcome'); if (!user.profile) redirect('/profile'); const plan = await fetchCurrentPlan(); return ; } const ITALIAN_DATE = new Intl.DateTimeFormat('it-IT', { day: 'numeric', month: 'long', year: 'numeric', }); function formatWeek(weekStart: string): string { const start = new Date(`${weekStart}T00:00:00`); const end = new Date(start); end.setDate(end.getDate() + 6); const startStr = new Intl.DateTimeFormat('it-IT', { day: 'numeric', month: 'long' }).format( start, ); const endStr = ITALIAN_DATE.format(end); return `${startStr} – ${endStr}`; } function PlanPageContent({ plan }: { plan: Awaited> }) { const t = useTranslations('Plan'); return ( Capitolo V {t('title')} . {plan ? formatWeek(plan.weekStart) : t('noPlan')} {plan ? t('regenerate') : t('generate')} {plan ? ( Lista della spesa → ) : null} {plan ? ( ) : null} ); }
Capitolo V
{plan ? formatWeek(plan.weekStart) : t('noPlan')}