import Image from "next/image"; import Link from "next/link"; import { PageLayout } from "@/components/ui/PageLayout"; import { actionGetUserProfileByUsername } from "@/modules/auth/auth-action"; import { repoGetFoldersWithTotalPairsByUserId } from "@/modules/folder/folder-repository"; import { notFound } from "next/navigation"; import { getTranslations } from "next-intl/server"; import { auth } from "@/auth"; import { headers } from "next/headers"; import { LogoutButton } from "@/app/users/[username]/LogoutButton"; interface UserPageProps { params: Promise<{ username: string; }>; } export default async function UserPage({ params }: UserPageProps) { const { username } = await params; const t = await getTranslations("user_profile"); // Get current session const session = await auth.api.getSession({ headers: await headers() }); // Get user profile const result = await actionGetUserProfileByUsername({ username }); if (!result.success || !result.data) { notFound(); } const user = result.data; // Get user's folders const folders = await repoGetFoldersWithTotalPairsByUserId(user.id); // Check if viewing own profile const isOwnProfile = session?.user?.username === username || session?.user?.email === username; return ( {/* Header */}
{isOwnProfile && }
{/* Avatar */} {user.image ? (
{user.displayUsername
) : (
{(user.displayUsername || user.username || user.email)[0].toUpperCase()}
)} {/* User Info */}

{user.displayUsername || user.username || t("anonymous")}

{user.username && (

@{user.username}

)}
Joined: {new Date(user.createdAt).toLocaleDateString()} {user.emailVerified && ( Verified )}
{/* Email Section */}

{t("email")}

{user.email}
{user.emailVerified ? ( ✓ {t("verified")} ) : ( {t("unverified")} )}
{/* Account Info */}

{t("accountInfo")}

{t("userId")}
{user.id}
{t("username")}
{user.username || {t("notSet")}}
{t("displayName")}
{user.displayUsername || {t("notSet")}}
{t("memberSince")}
{new Date(user.createdAt).toLocaleDateString()}
{/* Folders Section */}

{t("folders.title")}

{folders.length === 0 ? (

{t("folders.noFolders")}

) : (
{folders.map((folder) => ( ))}
{t("folders.folderName")} {t("folders.totalPairs")} {t("folders.createdAt")} {t("folders.actions")}
{folder.name}
ID: {folder.id}
{folder.total}
{new Date(folder.createdAt).toLocaleDateString()} {t("folders.view")}
)}
); }