58 lines
2.3 KiB
TypeScript
58 lines
2.3 KiB
TypeScript
import { getCurrentUser, getUsers } from "@/lib/user";
|
|
import { redirect } from "next/navigation";
|
|
import { AccountMenu } from "../account-menu";
|
|
import { Metadata } from "next";
|
|
import { getUserPositions } from "@/lib/positions/repository";
|
|
import { Button } from "@/components/ui/button";
|
|
import { CreatePositionDialog } from "./create-position-dialog";
|
|
import { getInstitutions } from "@/lib/acts/repository";
|
|
import { formatDate } from "@/lib/utils";
|
|
import Link from "next/link";
|
|
|
|
export const metadata: Metadata = {
|
|
title: "Positions",
|
|
robots: {
|
|
index: false,
|
|
follow: false,
|
|
},
|
|
};
|
|
|
|
export default async function Account() {
|
|
const user = await getCurrentUser();
|
|
if (!user) redirect("/");
|
|
|
|
const userPositions = await getUserPositions(user.id);
|
|
const institutions = await getInstitutions();
|
|
|
|
return (
|
|
<div className="flex flex-col md:flex-row p-4 md:p-16 gap-8 md:gap-16 mb-4 md:mb-0">
|
|
<AccountMenu />
|
|
<div className="flex flex-col gap-8 max-w-lg">
|
|
<div className="flex flex-col gap-6">
|
|
<div className="flex flex-col gap-1">
|
|
<h2>Positions</h2>
|
|
<p className="text-muted-foreground text-sm">Here are your positions in the European Federation</p>
|
|
</div>
|
|
{userPositions.length === 0 ? <p className="text-muted-foreground">You do not have any positions</p> :
|
|
<div className="flex flex-col gap-4">
|
|
{userPositions.map((position) => (
|
|
<div key={position.id} className="flex flex-col gap-0.5">
|
|
<h4>{position.position.name}</h4>
|
|
<p className="text-muted-foreground">Assigned on {formatDate(position.assignedAt)} by <Link href={`/acts/${position.actId}`} className="underline">{position.act?.actType.name} {position.act?.numberInSeries && `№${position.act.numberInSeries}/${position.act.numberYear}`}</Link></p>
|
|
</div>
|
|
))}
|
|
</div>
|
|
}
|
|
{user.isAdmin && (
|
|
<div className="flex flex-col gap-2">
|
|
<CreatePositionDialog institutions={institutions} />
|
|
<p className="text-muted-foreground">
|
|
To assign or dismiss someone from a position, create an appointment act.
|
|
</p>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
} |