|
| 1 | +import authOptions from "@/app/api/auth/[...nextauth]/authOptions"; |
| 2 | +import GridList from "@/components/GridList"; |
| 3 | +import List from "@/components/List"; |
| 4 | +import AchievementTile from "@/components/user/AchievementTile"; |
| 5 | +import CurriculumVitae from "@/components/user/CurriculumVitae"; |
| 6 | +import ProfileHeader from "@/components/user/ProfileHeader"; |
| 7 | +import ProfileInformations from "@/components/user/ProfileInformations"; |
| 8 | +import { AchievementService } from "@/services/AchievementService"; |
| 9 | +import { UserService } from "@/services/UserService"; |
| 10 | +import { isCompany, isMember } from "@/utils/utils"; |
| 11 | +import { UserPlus } from "lucide-react"; |
| 12 | +import { getServerSession } from "next-auth"; |
| 13 | +import DemoteButton from "./DemoteButton"; |
| 14 | + |
| 15 | +interface UserProfileParams { |
| 16 | + id: string; |
| 17 | +} |
| 18 | + |
| 19 | +export default async function UserProfile({ |
| 20 | + params, |
| 21 | +}: { |
| 22 | + params: UserProfileParams; |
| 23 | +}) { |
| 24 | + const { id: userID } = params; |
| 25 | + |
| 26 | + const session = (await getServerSession(authOptions))!; |
| 27 | + const user: User | null = await UserService.getMe(session.cannonToken); |
| 28 | + if (!user) return; |
| 29 | + |
| 30 | + const userProfile = await UserService.getUser(session.cannonToken, userID); |
| 31 | + if (!userProfile) return <div>User not found.</div>; |
| 32 | + |
| 33 | + const isMyself = userProfile.id === user.id; |
| 34 | + |
| 35 | + const achievements = await AchievementService.getAchievements(); |
| 36 | + const userAchievements = achievements?.filter((a) => |
| 37 | + a.users?.includes(userProfile.id), |
| 38 | + ); |
| 39 | + |
| 40 | + return ( |
| 41 | + <div className="container m-auto h-full"> |
| 42 | + <ProfileHeader user={userProfile} /> |
| 43 | + {!isMyself && ( |
| 44 | + <div className="px-4 py-2"> |
| 45 | + <button className="button-primary text-sm w-full mt-2"> |
| 46 | + <UserPlus size={16} /> |
| 47 | + Connect |
| 48 | + </button> |
| 49 | + {isMember(user.role) && |
| 50 | + (isMember(userProfile.role) || isCompany(userProfile.role)) && ( |
| 51 | + <DemoteButton |
| 52 | + cannonToken={session.cannonToken} |
| 53 | + userId={userProfile.id} |
| 54 | + /> |
| 55 | + )} |
| 56 | + </div> |
| 57 | + )} |
| 58 | + |
| 59 | + {/* Notes */} |
| 60 | + {/* <List title="Notes"> |
| 61 | + {userNotes && userNotes.trim() !== "" ? ( |
| 62 | + <ShowMore lines={3}> |
| 63 | + Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do |
| 64 | + eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim |
| 65 | + ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut |
| 66 | + aliquip ex ea commodo consequat. Duis aute irure dolor in |
| 67 | + reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla |
| 68 | + pariatur. Excepteur sint occaecat cupidatat non proident, sunt in |
| 69 | + culpa qui officia deserunt mollit anim id est laborum. |
| 70 | + </ShowMore> |
| 71 | + ) : ( |
| 72 | + <ListCard title="Write a note" icon={NotebookPen} /> |
| 73 | + )} |
| 74 | + </List> */} |
| 75 | + |
| 76 | + {!isCompany(userProfile.role) && |
| 77 | + (isCompany(user.role) || isMember(user.role)) && ( |
| 78 | + <List title="Curriculum Vitae (CV)"> |
| 79 | + <CurriculumVitae user={userProfile} session={session} /> |
| 80 | + </List> |
| 81 | + )} |
| 82 | + |
| 83 | + {/* User information */} |
| 84 | + <ProfileInformations user={userProfile} /> |
| 85 | + |
| 86 | + {/* Achievements */} |
| 87 | + {userAchievements?.length ? ( |
| 88 | + <GridList |
| 89 | + title="Achievements" |
| 90 | + description={`Total points: ${userAchievements?.reduce((acc, a) => acc + a.value, 0) || 0}`} |
| 91 | + scrollable |
| 92 | + > |
| 93 | + {userAchievements.map((a) => ( |
| 94 | + <AchievementTile key={a.id} achievement={a} achieved /> |
| 95 | + ))} |
| 96 | + </GridList> |
| 97 | + ) : ( |
| 98 | + <></> |
| 99 | + )} |
| 100 | + </div> |
| 101 | + ); |
| 102 | +} |
0 commit comments