Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

3.0 KB
Raw Blame
import { dehydrate, HydrationBoundary } from "@tanstack/react-query";
import type { Metadata } from "next";
import { notFound } from "next/navigation";
import {
  PageSection,
  PageSectionContent,
  PageSectionDescription,
  PageSectionDivider,
  PageSectionHeader,
  PageSectionTitle,
} from "@/components/page-layout";
import {
  SettingsPage,
  SettingsPageAction,
  SettingsPageContent,
  SettingsPageDescription,
  SettingsPageHeader,
  SettingsPageTitle,
} from "@/components/settings-layout";
import { Trans } from "@/i18n/client";
import { getTranslation } from "@/i18n/server";
import { isFeatureEnabled } from "@/lib/feature-flags/server";
import { createPrivateSSRHelper } from "@/trpc/server/create-ssr-helper";
import { CalendarConnectionFlash } from "./components/calendar-connection-flash";
import { CalendarConnectionList } from "./components/calendar-connection-list";
import { ConnectCalendarDropdown } from "./components/connect-calendar-dropdown";
import { DefaultCalendarSelect } from "./components/default-calendar-select";

export default async function CalendarsPage() {
  const isCalendarsEnabled = isFeatureEnabled("calendars");

  if (!isCalendarsEnabled) {
    notFound();
  }

  const trpc = await createPrivateSSRHelper();

  await Promise.all([
    trpc.calendars.list.prefetch(),
    trpc.calendars.getDefault.prefetch(),
  ]);

  return (
    <HydrationBoundary state={dehydrate(trpc.queryClient)}>
      <SettingsPage>
        <CalendarConnectionFlash />
        <SettingsPageHeader>
          <SettingsPageTitle>
            <Trans i18nKey="calendars" defaults="Calendars" />
          </SettingsPageTitle>
          <SettingsPageDescription>
            <Trans
              i18nKey="calendarsDescription"
              defaults="Manage your calendar connections"
            />
          </SettingsPageDescription>
          <SettingsPageAction>
            <ConnectCalendarDropdown />
          </SettingsPageAction>
        </SettingsPageHeader>
        <SettingsPageContent>
          <PageSection variant="card">
            <PageSectionHeader>
              <PageSectionTitle>
                <Trans i18nKey="defaultCalendar" defaults="Default calendar" />
              </PageSectionTitle>
              <PageSectionDescription>
                <Trans
                  i18nKey="defaultCalendarDescription"
                  defaults="Select the calendar that we should create events in"
                />
              </PageSectionDescription>
            </PageSectionHeader>
            <PageSectionContent>
              <DefaultCalendarSelect />
            </PageSectionContent>
          </PageSection>
          <PageSectionDivider />
          <CalendarConnectionList />
        </SettingsPageContent>
      </SettingsPage>
    </HydrationBoundary>
  );
}

export async function generateMetadata(): Promise<Metadata> {
  const { t } = await getTranslation();
  return {
    title: t("calendars", "Calendars"),
    description: t("calendarsDescription", "Manage your calendar connections"),
  };
}