initial commit

This commit is contained in:
Giovanni Rezcjikov
2026-03-08 14:54:29 +03:00
commit f4e4fb21e3
75 changed files with 7407 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
"use client"
import Header from "@/components/header";
import { Skeleton } from "@/components/ui/skeleton";
import { useTranslations } from "next-intl";
import type { Consent, User } from "@/types";
import { AppWindowMacIcon, BriefcaseBusinessIcon, LogOutIcon, UserIcon } from "lucide-react";
import { Button } from "@/components/ui/button";
import { useState } from "react";
import { Logout } from "@/actions/auth";
import Profile from "./items/profile";
import Applications from "./items/applications";
interface Props {
userData: User | null;
consentsData: Consent[] | [];
}
export default function MeClient({ userData, consentsData }: Props) {
const t = useTranslations("MePage");
const [user, setUser] = useState(userData);
const [consents, setConsents] = useState(consentsData)
const [selectedItem, setSelectedItem] = useState(0);
const items = [
{"name": t("items.profile.title"), "icon": <UserIcon />, "component": <Profile user={user} setUser={setUser} />},
{"name": t("items.applications.title"), "icon": <AppWindowMacIcon />, "component": <Applications consents={consents} setConsents={setConsents} />},
{"name": t("items.positions.title"), "icon": <BriefcaseBusinessIcon />},
]
return (
<>
<Header />
<div className="bg-background flex min-h-svh flex-col gap-6">
<div className="px-8 lg:px-16 pt-30 pb-16">
{!user ? (
<div className="flex flex-col gap-2">
<Skeleton className="w-64 h-5" />
<Skeleton className="w-52 h-4" />
</div>
) : (
<div className="flex flex-col lg:flex-row gap-12">
<div className="flex flex-col gap-8">
<div className="flex flex-col">
<h2 className="text-lg">
{user.first_name} {user.second_name}
</h2>
<p className="text-muted-foreground text-base">{user.email}</p>
</div>
<div className="flex flex-col gap-0.5 lg:w-64">
{
items.map((item, index) => (
<Button variant="ghost" className={`justify-start -mx-4 ${selectedItem == index && "bg-muted"}`} key={index} onClick={() => setSelectedItem(index)}>{item.icon}<h3 className="text-sm">{item.name}</h3></Button>
))
}
<Button variant="ghost" className="justify-start -mx-4" onClick={async () => Logout()}><LogOutIcon /><h3 className="text-sm">{t("items.logout")}</h3></Button>
</div>
</div>
{items[selectedItem].component}
</div>
)}
</div>
</div>
</>
);
}
@@ -0,0 +1,41 @@
"use client"
import { useLocale, useTranslations } from "next-intl";
import type { Consent } from "@/types";
import { Item, ItemActions, ItemContent, ItemDescription, ItemTitle } from "@/components/ui/item"
import { Button } from "@/components/ui/button";
import { localeMap } from "@/types";
import { enUS } from "date-fns/locale";
import { format } from "date-fns";
interface Props {
consents: Consent[] | [];
setConsents: (consents: Consent[]) => void;
}
export default function Applications({ consents, setConsents }: Props) {
const t = useTranslations("MePage.items.applications");
const locale = useLocale();
const dateLocale = localeMap[locale as keyof typeof localeMap] ?? enUS;
return (
<div className="w-full lg:max-w-sm flex flex-col gap-4">
<h1 className="text-xl">{t("title")}</h1>
<div className="space-y-4">
{consents.map((consent) => (
<Item key={consent.client_id}>
<ItemContent>
<ItemTitle>{consent.client_name}</ItemTitle>
<ItemDescription>{t("authorized")} {format(consent.authorized_at, "PPP", { locale: dateLocale }) }</ItemDescription>
</ItemContent>
<ItemActions>
<Button disabled={!consent.isRevokable}>{t("revoke")}</Button>
</ItemActions>
</Item>
))}
</div>
</div>
);
}
@@ -0,0 +1,115 @@
"use client"
import { useState } from "react";
import { useTranslations } from "next-intl";
import { useForm, Controller, SubmitHandler } from "react-hook-form";
import type { User } from "@/types";
import { Button } from "@/components/ui/button";
import { Field, FieldError, FieldGroup, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import { Spinner } from "@/components/ui/spinner";
import { BirthdatePicker } from "@/components/ui/birthdate-picker";
import { UpdateUser } from "@/actions/auth";
interface Props {
user: User | null;
setUser: (user: User) => void;
}
interface FormData {
first_name: string;
second_name: string;
birth_date: string;
}
export default function Profile({ user, setUser }: Props) {
const t = useTranslations("MePage.items.profile");
const [error, setError] = useState<string | null>(null);
const { register, handleSubmit, control, formState: { errors, isSubmitting } } = useForm<FormData>({
defaultValues: {
first_name: user?.first_name,
second_name: user?.second_name,
birth_date: user?.birth_date ?? "",
},
});
const onSubmit: SubmitHandler<FormData> = async (data) => {
setError(null);
try {
const response = await UpdateUser(data.first_name, data.second_name, data.birth_date);
if (response == null) setError(t("form.updateError"))
else setUser(response)
} catch (error) {
setError(t("form.updateError"))
}
};
return (
<div className="w-full lg:max-w-sm flex flex-col gap-4">
<h1 className="text-xl">{t("title")}</h1>
<form onSubmit={handleSubmit(onSubmit)}>
<FieldGroup>
<Field data-invalid={!!errors.first_name}>
<FieldLabel htmlFor="first_name">{t("form.firstName.title")}</FieldLabel>
<Input
id="first_name"
type="text"
disabled={isSubmitting}
aria-invalid={!!errors.first_name}
{...register("first_name", {
required: t("form.required"),
minLength: { value: 2, message: t("form.firstName.minLength") },
maxLength: { value: 64, message: t("form.firstName.maxLength") },
})}
/>
{errors.first_name && <FieldError>{errors.first_name.message}</FieldError>}
</Field>
<Field data-invalid={!!errors.second_name}>
<FieldLabel htmlFor="second_name">{t("form.secondName.title")}</FieldLabel>
<Input
id="second_name"
type="text"
disabled={isSubmitting}
aria-invalid={!!errors.second_name}
{...register("second_name", {
required: t("form.required"),
minLength: { value: 2, message: t("form.secondName.minLength") },
maxLength: { value: 64, message: t("form.secondName.maxLength") },
})}
/>
{errors.second_name && <FieldError>{errors.second_name.message}</FieldError>}
</Field>
<Field data-invalid={!!errors.birth_date}>
<FieldLabel htmlFor="birth_date">{t("form.birthdate.title")}</FieldLabel>
<Controller
name="birth_date"
control={control}
render={({ field }) => (
<BirthdatePicker
value={field.value}
onChange={field.onChange}
disabled={isSubmitting}
aria-invalid={!!errors.birth_date}
/>
)}
/>
{errors.birth_date && <FieldError>{errors.birth_date.message}</FieldError>}
</Field>
<Field>
<Button type="submit" disabled={isSubmitting}>
{isSubmitting && <Spinner />}
{t("form.save")}
</Button>
{error && <FieldError className="text-center">{error}</FieldError>}
</Field>
</FieldGroup>
</form>
</div>
);
}
+16
View File
@@ -0,0 +1,16 @@
import { GetUser } from "@/actions/auth";
import { redirect } from "next/navigation";
import MeComponent from "./component";
import { getConsents } from "@/actions/consents";
export default async function Me() {
const user = await GetUser();
if (!user) {
redirect("/api/auth/initiate");
}
var consents = await getConsents();
return <MeComponent userData={user} consentsData={consents} />;
}