feat: account

This commit is contained in:
Ivan Rezchikov
2026-06-23 15:32:52 +03:00
parent 64923cd1b2
commit 58ec75c948
18 changed files with 205 additions and 29 deletions
+1 -1
View File
@@ -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}
+2 -2
View File
@@ -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) => (
+44
View File
@@ -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>
);
}
+20
View File
@@ -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>
);
}
+87
View File
@@ -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 />
</>
);
}
+9
View File
@@ -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();
}
+1 -1
View File
@@ -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));
+1 -1
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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 />
+2 -2
View File
@@ -137,7 +137,7 @@ export default function Editor({ page, initialBlocks = [], onChange }: EditorPro
return (
<div className="flex flex-col gap-10">
<FieldSet>
<h2 className="underline underline-offset-8 decoration-2 mb-6">Meta</h2>
<h2 className=" mb-6">Meta</h2>
<FieldGroup>
<Field>
<FieldLabel htmlFor="title">Title</FieldLabel>
@@ -215,7 +215,7 @@ export default function Editor({ page, initialBlocks = [], onChange }: EditorPro
</FieldSet>
<div className="flex flex-col gap-1">
<h2 className="underline underline-offset-8 decoration-2 mb-6">Content</h2>
<h2 className=" mb-6">Content</h2>
{blocks.length === 0 && (
<p className="text-sm text-muted-foreground">No blocks yet. Add one below.</p>
)}
+1 -4
View File
@@ -2,7 +2,6 @@ import Image from "next/image";
import { Button } from "./ui/button";
import login from "@/app/actions/login";
import { getCurrentUser } from "@/lib/user";
import logout from "@/app/actions/logout";
import Link from "next/link";
import { getNavLinks } from "@/lib/navlinks/repository";
@@ -30,9 +29,7 @@ export default async function Header() {
</div>
{
user ? (
<form action={logout}>
<Button size="lg" type="submit">{`Logout from ${user.firstName} ${user.secondName}`}</Button>
</form>
<Link href="/account"><Button>Account</Button></Link>
) : (
<form action={login}>
<Button size="lg" type="submit">Sign in with Kotosoft ID</Button>
+1 -1
View File
@@ -8,7 +8,7 @@ export function NewsCard({ news }: { news: Page }) {
return (
<div className="flex flex-col gap-2">
<Link href={`/news/${news.slug}`} className="w-max">
<h2 className="hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">{news.title}</h2>
<h2 className="hover: duration-200 cursor-pointer">{news.title}</h2>
</Link>
<div className="flex flex-row gap-8 items-center">
<p className="flex gap-2 items-center"><CalendarIcon size={16} />{formatDate(news.publishedAt)}</p>
+2 -1
View File
@@ -3,7 +3,8 @@ import { Block, PageMeta, PageStatus, PageType } from "./types";
import { prisma } from "../prisma";
export async function getPages(type: PageType, status: PageStatus, limit?: number) {
return await prisma.page.findMany({ where: { type, status }, take: limit, orderBy: { publishedAt: "desc" }, });
// return await prisma.page.findMany({ where: { type, status }, take: limit, orderBy: { publishedAt: "desc" }, });
return []
}
export async function getPageById(id: string) {
+2
View File
@@ -1,5 +1,7 @@
import { getSessionUserId } from "@/lib/auth/session";
import { findUserById } from "@/lib/user/repository";
import { fetchKotosoftUser } from "./kotosoft/client";
import { cookies } from "next/headers";
export async function getCurrentUser() {
const userId = await getSessionUserId();
+16
View File
@@ -32,3 +32,19 @@ export async function updateUser(id: string, data: Partial<Omit<UserData, "kotos
},
});
}
export async function deleteUser(id: string) {
await prisma.page.updateMany({
where: { createdBy: id },
data: { createdBy: null }
});
await prisma.page.updateMany({
where: { updatedBy: id },
data: { updatedBy: null }
});
await prisma.user.delete({
where: { id }
});
}
+2 -2
View File
@@ -54,8 +54,8 @@ model Page {
updatedAt DateTime @updatedAt
publishedAt DateTime?
createdBy String
author User @relation("PageAuthor", fields: [createdBy], references: [id])
createdBy String?
author User? @relation("PageAuthor", fields: [createdBy], references: [id])
updatedBy String?
editor User? @relation("PageEditor", fields: [updatedBy], references: [id])