diff --git a/services/frontend/src/pages/Profile/components/user-stat-block.tsx b/services/frontend/src/pages/Profile/components/user-stat-block.tsx new file mode 100644 index 0000000..3fec3af --- /dev/null +++ b/services/frontend/src/pages/Profile/components/user-stat-block.tsx @@ -0,0 +1,14 @@ +export const UserStatBlock = ({ + value, + description, +}: { + value: number; + description: string; +}) => { + return ( +
+

{value}

+

{description}

+
+ ); +}; diff --git a/services/frontend/src/pages/Profile/index.tsx b/services/frontend/src/pages/Profile/index.tsx index 75cd2ff..d9b61c1 100644 --- a/services/frontend/src/pages/Profile/index.tsx +++ b/services/frontend/src/pages/Profile/index.tsx @@ -1,6 +1,6 @@ import { UserInfo } from "./widgets/user-info"; import { UserAchievements } from "./widgets/user-achievements"; -import { UserStats } from "./widgets/user-stats"; +import { UserStatsSections } from "./widgets/user-stats"; import { useQuery } from "@tanstack/react-query"; import { getCurrentUser } from "@/shared/api/user"; import { Loading } from "@/components/ui/loading"; @@ -25,11 +25,11 @@ const ProfilePage = () => { return (
-
+
- +
); }; diff --git a/services/frontend/src/pages/Profile/widgets/user-achievements.tsx b/services/frontend/src/pages/Profile/widgets/user-achievements.tsx index decd815..8231fbf 100644 --- a/services/frontend/src/pages/Profile/widgets/user-achievements.tsx +++ b/services/frontend/src/pages/Profile/widgets/user-achievements.tsx @@ -11,7 +11,7 @@ export const UserAchievements = ({

Достижения

{achievements && ( -
+
{achievements.map((a) => ( diff --git a/services/frontend/src/pages/Profile/widgets/user-info.tsx b/services/frontend/src/pages/Profile/widgets/user-info.tsx index 3b3b927..808619b 100644 --- a/services/frontend/src/pages/Profile/widgets/user-info.tsx +++ b/services/frontend/src/pages/Profile/widgets/user-info.tsx @@ -2,7 +2,7 @@ import { User } from "@/shared/types/user"; export const UserInfo = ({ user }: { user: User }) => { return ( -
+
{user.avatar && (
{ +import { Loading } from "@/components/ui/loading"; +import { UserStatBlock } from "../components/user-stat-block"; +import { getCurrentUserStats } from "@/shared/api/user"; +import { useQuery } from "@tanstack/react-query"; + +export const UserStatsSections = () => { + const { data: stats, isLoading } = useQuery({ + queryKey: ["user-stats"], + queryFn: getCurrentUserStats, + }); + return ( -
+

Аналитика

-
+ {isLoading ? ( +
+ +
+ ) : stats ? ( +
+ + +
+ ) : ( +
+

+ Что-то пошло не так 😔 +

+
+ )} +
); }; diff --git a/services/frontend/src/shared/api/user.ts b/services/frontend/src/shared/api/user.ts index 84b000d..7640390 100644 --- a/services/frontend/src/shared/api/user.ts +++ b/services/frontend/src/shared/api/user.ts @@ -1,6 +1,10 @@ import { userFetch } from "."; -import { User } from "../types/user"; +import { User, UserStats } from "../types/user"; export const getCurrentUser = async () => { return await userFetch("/me"); }; + +export const getCurrentUserStats = async () => { + return await userFetch("/me/stat"); +}; diff --git a/services/frontend/src/shared/types/user.ts b/services/frontend/src/shared/types/user.ts index 650c8d8..b9e927f 100644 --- a/services/frontend/src/shared/types/user.ts +++ b/services/frontend/src/shared/types/user.ts @@ -12,3 +12,8 @@ export interface Achievement { received_at: Date; icon?: string; } + +export interface UserStats { + total_attempts: number; + solved_tasks: number; +}