|
1 | 1 | import Link from "next/link" |
| 2 | +import { notFound } from "next/navigation" |
2 | 3 |
|
| 4 | +import { getUser } from "database" |
3 | 5 | import { getTranslations } from "next-intl/server" |
4 | 6 | import { Avatar, AvatarFallback, AvatarImage, Card, CardContent, CardHeader, Typography } from "ui" |
5 | 7 |
|
6 | | -import APP_APIS from "@/constants/apis" |
7 | | -import { TUserItem } from "@/types/users" |
8 | | -import { generatePath } from "@/utils/generatePath" |
9 | | - |
10 | 8 | import FollowButton from "./follow-button" |
11 | 9 |
|
12 | 10 | export type UserProfileProps = { |
13 | 11 | authorId: string |
14 | 12 | } |
15 | 13 |
|
16 | 14 | export async function UserProfile({ authorId }: UserProfileProps) { |
17 | | - // const rawAuthor = await fetch( |
18 | | - // `${process.env.NEXT_PUBLIC_FRONTEND_URL}${generatePath(APP_APIS.protected.user.GET, { |
19 | | - // userId: authorId, |
20 | | - // })}`, |
21 | | - // { |
22 | | - // method: "GET", |
23 | | - // cache: "no-cache", |
24 | | - // headers: { |
25 | | - // "Content-Type": "application/json", |
26 | | - // }, |
27 | | - // } |
28 | | - // ) |
29 | | - const author: TUserItem = await rawAuthor?.json() |
30 | 15 | const t = await getTranslations() |
| 16 | + const { data: author, error } = await getUser({ userId: authorId }) |
| 17 | + |
| 18 | + if (error) { |
| 19 | + return notFound() |
| 20 | + } |
31 | 21 |
|
32 | 22 | return ( |
33 | 23 | <div className="col-span-4"> |
@@ -58,13 +48,13 @@ export async function UserProfile({ authorId }: UserProfileProps) { |
58 | 48 | </Typography> |
59 | 49 | <div className="mt-4 flex w-full flex-1 divide-x"> |
60 | 50 | <div className="flex flex-1 flex-col items-center justify-center"> |
61 | | - <div className="font-bold">{author?._count?.post}</div> |
| 51 | + <div className="font-bold">{author?.totalPost}</div> |
62 | 52 | <div className="hover:underline"> |
63 | 53 | <Link href={`/author/${author?.id}`}>{t("common.posts")}</Link> |
64 | 54 | </div> |
65 | 55 | </div> |
66 | 56 | <div className="flex flex-1 flex-col items-center justify-center"> |
67 | | - <div className="font-bold">{author?._count?.followers}</div> |
| 57 | + <div className="font-bold">{author?.totalFollower}</div> |
68 | 58 | <div className="hover:underline"> |
69 | 59 | <Link href={`/author/${author?.id}/followers`}>{t("common.followers")}</Link> |
70 | 60 | </div> |
|
0 commit comments