File size: 1,306 Bytes
1006c22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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>
  );
}