2023-06-15 12:52:46 +03:00
|
|
|
/* eslint-disable */
|
2023-06-06 18:32:48 +03:00
|
|
|
"use client";
|
2023-06-06 20:07:54 +03:00
|
|
|
import Link from "next/link";
|
2023-06-05 18:58:59 +03:00
|
|
|
import prettyBytes from "pretty-bytes";
|
2023-06-06 18:32:48 +03:00
|
|
|
import { HTMLAttributes } from "react";
|
2023-08-07 15:13:41 +03:00
|
|
|
import { useTranslation } from "react-i18next";
|
2023-06-15 12:52:46 +03:00
|
|
|
|
|
|
|
import Button from "@/lib/components/ui/Button";
|
|
|
|
import { UserStats } from "@/lib/types/User";
|
|
|
|
import { cn } from "@/lib/utils";
|
|
|
|
|
2023-07-26 00:12:46 +03:00
|
|
|
import { ApiKeyConfig } from "./ApiKeyConfig";
|
2023-06-05 18:58:59 +03:00
|
|
|
import { BrainConsumption } from "./BrainConsumption";
|
|
|
|
import { DateComponent } from "./Date";
|
2023-06-06 18:32:48 +03:00
|
|
|
import BrainSpaceChart from "./Graphs/BrainSpaceChart";
|
|
|
|
import { RequestsPerDayChart } from "./Graphs/RequestsPerDayChart";
|
2023-06-05 18:58:59 +03:00
|
|
|
|
|
|
|
export const UserStatistics = (userStats: UserStats): JSX.Element => {
|
2023-06-06 18:32:48 +03:00
|
|
|
const { email, current_brain_size, max_brain_size, date, requests_stats } =
|
|
|
|
userStats;
|
2023-08-21 15:05:13 +03:00
|
|
|
const { t } = useTranslation(["translation", "user"]);
|
2023-06-15 12:52:46 +03:00
|
|
|
|
2023-06-05 18:58:59 +03:00
|
|
|
return (
|
2023-06-06 18:32:48 +03:00
|
|
|
<>
|
|
|
|
<div className="flex flex-col sm:flex-row sm:items-center py-10 gap-5">
|
2023-06-06 20:07:54 +03:00
|
|
|
<div className="flex-1 flex flex-col">
|
2023-06-06 18:32:48 +03:00
|
|
|
<h1 className="text-4xl font-semibold">
|
2023-08-21 15:05:13 +03:00
|
|
|
{t("title", { user: email.split("@")[0], ns: "user" })}
|
2023-06-06 18:32:48 +03:00
|
|
|
</h1>
|
|
|
|
<p className="opacity-50">{email}</p>
|
2023-06-06 20:07:54 +03:00
|
|
|
<Link className="mt-2" href={"/logout"}>
|
|
|
|
<Button className="px-3 py-2" variant={"danger"}>
|
2023-08-07 15:13:41 +03:00
|
|
|
{t("logoutButton")}
|
2023-06-06 20:07:54 +03:00
|
|
|
</Button>
|
|
|
|
</Link>
|
2023-06-06 18:32:48 +03:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<BrainConsumption {...userStats} />
|
|
|
|
</div>
|
|
|
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-5">
|
|
|
|
<UserStatisticsCard className="">
|
|
|
|
<div>
|
|
|
|
<h1 className="text-2xl font-semibold">
|
|
|
|
{/* The last element corresponds to today's request_count */}
|
2023-08-21 15:05:13 +03:00
|
|
|
{t("requestsCount", {
|
|
|
|
count: requests_stats.at(-1)?.daily_requests_count,
|
|
|
|
ns: "user",
|
|
|
|
})}
|
2023-06-06 18:32:48 +03:00
|
|
|
</h1>
|
|
|
|
<DateComponent date={date} />
|
|
|
|
</div>
|
|
|
|
<div className="">
|
2023-06-05 18:58:59 +03:00
|
|
|
<RequestsPerDayChart {...userStats} />
|
|
|
|
</div>
|
2023-06-06 18:32:48 +03:00
|
|
|
</UserStatisticsCard>
|
|
|
|
|
|
|
|
<UserStatisticsCard>
|
|
|
|
<div>
|
2023-08-21 15:05:13 +03:00
|
|
|
<h1 className="text-2xl font-semibold">
|
|
|
|
{t("brainSize", { ns: "user" })}
|
|
|
|
</h1>
|
2023-06-06 18:32:48 +03:00
|
|
|
<p>
|
|
|
|
{/* How much brain space is left */}
|
|
|
|
{prettyBytes(max_brain_size - current_brain_size, {
|
|
|
|
binary: true,
|
|
|
|
})}
|
|
|
|
/{prettyBytes(max_brain_size - 0, { binary: true })}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div className="">
|
|
|
|
<BrainSpaceChart
|
|
|
|
current_brain_size={current_brain_size}
|
|
|
|
max_brain_size={max_brain_size}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</UserStatisticsCard>
|
|
|
|
</div>
|
2023-07-26 00:12:46 +03:00
|
|
|
<ApiKeyConfig />
|
2023-06-06 18:32:48 +03:00
|
|
|
</>
|
2023-06-05 18:58:59 +03:00
|
|
|
);
|
|
|
|
};
|
2023-06-06 18:32:48 +03:00
|
|
|
|
|
|
|
const UserStatisticsCard = ({
|
|
|
|
children,
|
|
|
|
className,
|
|
|
|
}: HTMLAttributes<HTMLDivElement>) => {
|
|
|
|
return (
|
|
|
|
<div className={cn("w-full h-full flex flex-col gap-5", className)}>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default UserStatistics;
|