Skip to content

Commit 81bfa1c

Browse files
committed
refactor: follow best practices
1 parent ff68eaa commit 81bfa1c

File tree

16 files changed

+57
-236
lines changed

16 files changed

+57
-236
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
## Variables
44

55
```env
6-
BACKEND_BASE_URL=
7-
APP_REDIRECT_URL=
6+
NEXT_PUBLIC_BACKEND_BASE_URL=
87
```
98

109
## Development

app/(admin)/(user-management)/groups/[id]/_components/audit-info-card.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ function CardMain({ id }: { id: string }) {
2626
<li className="flex items-center gap-2">
2727
<Clock className="h-4 w-4 text-muted-foreground" />
2828
<span>
29-
建立時間:{new Date(data.group.createdAt).toLocaleString()}
29+
建立時間:{new Date(data.group.createdAt).toLocaleString('zh-TW', { timeZone: 'Asia/Taipei' })}
3030
</span>
3131
</li>
3232
<li className="flex items-center gap-2">
3333
<Clock className="h-4 w-4 text-muted-foreground" />
3434
<span>
35-
更新時間:{new Date(data.group.updatedAt).toLocaleString()}
35+
更新時間:{new Date(data.group.updatedAt).toLocaleString('zh-TW', { timeZone: 'Asia/Taipei' })}
3636
</span>
3737
</li>
3838
</ul>

app/(admin)/(user-management)/users/[id]/_components/audit-info.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ function CardMain({ id }: { id: string }) {
2626
<li className="flex items-center gap-2">
2727
<Clock className="h-4 w-4 text-muted-foreground" />
2828
<span>
29-
建立時間:{new Date(data.user.createdAt).toLocaleString()}
29+
建立時間:{new Date(data.user.createdAt).toLocaleString('zh-TW', { timeZone: 'Asia/Taipei' })}
3030
</span>
3131
</li>
3232
<li className="flex items-center gap-2">
3333
<Clock className="h-4 w-4 text-muted-foreground" />
3434
<span>
35-
更新時間:{new Date(data.user.updatedAt).toLocaleString()}
35+
更新時間:{new Date(data.user.updatedAt).toLocaleString('zh-TW', { timeZone: 'Asia/Taipei' })}
3636
</span>
3737
</li>
3838
</ul>

app/(admin)/layout.tsx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
import { AppSidebar } from "@/components/app-sidebar";
22
import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar";
3-
import { UserProvider } from "@/providers/use-user";
43

54
export default function AdminLayout({
65
children,
76
}: Readonly<{
87
children: React.ReactNode;
98
}>) {
109
return (
11-
<UserProvider>
12-
<SidebarProvider
13-
style={{
14-
"--sidebar-width": "calc(var(--spacing) * 72)",
15-
"--header-height": "calc(var(--spacing) * 12)",
16-
} as React.CSSProperties}
17-
>
18-
<AppSidebar variant="inset" />
19-
<SidebarInset>
20-
{children}
21-
</SidebarInset>
22-
</SidebarProvider>
23-
</UserProvider>
10+
<SidebarProvider
11+
style={{
12+
"--sidebar-width": "calc(var(--spacing) * 72)",
13+
"--header-height": "calc(var(--spacing) * 12)",
14+
} as React.CSSProperties}
15+
>
16+
<AppSidebar variant="inset" />
17+
<SidebarInset>
18+
{children}
19+
</SidebarInset>
20+
</SidebarProvider>
2421
);
2522
}

app/api/graphql/route.ts

Lines changed: 0 additions & 139 deletions
This file was deleted.

app/forbidden/page.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle }
44
import { redirectIfAuthenticated } from "@/lib/auth.rsc";
55
import { AlertTriangle } from "lucide-react";
66
import Link from "next/link";
7+
import { UserInfo } from "./user-info";
78

8-
export default async function ForbiddenPage({ searchParams }: { searchParams: Promise<{ name?: string; email?: string }> }) {
9+
export default async function ForbiddenPage() {
910
await redirectIfAuthenticated();
1011

11-
const { name, email } = await searchParams;
12-
1312
return (
1413
<div
1514
className={`
@@ -48,10 +47,7 @@ export default async function ForbiddenPage({ searchParams }: { searchParams: Pr
4847
<CardFooter
4948
className={`justify-center text-center text-xs text-muted-foreground`}
5049
>
51-
<section className="flex flex-col items-center gap-1">
52-
<p>您目前登入的帳號是:{name} ({email})</p>
53-
<p>如果這不是您想登入的帳號,請切換 Google 帳號後重新登入</p>
54-
</section>
50+
<UserInfo />
5551
</CardFooter>
5652
</Card>
5753
</div>

app/forbidden/user-info.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"use client";
2+
3+
import { useUser } from "@/providers/use-user";
4+
5+
export function UserInfo() {
6+
const { user } = useUser();
7+
8+
return (
9+
<section className="flex flex-col items-center gap-1">
10+
<p>
11+
您目前登入的帳號是:{user?.name} ({user?.email})
12+
</p>
13+
<p>如果這不是您想登入的帳號,請切換 Google 帳號後重新登入</p>
14+
</section>
15+
);
16+
}

app/layout.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { Geist, Geist_Mono } from "next/font/google";
33
import "./globals.css";
44
import { Toaster } from "@/components/ui/sonner";
55
import { ApolloWrapper } from "@/providers/use-apollo";
6-
import { UserProvider } from "@/providers/use-user";
76
import { PreloadResources } from "./preload-resources";
7+
import { getAuthToken } from "@/lib/auth";
88

99
const geistSans = Geist({
1010
variable: "--font-geist-sans",
@@ -21,11 +21,13 @@ export const metadata: Metadata = {
2121
description: "Managing your Database Playground instance.",
2222
};
2323

24-
export default function RootLayout({
24+
export default async function RootLayout({
2525
children,
2626
}: Readonly<{
2727
children: React.ReactNode;
2828
}>) {
29+
const token = await getAuthToken();
30+
2931
return (
3032
<html lang="zh-hant-tw">
3133
<head>
@@ -43,7 +45,7 @@ export default function RootLayout({
4345
font-sans antialiased
4446
`}
4547
>
46-
<ApolloWrapper>
48+
<ApolloWrapper token={token}>
4749
{children}
4850
</ApolloWrapper>
4951
<Toaster />

app/preload-resources.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use client";
2-
31
import ReactDOM from "react-dom";
42

53
export function PreloadResources() {

components/app-sidebar.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
import { useUser } from "@/providers/use-user";
2020
import Link from "next/link";
2121
import { usePathname } from "next/navigation";
22+
import { Suspense } from "react";
2223

2324
export interface NavItem {
2425
title: string;
@@ -148,18 +149,16 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
148149
<NavSecondary items={data.navSecondary} className="mt-auto" />
149150
</SidebarContent>
150151
<SidebarFooter>
151-
<NavUserMe />
152+
<Suspense fallback={<NavUserLoading />}>
153+
<NavUserMe />
154+
</Suspense>
152155
</SidebarFooter>
153156
</Sidebar>
154157
);
155158
}
156159

157160
function NavUserMe() {
158-
const { user, isInitialized } = useUser();
159-
160-
if (!isInitialized || !user) {
161-
return <NavUserLoading />;
162-
}
161+
const { user } = useUser();
163162

164163
return <NavUser user={user} />;
165164
}

0 commit comments

Comments
 (0)