Files
glenloch-media/src/app/(app)/profile/page.tsx
T
2026-11-20 04:07:02 +00:00

74 lines
2.7 KiB
TypeScript

import Link from "next/link";
import { redirect } from "next/navigation";
import { ArrowLeft } from "lucide-react";
import { auth } from "@/auth/config";
import { getProfile } from "@/db/profile";
import { getUserSkills } from "@/db/userSkills";
import { listSkills } from "@/db/positions";
import { getOrCreateCalendarFeedToken } from "@/db/volunteer";
import { mediaOrigin } from "@/lib/media-url";
import { ProfilePanel } from "@/components/app/profile-panel";
export const metadata = { title: "My profile" };
export const dynamic = "force-dynamic";
export default async function ProfilePage() {
const session = await auth();
const user = session?.user as { id?: string } | undefined;
if (!user?.id) redirect("/login");
const [profile, skillRows, allSkills, token, origin] = await Promise.all([
getProfile(user.id),
getUserSkills(user.id),
listSkills({ active: true }),
getOrCreateCalendarFeedToken(user.id),
mediaOrigin(),
]);
const bySkill = new Map(skillRows.map((row) => [row.skillId, row]));
return (
<div className="space-y-5">
<div>
<Link
href="/settings"
className="inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground"
>
<ArrowLeft className="h-3.5 w-3.5" aria-hidden="true" />
Settings
</Link>
<h1 className="mt-2 text-lg font-semibold tracking-tight">My profile</h1>
<p className="text-sm text-muted-foreground">
Contact details, reminders, skill comfort, and your personal calendar.
</p>
</div>
<ProfilePanel
userId={user.id}
initial={{
firstName: profile.user.firstName,
lastName: profile.user.lastName,
displayName: profile.user.displayName ?? profile.user.firstName,
email: profile.user.email,
phoneE164: profile.user.phoneE164 ?? "",
emergencyContact: profile.user.emergencyContact ?? "",
timezone: profile.user.timezone,
}}
preferences={{
emailEnabled: profile.preferences?.emailEnabled ?? true,
reminderLeadDays: profile.preferences?.reminderLeadDays ?? 7,
digestOnly: profile.preferences?.digestOnly ?? false,
quietHoursStart: profile.preferences?.quietHoursStart ?? "21:00",
quietHoursEnd: profile.preferences?.quietHoursEnd ?? "08:00",
}}
skills={allSkills.map((skill) => ({
id: skill.id,
name: skill.name,
verifiedLevel: bySkill.get(skill.id)?.verifiedLevel ?? "none",
selfComfort: bySkill.get(skill.id)?.selfComfort ?? null,
}))}
feedUrl={`${origin}/api/calendar/${token}`}
/>
</div>
);
}