Add friend codes to user admin tab

This commit is contained in:
Kalle
2025-10-28 19:35:31 +02:00
parent d6b0e2aa0b
commit 8dc22fcce4
3 changed files with 55 additions and 0 deletions

View File

@@ -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<string> | null = null;
export async function allCurrentFriendCodes() {

View File

@@ -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,
};
};

View File

@@ -21,6 +21,14 @@ export default function UserAdminPage() {
return (
<Main className="stack xl">
<AccountInfos />
<div className="stack sm">
<Divider smallText className="font-bold">
Friend codes
</Divider>
<FriendCodes />
</div>
<div className="stack sm">
<Divider smallText className="font-bold">
Mod notes
@@ -229,3 +237,32 @@ function BanLog() {
</div>
);
}
function FriendCodes() {
const data = useLoaderData<typeof loader>();
if (!data.friendCodes || data.friendCodes.length === 0) {
return <p className="text-center text-lighter italic">No friend codes</p>;
}
return (
<div className="stack lg">
{data.friendCodes.map((fc, index) => (
<div key={fc.createdAt}>
<p className="font-bold">{fc.friendCode}</p>
<p className="ml-2">
{index === 0 ? "Current" : "Past"} - Added on{" "}
{databaseTimestampToDate(fc.createdAt).toLocaleString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
hour: "2-digit",
minute: "2-digit",
})}
</p>
<p className="ml-2">Submitted by: {fc.submitterUsername}</p>
</div>
))}
</div>
);
}