diff --git a/src/app/(frontend)/account/page.tsx b/src/app/(frontend)/account/page.tsx index 75ebb67..4a9f3c1 100644 --- a/src/app/(frontend)/account/page.tsx +++ b/src/app/(frontend)/account/page.tsx @@ -2,17 +2,27 @@ import config from "@payload-config"; import { getPayload } from "payload"; import { headers as nextHeaders } from "next/headers"; import { redirect } from "next/navigation"; +import type { Assignment } from "@/payload-types"; import { UserCogIcon } from "lucide-react"; +import { Badge } from "@/components/ui/badge"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { AccountProfileForm } from "@/components/frontend/account/AccountProfileForm"; +import { AssignmentCard } from "@/components/frontend/account/AssignmentCard"; +import type { AccountAssignment } from "@/components/frontend/transfers/transferTypes"; import { ChangePasswordForm } from "@/components/frontend/account/ChangePasswordForm"; import { DiscordUsernameRequestForm } from "@/components/frontend/account/DiscordUsernameRequestForm"; import { PreferencesForm } from "@/components/frontend/account/PreferencesForm"; +import { RequestTransferDialog } from "@/components/frontend/account/RequestTransferDialog"; export const metadata = { title: "Account — Polaris Task Force", }; +function relationId(value: Assignment["leader"]): number | null { + if (typeof value === "object" && value !== null) return value.id; + return value ?? null; +} + export default async function AccountPage() { const payload = await getPayload({ config }); const { user } = await payload.auth({ @@ -30,6 +40,46 @@ export default async function AccountPage() { depth: 0, overrideAccess: true, }); + const assignmentsRes = await payload.find({ + collection: "assignments", + where: { + or: [{ members: { equals: user.id } }, { leader: { equals: user.id } }], + }, + limit: 50, + depth: 0, + select: { name: true, type: true, callsign: true, leader: true }, + }); + + const assignments: AccountAssignment[] = assignmentsRes.docs.map((assignment) => ({ + id: assignment.id, + name: assignment.name, + type: assignment.type, + callsign: assignment.callsign ?? null, + leaderId: + typeof assignment.leader === "object" && assignment.leader !== null + ? assignment.leader.id + : (assignment.leader ?? null), + isLeader: relationId(assignment.leader) === user.id, + })); + + const assignmentRes = await payload.find({ + collection: "assignments", + where: { + or: [{ members: { contains: user.id } }, { leader: { equals: user.id } }], + }, + sort: "name", + limit: 100, + depth: 0, + select: { name: true, type: true, callsign: true, leader: true }, + }); + const currentAssignments: AccountAssignment[] = assignmentRes.docs.map((assignment) => ({ + id: assignment.id, + name: assignment.name, + type: assignment.type, + callsign: assignment.callsign ?? null, + leaderId: relationId(assignment.leader), + isLeader: relationId(assignment.leader) === user.id, + })); const notifications = fullUser.preferences?.notifications; const discord = fullUser.preferences?.discord; @@ -57,6 +107,42 @@ export default async function AccountPage() { + + + + +
+
+ Assignment + Review your current assignment and request a move. +
+ +
+
+ + {currentAssignments.length > 0 ? ( +
+ {currentAssignments.map((assignment) => ( + + {assignment.callsign + ? `${assignment.name} · ${assignment.callsign}` + : assignment.name} + {assignment.isLeader ? " · Leader" : ""} + + ))} +
+ ) : ( +

+ You are not currently assigned to a unit. Ask leadership to add you before + requesting a transfer. +

+ )} +
+
+ Password