feat: account
This commit is contained in:
@@ -46,7 +46,7 @@ export default function EditPageClient({ page, pageType, initialBlocks = [] }: P
|
||||
return (
|
||||
<div className="flex flex-col p-16 gap-12">
|
||||
<div className="flex flex-row items-center justify-between">
|
||||
<h1 className="underline underline-offset-8 decoration-2">Edit page</h1>
|
||||
<h1 className="">Edit page</h1>
|
||||
<div className="flex flex-row gap-3">
|
||||
<Button
|
||||
disabled={isPending}
|
||||
|
||||
@@ -170,7 +170,7 @@ export default async function Page({ params }: { params: Promise<{ type: string;
|
||||
<div className="flex flex-col p-16 gap-12">
|
||||
<div className={cn("flex flex-col gap-4 justify-center", isNews && "items-center")}>
|
||||
<div className="flex flex-row items-center gap-6">
|
||||
<h1 className="underline underline-offset-8 decoration-2">{page?.title}</h1>
|
||||
<h1 className="">{page?.title}</h1>
|
||||
{user?.isAdmin && (
|
||||
<div className="flex flex-row gap-2 items-center">
|
||||
<Link href={`/${page.type.toLowerCase()}/${page.slug}/edit`}>
|
||||
@@ -194,7 +194,7 @@ export default async function Page({ params }: { params: Promise<{ type: string;
|
||||
<Alert className="w-max">
|
||||
<InfoIcon />
|
||||
<AlertTitle>This page is archived</AlertTitle>
|
||||
<AlertDescription>It can be seen only by admins. Make any edits to make it visible again.</AlertDescription>
|
||||
<AlertDescription>It can be seen only by administrators. Make any edits to make it visible again.</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
{blocks.map((block) => (
|
||||
|
||||
@@ -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 />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
"use server"
|
||||
|
||||
import { deleteUser } from "@/lib/user/repository"
|
||||
import logout from "./logout";
|
||||
|
||||
export default async function deleteUserAction(userId: string ) {
|
||||
await deleteUser(userId);
|
||||
await logout();
|
||||
}
|
||||
@@ -39,7 +39,7 @@ export async function GET(request: NextRequest) {
|
||||
await createSession(user.id);
|
||||
await deleteOAuthCookies();
|
||||
|
||||
return NextResponse.redirect(new URL("/", request.url));
|
||||
return NextResponse.redirect(new URL("/account", request.url));
|
||||
} catch (e) {
|
||||
console.error("OAuth callback error:", e);
|
||||
return NextResponse.redirect(new URL("/callback/error", request.url));
|
||||
|
||||
@@ -38,7 +38,7 @@ export default function CreatePageClient() {
|
||||
return (
|
||||
<div className="flex flex-col p-16 gap-12">
|
||||
<div className="flex flex-row items-center justify-between">
|
||||
<h1 className="underline underline-offset-8 decoration-2">Create page</h1>
|
||||
<h1 className="">Create page</h1>
|
||||
<div className="flex flex-row gap-3">
|
||||
<Button
|
||||
variant="outline"
|
||||
|
||||
+4
-4
@@ -55,8 +55,8 @@
|
||||
--card-foreground: oklch(0.145 0 0);
|
||||
--popover: oklch(1 0 0);
|
||||
--popover-foreground: oklch(0.145 0 0);
|
||||
--primary: oklch(0.205 0 0);
|
||||
--primary-foreground: oklch(0.985 0 0);
|
||||
--primary: #00a2e8;
|
||||
--primary-foreground: oklch(1 0 0);
|
||||
--secondary: oklch(0.97 0 0);
|
||||
--secondary-foreground: oklch(0.205 0 0);
|
||||
--muted: oklch(0.97 0 0);
|
||||
@@ -66,7 +66,7 @@
|
||||
--destructive: oklch(0.577 0.245 27.325);
|
||||
--border: oklch(0.922 0 0);
|
||||
--input: oklch(0.922 0 0);
|
||||
--ring: oklch(0.708 0 0);
|
||||
--ring: #00a2e8;
|
||||
--chart-1: oklch(0.87 0 0);
|
||||
--chart-2: oklch(0.556 0 0);
|
||||
--chart-3: oklch(0.439 0 0);
|
||||
@@ -133,7 +133,7 @@
|
||||
}
|
||||
|
||||
h1 {
|
||||
@apply text-3xl tracking-tight
|
||||
@apply text-3xl tracking-tight underline underline-offset-8 decoration-2
|
||||
}
|
||||
|
||||
h2 {
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ export default async function News() {
|
||||
<Header />
|
||||
<div className="flex flex-col p-16 gap-16">
|
||||
<div className="flex flex-row items-center justify-between">
|
||||
<h1 className="underline underline-offset-8 decoration-2">News</h1>
|
||||
<h1 className="">News</h1>
|
||||
<div className="flex flex-row items-center gap-4">
|
||||
{user?.isAdmin && (
|
||||
<div className="flex flex-row items-center gap-4">
|
||||
|
||||
+9
-9
@@ -12,34 +12,34 @@ export default async function Home() {
|
||||
<>
|
||||
<Header />
|
||||
<div className="flex flex-col p-16 gap-16">
|
||||
<h1>Welcome to the <span className="underline underline-offset-8 decoration-2">European Federation</span>!</h1>
|
||||
<h1>Welcome to the European Federation!</h1>
|
||||
<div className="grid grid-cols-[2fr_1fr_1fr_1fr] gap-8">
|
||||
<Link href="/page/citizenship">
|
||||
<div className="flex items-end h-64 p-4 rounded-lg bg-[#00a2e8] text-white">
|
||||
<h1 className="flex flex-row items-center gap-2 hover:gap-4 hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">Become a citizen<ArrowRightIcon size={30} /></h1>
|
||||
<div className="flex items-end h-64 p-4 rounded-lg bg-primary text-primary-foreground">
|
||||
<h1 className="flex flex-row items-center gap-2 hover:gap-4 hover: duration-200 cursor-pointer">Become a citizen<ArrowRightIcon size={30} /></h1>
|
||||
</div>
|
||||
</Link>
|
||||
<div className="grid grid-rows-2 gap-8">
|
||||
<Link href="/page/president">
|
||||
<div className="flex items-end h-28 p-2.5 rounded-lg bg-muted">
|
||||
<h2 className="flex flex-row items-center gap-2 hover:gap-4 hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">Learn more about the President</h2>
|
||||
<h2 className="flex flex-row items-center gap-2 hover:gap-4 hover: duration-200 cursor-pointer">Learn more about the President</h2>
|
||||
</div>
|
||||
</Link>
|
||||
<div className="flex items-end h-28 p-2.5 rounded-lg bg-muted">
|
||||
<h2 className="flex flex-row items-center gap-2 hover:gap-4 hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">Acknowledge with the Federal Government</h2>
|
||||
<h2 className="flex flex-row items-center gap-2 hover:gap-4 hover: duration-200 cursor-pointer">Acknowledge with the Federal Government</h2>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid grid-rows-2 gap-8">
|
||||
<div className="flex items-end h-28 p-2.5 rounded-lg bg-muted">
|
||||
<h2 className="flex flex-row items-center gap-2 hover:gap-4 hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">Regions of the Federation</h2>
|
||||
<h2 className="flex flex-row items-center gap-2 hover:gap-4 hover: duration-200 cursor-pointer">Regions of the Federation</h2>
|
||||
</div>
|
||||
<div className="flex items-end h-28 p-2.5 rounded-lg bg-muted">
|
||||
<h2 className="flex flex-row items-center gap-2 hover:gap-4 hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">Receive consular services abroad</h2>
|
||||
<h2 className="flex flex-row items-center gap-2 hover:gap-4 hover: duration-200 cursor-pointer">Receive consular services abroad</h2>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-col gap-8 mt-8">
|
||||
<h1 className="underline underline-offset-8 decoration-2">Recent news</h1>
|
||||
<h1 className="">Recent news</h1>
|
||||
<div className="flex flex-col gap-6">
|
||||
{
|
||||
news.length > 0 ? news.map((n) => (
|
||||
@@ -47,7 +47,7 @@ export default async function Home() {
|
||||
)) : <h2 className="text-muted-foreground">There are no news yet...</h2>
|
||||
}
|
||||
</div>
|
||||
<Link href="/news"><h3 className="w-max flex flex-row items-center gap-2 hover:gap-2.5 hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">See all news<ArrowRightIcon size={20} /></h3></Link>
|
||||
<Link href="/news"><h3 className="w-max flex flex-row items-center gap-2 hover:gap-2.5 hover: duration-200 cursor-pointer">See all news<ArrowRightIcon size={20} /></h3></Link>
|
||||
</div>
|
||||
</div>
|
||||
<Footer />
|
||||
|
||||
Reference in New Issue
Block a user