diff --git a/src/app/profile/[id]/page.tsx b/src/app/profile/[id]/page.tsx index 67ecf34..91c898e 100644 --- a/src/app/profile/[id]/page.tsx +++ b/src/app/profile/[id]/page.tsx @@ -1,13 +1,10 @@ import { Metadata } from "next"; import { redirect } from "next/navigation"; -import Image from "next/image"; -import Link from "next/link"; - -import { Icon } from "@iconify/react"; import { auth } from "@/lib/auth"; import { prisma } from "@/lib/prisma"; +import ProfileInformation from "@/components/profile-information"; import MiiList from "@/components/mii-list"; interface Props { @@ -78,54 +75,9 @@ export default async function ProfilePage({ params }: Props) { if (!user) redirect("/404"); - const likedMiis = await prisma.like.count({ where: { userId: Number(id) } }); - return (
-
- profile picture - -
-

- {user?.name} - {user.id === Number(process.env.NEXT_PUBLIC_ADMIN_USER_ID) && ( -
- -
- )} -

-

@{user?.username}

- -

- Liked {likedMiis} Miis -

-

- Created: {user?.createdAt.toLocaleDateString("en-GB", { month: "long", day: "2-digit", year: "numeric" })} -

-
- -
- {Number(session?.user.id) === Number(process.env.NEXT_PUBLIC_ADMIN_USER_ID) && ( - - - Admin - - )} - {session?.user.id == id && ( - - - Settings - - )} -
-
- +
); diff --git a/src/app/profile/settings/page.tsx b/src/app/profile/settings/page.tsx index e5e056f..6728f74 100644 --- a/src/app/profile/settings/page.tsx +++ b/src/app/profile/settings/page.tsx @@ -9,6 +9,7 @@ import { auth } from "@/lib/auth"; import { prisma } from "@/lib/prisma"; import ProfileSettings from "@/components/profile-settings"; +import ProfileInformation from "@/components/profile-information"; export const metadata: Metadata = { title: "Profile Settings - TomodachiShare", @@ -25,44 +26,10 @@ export default async function ProfileSettingsPage() { if (!session) redirect("/login"); const userExtra = await prisma.user.findUnique({ where: { id: Number(session.user.id) } }); - const likedMiis = await prisma.like.count({ where: { userId: Number(session.user.id) } }); return (
-
- profile picture - -
-

- {session.user.name} - {Number(session.user.id) === Number(process.env.NEXT_PUBLIC_ADMIN_USER_ID) && ( -
- -
- )} -

-

@{session.user.username}

- -

- Liked {likedMiis} Miis -

-

- Created: {userExtra!.createdAt.toLocaleDateString("en-GB", { month: "long", day: "2-digit", year: "numeric" })} -

- - - - Back - -
-
- +
); diff --git a/src/components/profile-information.tsx b/src/components/profile-information.tsx new file mode 100644 index 0000000..4eab2f9 --- /dev/null +++ b/src/components/profile-information.tsx @@ -0,0 +1,78 @@ +import Image from "next/image"; +import { User } from "@prisma/client"; +import { Icon } from "@iconify/react"; + +import { auth } from "@/lib/auth"; +import { prisma } from "@/lib/prisma"; +import Link from "next/link"; + +interface Props { + user?: User; + createdAt: Date; + inSettings?: boolean; +} + +export default async function ProfileInformation({ user: userData, createdAt, inSettings }: Props) { + const session = await auth(); + + const id = userData && userData.id ? userData.id : Number(session?.user.id); + const user = userData ? userData : session?.user; + + const likedMiis = await prisma.like.count({ where: { userId: id } }); + + return ( +
+
+ {/* Profile picture */} + profile picture + {/* User information */} +
+

+ {user?.name} + {id === Number(process.env.NEXT_PUBLIC_ADMIN_USER_ID) && ( +
+ +
+ )} +

+

@{user?.username}

+ +

+ Liked {likedMiis} Miis +

+

+ Created: {createdAt.toLocaleDateString("en-GB", { month: "long", day: "2-digit", year: "numeric" })} +

+
+
+ + {/* Buttons */} +
+ {Number(session?.user.id) == id && Number(session?.user.id) === Number(process.env.NEXT_PUBLIC_ADMIN_USER_ID) && ( + + + Admin + + )} + {!inSettings && Number(session?.user.id) == id && ( + + + Settings + + )} + {inSettings && ( + + + Back + + )} +
+
+ ); +}