mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-08-26 04:57:08 -05:00
Add friend codes to user admin tab
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user