Spaces:
Sleeping
Sleeping
import { DatePicker } from '@/components/DatePicker'; | |
import Loading from '@/components/ui/Loading'; | |
import { isValidDate } from '@/lib/utils'; | |
import { format } from 'date-fns'; | |
import { redirect } from 'next/navigation'; | |
import { Suspense } from 'react'; | |
import InternalServer from './server'; | |
import { sessionUser } from '@/auth'; | |
export interface pageProps { | |
searchParams?: { [key: string]: string | string[] | undefined }; | |
} | |
export default async function page({ searchParams }: pageProps) { | |
const { isAdmin } = await sessionUser(); | |
if (!isAdmin) { | |
redirect('/'); | |
} | |
const date = searchParams?.date as string; | |
if (!date || !isValidDate(date)) { | |
const today = new Date(); | |
// default to today | |
redirect(`/internal?date=${format(today, 'yyyy-MM-dd')}`); | |
} | |
return ( | |
<Suspense | |
fallback={ | |
<div className="h-screen w-screen flex justify-center items-center"> | |
<Loading /> | |
</div> | |
} | |
> | |
<div className="w-[1600px] max-w-full mx-auto flex flex-col space-y-4 items-center"> | |
<DatePicker | |
date={date} | |
setDate={async newDate => { | |
'use server'; | |
redirect(`/internal?date=${newDate}`); | |
}} | |
/> | |
<InternalServer date={date} /> | |
</div> | |
</Suspense> | |
); | |
} | |