68 lines
2.7 KiB
TypeScript
68 lines
2.7 KiB
TypeScript
import { Separator } from "@/components/ui/separator";
|
|
import { getCurrentUser } from "@/lib/user";
|
|
import { formatDate } from "@/lib/utils";
|
|
import { redirect } from "next/navigation";
|
|
import { DeleteDialog } from "./delete-dialog";
|
|
import { LogoutButton } from "./logout-button";
|
|
import { UpdateButton } from "./update-button";
|
|
import { AccountMenu } from "./account-menu";
|
|
|
|
function ProfileField({ label, value }: { label: string; value: string }) {
|
|
return (
|
|
<div className="flex flex-col">
|
|
<h4>{label}</h4>
|
|
<p className="text-muted-foreground">{value}</p>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default async function Account() {
|
|
const user = await getCurrentUser();
|
|
if (!user) redirect("/");
|
|
|
|
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>Personal details</h2>
|
|
<p className="text-muted-foreground text-sm">
|
|
Synced from your Kotosoft ID account. To correct any details, update them there first, then click Update below.
|
|
</p>
|
|
</div>
|
|
<div className="flex flex-col gap-4">
|
|
<ProfileField label="Name" value={`${user.firstName} ${user.secondName}`} />
|
|
<ProfileField label="Email" value={user.email} />
|
|
<ProfileField label="Birthday" value={formatDate(user.birthDate)} />
|
|
<ProfileField label="Sex" value={user.sex === "MALE" ? "Male" : "Female"} />
|
|
{user.isAdmin && <ProfileField label="Role" value="Administrator" />}
|
|
</div>
|
|
<Separator />
|
|
<div className="flex flex-row items-center justify-between gap-2">
|
|
<div className="flex flex-col">
|
|
<h4>Update personal details</h4>
|
|
<p className="text-muted-foreground">Syncs your name, email, and birthday from Kotosoft ID</p>
|
|
</div>
|
|
<UpdateButton />
|
|
</div>
|
|
<div className="flex flex-row items-center justify-between gap-2">
|
|
<div className="flex flex-col">
|
|
<h4>Log out</h4>
|
|
<p className="text-muted-foreground">Log out from your account on this device</p>
|
|
</div>
|
|
<LogoutButton />
|
|
</div>
|
|
<Separator />
|
|
<div className="flex flex-row items-center justify-between gap-2">
|
|
<div className="flex flex-col">
|
|
<h4>Delete account</h4>
|
|
<p className="text-muted-foreground">Permanently delete your account and all associated data</p>
|
|
</div>
|
|
<DeleteDialog />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
} |