diff --git a/app/features/user-page/UserRepository.server.ts b/app/features/user-page/UserRepository.server.ts index 459114d96..50edbc91d 100644 --- a/app/features/user-page/UserRepository.server.ts +++ b/app/features/user-page/UserRepository.server.ts @@ -762,6 +762,21 @@ export async function currentFriendCodeByUserId(userId: number) { .executeTakeFirst(); } +/** Returns all friend codes submitted by a user (both present and past) */ +export async function friendCodesByUserId(userId: number) { + return db + .selectFrom("UserFriendCode") + .leftJoin("User", "User.id", "UserFriendCode.submitterUserId") + .select([ + "UserFriendCode.friendCode", + "UserFriendCode.createdAt", + "User.username as submitterUsername", + ]) + .where("UserFriendCode.userId", "=", userId) + .orderBy("UserFriendCode.createdAt", "desc") + .execute(); +} + let cachedFriendCodes: Set | null = null; export async function allCurrentFriendCodes() { diff --git a/app/features/user-page/loaders/u.$identifier.admin.server.ts b/app/features/user-page/loaders/u.$identifier.admin.server.ts index 03b97fc1f..d29c9d393 100644 --- a/app/features/user-page/loaders/u.$identifier.admin.server.ts +++ b/app/features/user-page/loaders/u.$identifier.admin.server.ts @@ -23,9 +23,12 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => { await UserRepository.findModInfoById(user.id), ); + const friendCodes = await UserRepository.friendCodesByUserId(user.id); + return { ...userData, discordId: user.discordId, discordAccountCreatedAt: convertSnowflakeToDate(user.discordId).getTime(), + friendCodes, }; }; diff --git a/app/features/user-page/routes/u.$identifier.admin.tsx b/app/features/user-page/routes/u.$identifier.admin.tsx index 0f276c206..2f6b6d008 100644 --- a/app/features/user-page/routes/u.$identifier.admin.tsx +++ b/app/features/user-page/routes/u.$identifier.admin.tsx @@ -21,6 +21,14 @@ export default function UserAdminPage() { return (
+ +
+ + Friend codes + + +
+
Mod notes @@ -229,3 +237,32 @@ function BanLog() {
); } + +function FriendCodes() { + const data = useLoaderData(); + + if (!data.friendCodes || data.friendCodes.length === 0) { + return

No friend codes

; + } + + return ( +
+ {data.friendCodes.map((fc, index) => ( +
+

{fc.friendCode}

+

+ {index === 0 ? "Current" : "Past"} - Added on{" "} + {databaseTimestampToDate(fc.createdAt).toLocaleString("en-US", { + year: "numeric", + month: "long", + day: "numeric", + hour: "2-digit", + minute: "2-digit", + })} +

+

Submitted by: {fc.submitterUsername}

+
+ ))} +
+ ); +}