forked from Transparency/kgroad-frontend2
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import Typography from "@/shared/ui/components/Typography/Typography";
|
|
import "./Profile.scss";
|
|
import ProfileNav from "@/widgets/ProfileNav/ProfileNav";
|
|
import AuthGuard from "./AuthGuard";
|
|
import { AxiosError } from "axios";
|
|
import { apiInstance } from "@/shared/config/apiConfig";
|
|
import { getServerSession } from "next-auth";
|
|
import { authConfig } from "@/shared/config/authConfig";
|
|
import { Metadata } from "next";
|
|
import BreadCrumbs from "@/features/BreadCrumbs/BreadCrumbs";
|
|
|
|
export const metadata: Metadata = {
|
|
title: "KG ROAD | Профиль",
|
|
description: "Страница профиля KG ROAD",
|
|
};
|
|
|
|
const Profile = async ({
|
|
children,
|
|
}: Readonly<{
|
|
children: React.ReactNode;
|
|
}>) => {
|
|
const session = await getServerSession(authConfig);
|
|
|
|
const getProfile = async () => {
|
|
const Authorization = `Bearer ${session?.access_token}`;
|
|
const config = {
|
|
headers: {
|
|
Authorization,
|
|
},
|
|
};
|
|
try {
|
|
const response = await apiInstance.get<{
|
|
report_count: number;
|
|
}>("/users/profile/", config);
|
|
|
|
return response.data;
|
|
} catch (error: unknown) {
|
|
if (error instanceof AxiosError) console.log(error.message);
|
|
}
|
|
};
|
|
|
|
const data = await getProfile();
|
|
|
|
return (
|
|
<div className="profile page-padding">
|
|
<BreadCrumbs />
|
|
<Typography element="h2">Личный кабинет</Typography>
|
|
<ProfileNav report_count={data?.report_count as number} />
|
|
|
|
<AuthGuard>{children}</AuthGuard>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default Profile;
|