feat: account
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
"use client"
|
||||
|
||||
import { useTransition } from "react";
|
||||
import {
|
||||
Dialog, DialogClose, DialogContent, DialogDescription,
|
||||
DialogFooter, DialogHeader, DialogTitle, DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import deleteUserAction from "../actions/delete";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
|
||||
export function DeleteDialog({ userId }: { userId: string }) {
|
||||
const [isPending, startTransition] = useTransition();
|
||||
|
||||
return (
|
||||
<Dialog>
|
||||
<DialogTrigger asChild>
|
||||
<Button variant="ghost" className="text-destructive hover:text-destructive hover:bg-destructive/10">
|
||||
Delete
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle asChild><h3>Are you absolutely sure?</h3></DialogTitle>
|
||||
<DialogDescription>
|
||||
This action cannot be undone. This will permanently delete your account
|
||||
and remove your data from our servers.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline" disabled={isPending}>Cancel</Button>
|
||||
</DialogClose>
|
||||
<Button
|
||||
disabled={isPending}
|
||||
onClick={() => startTransition(() => deleteUserAction(userId))}
|
||||
>
|
||||
{isPending && <Spinner />}Delete
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
"use client"
|
||||
|
||||
import { useTransition } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import logout from "../actions/logout";
|
||||
|
||||
export function LogoutButton() {
|
||||
const [isPending, startTransition] = useTransition();
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="secondary"
|
||||
disabled={isPending}
|
||||
onClick={() => startTransition(() => logout())}
|
||||
>
|
||||
{isPending && <Spinner />}Log out
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import Footer from "@/components/footer";
|
||||
import Header from "@/components/header";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { getCurrentUser } from "@/lib/user";
|
||||
import { formatDate } from "@/lib/utils";
|
||||
import { BookOpenTextIcon, SignatureIcon, UserIcon } from "lucide-react";
|
||||
import { redirect } from "next/navigation";
|
||||
import { DeleteDialog } from "./deleteDialog";
|
||||
import { LogoutButton } from "./logoutButton";
|
||||
|
||||
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 (
|
||||
<>
|
||||
<Header />
|
||||
<div className="flex flex-row py-16 gap-8">
|
||||
<div className="flex flex-col w-56 gap-2 mx-16 shrink-0">
|
||||
<div className="flex flex-row gap-2 items-center text-foreground underline underline-offset-8 decoration-2 mb-1.5">
|
||||
<UserIcon size={16} />
|
||||
<h4>Profile</h4>
|
||||
</div>
|
||||
<div className="flex flex-row gap-2 items-center text-muted-foreground hover:text-foreground hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">
|
||||
<BookOpenTextIcon size={16} />
|
||||
<h4>Citizenship</h4>
|
||||
</div>
|
||||
<div className="flex flex-row gap-2 items-center text-muted-foreground hover:text-foreground hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">
|
||||
<SignatureIcon size={16} />
|
||||
<h4>Signature</h4>
|
||||
</div>
|
||||
</div>
|
||||
<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">
|
||||
<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>
|
||||
<Button variant="secondary">Update</Button>
|
||||
</div>
|
||||
<div className="flex flex-row items-center justify-between">
|
||||
<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">
|
||||
<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 userId={user.id} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Footer />
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user