feat : update

This commit is contained in:
2026-10-03 00:56:31 +07:00 Unverified
parent f71c00d2ab
commit f23b69a280
36 changed files with 766 additions and 376 deletions
+12 -4
View File
@@ -6,6 +6,8 @@ import { users } from "@/db/schema";
import { SiteHeader } from "@/components/public/site-header";
import { AdminHeader } from "@/components/admin/admin-header";
import { ProfileForm } from "@/components/auth/profile-form";
import { PasswordForm } from "@/components/auth/password-form";
import { EmailSettings } from "@/components/auth/email-settings";
import { isAuthorizedAdmin } from "@/lib/auth/authorization";
import { getCustomerSession } from "@/lib/auth/server";
import { safeAuthReturnPath } from "@/lib/auth/return-path";
@@ -14,22 +16,28 @@ export const instant = false;
export default async function ProfilePage({ searchParams }: PageProps<"/profile">) {
await connection();
const { setup, next, upload } = await searchParams;
const { setup, next, upload, emailAction, error } = await searchParams;
const nextPath = safeAuthReturnPath(next);
const setupNextPath = nextPath === "/profile" || nextPath.startsWith("/profile?") ? "/" : nextPath;
const session = await getCustomerSession();
if (!session) redirect("/login?next=%2Fprofile");
const [user] = await getDb().select({ name: users.name, email: users.email, image: users.image })
const [user] = await getDb().select({ name: users.name, email: users.email,
emailVerified: users.emailVerified, image: users.image })
.from(users).where(eq(users.id, session.user.id)).limit(1);
if (!user) redirect("/login?next=%2Fprofile");
return <div className="min-h-svh">{isAuthorizedAdmin(session.user) ? <AdminHeader /> : <SiteHeader />}
<main className="mx-auto max-w-xl p-4 py-10 sm:p-8">
<main className="mx-auto max-w-5xl p-4 py-10 sm:p-8">
<h1 className="mb-6 font-heading text-3xl font-semibold">โปรไฟล์ของฉัน</h1>
{setup === "1" && <p className="mb-6 text-muted-foreground">
{upload === "failed" ? "สร้างบัญชีแล้ว แต่บันทึกรูปโปรไฟล์ไม่สำเร็จ กรุณาลองอีกครั้งหรือข้ามไปก่อน" :
"เพิ่มรูปโปรไฟล์หรือแก้ชื่อที่แสดงก่อนเริ่มใช้งาน"}
</p>}
<ProfileForm {...user} nextPath={setup === "1" ? setupNextPath : undefined} />
<div className="grid items-start gap-6 md:grid-cols-2">
<ProfileForm {...user} nextPath={setup === "1" ? setupNextPath : undefined} />
<EmailSettings email={user.email} verified={user.emailVerified}
callbackCompleted={emailAction === "1" && !error} callbackError={typeof error === "string"} />
<PasswordForm />
</div>
</main>
</div>;
}