Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
♻️ Use stale times and csr (#2215)
Luke Vella0e886ee77009
diff --git a/apps/web/next.config.ts b/apps/web/next.config.tsindex a268460a1..3d169168b 100644--- a/apps/web/next.config.ts+++ b/apps/web/next.config.ts@@ -12,6 +12,11 @@ const withBundleAnalyzer = createBundleAnalyzer({});const nextConfig: NextConfig = {+ experimental: {+ staleTimes: {+ dynamic: 60,+ },+ },output:process.env.NEXT_PUBLIC_SELF_HOSTED === "true" ? "standalone" : undefined,productionBrowserSourceMaps: true,diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/events/events-page.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/events/events-page.tsxnew file mode 100644index 000000000..b02d7bbc6--- /dev/null+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/events/events-page.tsx@@ -0,0 +1,143 @@+"use client";++import { CalendarIcon } from "lucide-react";+import dynamic from "next/dynamic";+import { useSearchParams } from "next/navigation";+import type React from "react";+import {+ PageContainer,+ PageContent,+ PageHeader,+ PageSkeleton,+ PageTitle,+} from "@/app/components/page-layout";+import { SearchInput } from "@/app/components/search-input";+import {+ EmptyState,+ EmptyStateDescription,+ EmptyStateIcon,+ EmptyStateTitle,+} from "@/components/empty-state";+import { MemberSelector } from "@/components/member-selector";+import type { Status } from "@/features/scheduled-event/schema";+import { Trans, useTranslation } from "@/i18n/client";+import { trpc } from "@/trpc/client";+import { EventsInfiniteList } from "./events-infinite-list";+import { EventsTabbedView } from "./events-tabbed-view";+import { eventsSearchParamsSchema } from "./schema";++function EventsEmptyState({ status }: { status: Status }) {+ const contentByStatus: Record<+ Status,+ { title: React.ReactNode; description: React.ReactNode }+ > = {+ upcoming: {+ title: (+ <Trans+ i18nKey="upcomingEventsEmptyStateTitle"+ defaults="No Upcoming Events"+ />+ ),+ description: (+ <Trans+ i18nKey="upcomingEventsEmptyStateDescription"+ defaults="When you schedule events, they will appear here."+ />+ ),+ },+ past: {+ title: (+ <Trans i18nKey="pastEventsEmptyStateTitle" defaults="No Past Events" />+ ),+ description: (+ <Trans+ i18nKey="pastEventsEmptyStateDescription"+ defaults="Past events will show up here."+ />+ ),+ },+ unconfirmed: {+ title: (+ <Trans+ i18nKey="unconfirmedEventsEmptyStateTitle"+ defaults="No Unconfirmed Events"+ />+ ),+ description: (+ <Trans+ i18nKey="unconfirmedEventsEmptyStateDescription"+ defaults="Unconfirmed events will show up here."+ />+ ),+ },+ canceled: {+ title: (+ <Trans+ i18nKey="canceledEventsEmptyStateTitle"+ defaults="No Canceled Events"+ />+ ),+ description: (+ <Trans+ i18nKey="canceledEventsEmptyStateDescription"+ defaults="Canceled events will show up here."+ />+ ),+ },+ };++ const { title, description } = contentByStatus[status];++ return (+ <EmptyState className="h-96">+ <EmptyStateIcon>+ <CalendarIcon />+ </EmptyStateIcon>+ <EmptyStateTitle>{title}</EmptyStateTitle>+ <EmptyStateDescription>{description}</EmptyStateDescription>+ </EmptyState>+ );+}++function EventsPageContent() {+ const searchParams = useSearchParams();+ const { t } = useTranslation();+ const [members] = trpc.space.members.useSuspenseQuery();++ const { status, q, member } = eventsSearchParamsSchema.parse(+ Object.fromEntries(searchParams.entries()),+ );++ return (+ <PageContainer>+ <PageHeader>+ <PageTitle>+ <Trans i18nKey="events" defaults="Events" />+ </PageTitle>+ </PageHeader>+ <PageContent>+ <EventsTabbedView>+ <div className="mb-4 flex gap-x-2">+ <SearchInput+ placeholder={t("searchEventsPlaceholder", {+ defaultValue: "Search events by title...",+ })}+ />+ <MemberSelector members={members} />+ </div>+ <EventsInfiniteList+ status={status}+ search={q}+ member={member}+ emptyState={<EventsEmptyState status={status || "upcoming"} />}+ />+ </EventsTabbedView>+ </PageContent>+ </PageContainer>+ );+}++export const EventsPage = dynamic(() => Promise.resolve(EventsPageContent), {+ ssr: false,+ loading: () => <PageSkeleton />,+});diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/events/page.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/events/page.tsxindex 3dd781abf..8877703a0 100644--- a/apps/web/src/app/[locale]/(space)/(dashboard)/events/page.tsx+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/events/page.tsx@@ -1,152 +1,30 @@import { dehydrate, HydrationBoundary } from "@tanstack/react-query";-import { CalendarIcon } from "lucide-react";import type { Metadata } from "next";-import type { Params } from "@/app/[locale]/types";-import {- PageContainer,- PageContent,- PageHeader,- PageTitle,-} from "@/app/components/page-layout";-import { SearchInput } from "@/app/components/search-input";-import {- EmptyState,- EmptyStateDescription,- EmptyStateIcon,- EmptyStateTitle,-} from "@/components/empty-state";-import type { Status } from "@/features/scheduled-event/schema";-import { loadMembers } from "@/features/space/data";-import { Trans } from "@/i18n/client";import { getTranslation } from "@/i18n/server";import { createAuthenticatedSSRHelper } from "@/trpc/server/create-ssr-helper";-import { MemberSelector } from "../../../../../components/member-selector";-import { EventsInfiniteList } from "./events-infinite-list";-import { EventsTabbedView } from "./events-tabbed-view";+import { EventsPage } from "./events-page";import { eventsSearchParamsSchema } from "./schema";-async function loadData({- status,- search,- member,-}: {- status?: Status;- search?: string;- member?: string;+export default async function Page(props: {+ searchParams?: Promise<{ [key: string]: string | string[] | undefined }>;}) {+ const searchParams = await props.searchParams;+ const { status, q, member } = eventsSearchParamsSchema.parse(searchParams);+const helpers = await createAuthenticatedSSRHelper();- const [members] = await Promise.all([- loadMembers(),- // Prefetch the first page of events in parallel+ await Promise.all([+ helpers.space.members.prefetch(),helpers.events.infiniteList.prefetchInfinite({status,- search,+ search: q,member,}),]);- return {- members,- dehydratedState: dehydrate(helpers.queryClient),- };-}--async function ScheduledEventEmptyState({ status }: { status: Status }) {- const { t } = await getTranslation();- const contentByStatus = {- upcoming: {- title: t("upcomingEventsEmptyStateTitle", {- defaultValue: "No Upcoming Events",- }),- description: t("upcomingEventsEmptyStateDescription", {- defaultValue: "When you schedule events, they will appear here.",- }),- },- past: {- title: t("pastEventsEmptyStateTitle", {- defaultValue: "No Past Events",- }),- description: t("pastEventsEmptyStateDescription", {- defaultValue: "Past events will show up here.",- }),- },- unconfirmed: {- title: t("unconfirmedEventsEmptyStateTitle", {- defaultValue: "No Unconfirmed Events",- }),- description: t("unconfirmedEventsEmptyStateDescription", {- defaultValue: "Unconfirmed events will show up here.",- }),- },- canceled: {- title: t("canceledEventsEmptyStateTitle", {- defaultValue: "No Canceled Events",- }),- description: t("canceledEventsEmptyStateDescription", {- defaultValue: "Canceled events will show up here.",- }),- },- };-- const { title, description } = contentByStatus[status];-- return (- <EmptyState className="h-96">- <EmptyStateIcon>- <CalendarIcon />- </EmptyStateIcon>- <EmptyStateTitle>{title}</EmptyStateTitle>- <EmptyStateDescription>{description}</EmptyStateDescription>- </EmptyState>- );-}--export default async function Page(props: {- params: Promise<Params>;- searchParams?: Promise<{ [key: string]: string | string[] | undefined }>;-}) {- const searchParams = await props.searchParams;- const params = await props.params;- const { t } = await getTranslation(params.locale);-- const { status, q, member } = eventsSearchParamsSchema.parse(searchParams);-- const { members, dehydratedState } = await loadData({- status,- search: q,- member,- });-return (- <HydrationBoundary state={dehydratedState}>- <PageContainer>- <PageHeader>- <PageTitle>- <Trans i18nKey="events" defaults="Events" />- </PageTitle>- </PageHeader>- <PageContent>- <EventsTabbedView>- <div className="mb-4 flex gap-x-2">- <SearchInput- placeholder={t("searchEventsPlaceholder", {- defaultValue: "Search events by title...",- })}- />- <MemberSelector members={members.data} />- </div>- <EventsInfiniteList- status={status}- search={q}- member={member}- emptyState={- <ScheduledEventEmptyState status={status || "upcoming"} />- }- />- </EventsTabbedView>- </PageContent>- </PageContainer>+ <HydrationBoundary state={dehydrate(helpers.queryClient)}>+ <EventsPage /></HydrationBoundary>);}diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/loading.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/loading.tsxindex fdf5e4f64..4d560572d 100644--- a/apps/web/src/app/[locale]/(space)/(dashboard)/loading.tsx+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/loading.tsx@@ -1,7 +1,7 @@import { PageSkeleton } from "@/app/components/page-layout";import { RouterLoadingIndicator } from "@/components/router-loading-indicator";-export default async function Loading() {+export default function Loading() {return (<><RouterLoadingIndicator />diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/page.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/page.tsxindex 90d166522..56617898a 100644--- a/apps/web/src/app/[locale]/(space)/(dashboard)/page.tsx+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/page.tsx@@ -1,9 +1,19 @@+import { dehydrate, HydrationBoundary } from "@tanstack/react-query";import type { Metadata } from "next";import { getTranslation } from "@/i18n/server";+import { createAuthenticatedSSRHelper } from "@/trpc/server/create-ssr-helper";import { DashboardHome } from "./dashboard-home";-export default function Page() {- return <DashboardHome />;+export default async function Page() {+ const helpers = await createAuthenticatedSSRHelper();++ await helpers.dashboard.stats.prefetch();++ return (+ <HydrationBoundary state={dehydrate(helpers.queryClient)}>+ <DashboardHome />+ </HydrationBoundary>+ );}export async function generateMetadata(): Promise<Metadata> {diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/page.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/page.tsxindex ebd43ff53..748ca2b72 100644--- a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/page.tsx+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/page.tsx@@ -1,9 +1,32 @@+import { dehydrate, HydrationBoundary } from "@tanstack/react-query";import type { Metadata } from "next";import { getTranslation } from "@/i18n/server";+import { createAuthenticatedSSRHelper } from "@/trpc/server/create-ssr-helper";import { PollsPage } from "./polls-page";+import { searchParamsSchema } from "./schema";-export default function Page() {- return <PollsPage />;+export default async function Page(props: {+ searchParams?: Promise<{ [key: string]: string | string[] | undefined }>;+}) {+ const searchParams = await props.searchParams;+ const { status, q, member } = searchParamsSchema.parse(searchParams);++ const helpers = await createAuthenticatedSSRHelper();++ await Promise.all([+ helpers.space.members.prefetch(),+ helpers.polls.infiniteChronological.prefetchInfinite({+ status,+ search: q,+ member,+ }),+ ]);++ return (+ <HydrationBoundary state={dehydrate(helpers.queryClient)}>+ <PollsPage />+ </HydrationBoundary>+ );}export async function generateMetadata(): Promise<Metadata> {diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/polls-page.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/polls-page.tsxindex 4c16c09f0..211c8092b 100644--- a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/polls-page.tsx+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/polls-page.tsx@@ -5,14 +5,12 @@ import { Icon } from "@rallly/ui/icon";import { InboxIcon, PlusIcon } from "lucide-react";import Link from "next/link";import { useSearchParams } from "next/navigation";-import React from "react";import {PageContainer,PageContent,PageHeader,PageHeaderActions,PageHeaderContent,- PageSkeleton,PageTitle,} from "@/app/components/page-layout";import { SearchInput } from "@/app/components/search-input";@@ -56,7 +54,7 @@ function PollsEmptyState() {);}-function PollsPageContent() {+export function PollsPage() {const searchParams = useSearchParams();const { t } = useTranslation();const [members] = trpc.space.members.useSuspenseQuery();@@ -105,11 +103,3 @@ function PollsPageContent() {</PageContainer>);}--export function PollsPage() {- return (- <React.Suspense fallback={<PageSkeleton />}>- <PollsPageContent />- </React.Suspense>- );-}diff --git a/apps/web/src/trpc/client/provider.tsx b/apps/web/src/trpc/client/provider.tsxindex 885ed9723..5c51adf0d 100644--- a/apps/web/src/trpc/client/provider.tsx+++ b/apps/web/src/trpc/client/provider.tsx@@ -1,6 +1,7 @@"use client";import { usePostHog } from "@rallly/posthog/client";import { toast } from "@rallly/ui/sonner";+import { absoluteUrl } from "@rallly/utils/absolute-url";import {MutationCache,QueryClient,@@ -67,7 +68,7 @@ export function TRPCProvider(props: { children: React.ReactNode }) {trpc.createClient({links: [httpBatchLink({- url: "/api/trpc",+ url: absoluteUrl("/api/trpc"),transformer: superjson,}),],