Skip to content

Commit d86984e

Browse files
175 updates timezone logic for cloudflare (#177)
1 parent 2f63cfd commit d86984e

File tree

10 files changed

+2365
-117
lines changed

10 files changed

+2365
-117
lines changed

apps/web/next.config.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { fileURLToPath } from "node:url";
22
import createJiti from "jiti";
3+
import { setupDevPlatform } from "@cloudflare/next-on-pages/next-dev";
34
const jiti = createJiti(fileURLToPath(import.meta.url));
45

56
jiti("./src/env");
@@ -29,4 +30,8 @@ const nextConfig = {
2930
},
3031
};
3132

33+
if (process.env.NODE_ENV === "development") {
34+
await setupDevPlatform();
35+
}
36+
3237
export default nextConfig;

apps/web/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101
"zod": "^3.23.8"
102102
},
103103
"devDependencies": {
104+
"@cloudflare/next-on-pages": "^1.13.10",
105+
"@cloudflare/workers-types": "^4.20250319.0",
104106
"esbuild-register": "^3.5.0"
105107
}
106108
}

apps/web/src/app/dash/schedule/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import UserScheduleView from "@/components/schedule/UserScheduleView";
33
import ScheduleTimeline from "./schedule-timeline";
44
import Loading from "@/components/shared/Loading";
55
import { getAllEvents } from "db/functions";
6-
import { headers } from "next/headers";
7-
import { VERCEL_IP_TIMEZONE_HEADER_KEY } from "@/lib/constants";
86
import { getClientTimeZone } from "@/lib/utils/client/shared";
7+
import { getRequestContext } from "@cloudflare/next-on-pages";
98
export default async function Page() {
109
const sched = await getAllEvents();
11-
const userTimeZoneHeaderKey = headers().get(VERCEL_IP_TIMEZONE_HEADER_KEY);
10+
const { cf } = getRequestContext();
11+
const userTimeZoneHeaderKey = cf.timezone;
1212
const userTimeZone = getClientTimeZone(userTimeZoneHeaderKey);
1313
return (
1414
<>

apps/web/src/app/not-found.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import Link from "next/link";
22

3-
// TODO: make this look better
4-
53
export default function NotFound() {
64
return (
7-
<div>
8-
<h2>Not Found</h2>
9-
<p>Could not find requested resource</p>
10-
<Link href="/">Return Home</Link>
5+
<div className="flex h-screen w-screen items-center justify-center bg-white dark:bg-black">
6+
<div className="text-center">
7+
<h1 className="mb-4 text-9xl font-extrabold text-hackathon dark:text-primary">
8+
404
9+
</h1>
10+
<h2 className="mb-4 text-4xl font-bold">Page Not Found</h2>
11+
<p className="mb-8 text-lg">
12+
The page you are looking for does not exist.
13+
</p>
14+
<Link href="/" className="text-lg text-blue-500 underline">
15+
Return to Home
16+
</Link>
17+
</div>
1118
</div>
1219
);
1320
}

apps/web/src/app/schedule/page.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Suspense } from "react";
2+
import UserScheduleView from "@/components/schedule/UserScheduleView";
3+
import ScheduleTimeline from "../dash/schedule/schedule-timeline";
4+
import Loading from "@/components/shared/Loading";
5+
import { getAllEvents } from "db/functions";
6+
import { getClientTimeZone } from "@/lib/utils/client/shared";
7+
import { getRequestContext } from "@cloudflare/next-on-pages";
8+
export default async function Page() {
9+
const sched = await getAllEvents();
10+
const { cf } = getRequestContext();
11+
const userTimeZoneHeaderKey = cf.timezone;
12+
const userTimeZone = getClientTimeZone(userTimeZoneHeaderKey);
13+
return (
14+
<>
15+
<h1 className="mx-auto my-8 w-3/4 text-8xl font-black">Schedule</h1>
16+
<Suspense fallback={<Loading />}>
17+
{/* <UserScheduleView /> */}
18+
<ScheduleTimeline schedule={sched} timezone={userTimeZone} />
19+
</Suspense>
20+
</>
21+
);
22+
}
23+
24+
export const runtime = "edge";
25+
export const revalidate = 60;

apps/web/src/components/events/admin/EventDetails.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { formatInTimeZone } from "date-fns-tz";
55
import { Event } from "db/types";
66
import { headers } from "next/headers";
77
import { getClientTimeZone } from "@/lib/utils/client/shared";
8-
import { VERCEL_IP_TIMEZONE_HEADER_KEY } from "@/lib/constants";
8+
import { getRequestContext } from "@cloudflare/next-on-pages";
99
export default function EventFull({ event }: { event: Event }) {
10-
const userTimeZoneHeaderKey = headers().get(VERCEL_IP_TIMEZONE_HEADER_KEY);
10+
const { cf } = getRequestContext();
11+
const userTimeZoneHeaderKey = cf.timezone;
1112

1213
const userTimeZone = getClientTimeZone(userTimeZoneHeaderKey);
1314
return (

apps/web/src/components/schedule/Day.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ import c from "config";
55
import { headers } from "next/headers";
66
import { getClientTimeZone } from "@/lib/utils/client/shared";
77
import EventItem from "./EventItem";
8-
import { VERCEL_IP_TIMEZONE_HEADER_KEY } from "@/lib/constants";
8+
import { getRequestContext } from "@cloudflare/next-on-pages";
99
interface DayProps {
1010
title: string;
1111
subtitle: string;
1212
events: EventType[];
1313
}
1414

1515
export default function Day({ title, subtitle, events }: DayProps) {
16-
const userTimeZoneHeaderKey = headers().get(VERCEL_IP_TIMEZONE_HEADER_KEY);
16+
const { cf } = getRequestContext();
17+
const userTimeZoneHeaderKey = cf.timezone;
1718

1819
const userTimeZone = getClientTimeZone(userTimeZoneHeaderKey);
1920

apps/web/src/lib/constants/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import c from "config";
22
export const ONE_HOUR_IN_MILLISECONDS = 3600000;
33
export const FIVE_MINUTES_IN_MILLISECONDS = 300000;
4-
export const VERCEL_IP_TIMEZONE_HEADER_KEY = "x-vercel-ip-timezone";
54
export const PHONE_NUMBER_REGEX =
65
/^(\+\d{1,2}\s?)?\(?\d{3}\)?\s?[\s.-]?\s?\d{3}\s?[\s.-]?\s?\d{4}$/gm;
76
export const UNIQUE_KEY_CONSTRAINT_VIOLATION_CODE = "23505";

apps/web/src/lib/utils/client/shared.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { rankItem } from "@tanstack/match-sorter-utils";
22
import { FilterFn } from "@tanstack/react-table";
33
import { redirect } from "next/navigation";
4-
export function getClientTimeZone(vercelIPTimeZone: string | null) {
4+
export function getClientTimeZone(vercelIPTimeZone?: string) {
55
return vercelIPTimeZone ?? Intl.DateTimeFormat().resolvedOptions().timeZone;
66
}
77

0 commit comments

Comments
 (0)