mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-30 07:12:36 -05:00
Friend code to root user
This commit is contained in:
@@ -7,7 +7,11 @@ import { SubmitButton } from "~/components/SubmitButton";
|
||||
import { FRIEND_CODE_REGEXP_PATTERN } from "~/features/sendouq/q-constants";
|
||||
import { SENDOUQ_PAGE } from "~/utils/urls";
|
||||
|
||||
export function FriendCodeInput({ friendCode }: { friendCode?: string }) {
|
||||
export function FriendCodeInput({
|
||||
friendCode,
|
||||
}: {
|
||||
friendCode?: string | null;
|
||||
}) {
|
||||
const fetcher = useFetcher();
|
||||
const { t } = useTranslation(["common"]);
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ const createTeam = (teamId: number, userIds: number[]): TournamentDataTeam => ({
|
||||
discordId: "123",
|
||||
username: "test",
|
||||
inGameName: "test",
|
||||
twitch: null,
|
||||
isOwner: 0,
|
||||
plusTier: null,
|
||||
createdAt: 0,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -17,7 +17,7 @@ import { joinTeam } from "../queries/joinLeaveTeam.server";
|
||||
import { TOURNAMENT } from "../tournament-constants";
|
||||
import { joinSchema } from "../tournament-schemas.server";
|
||||
import { tournamentIdFromParams } from "../tournament-utils";
|
||||
import { useTournamentFriendCode, useTournament } from "./to.$id";
|
||||
import { useTournament } from "./to.$id";
|
||||
import { FriendCodeInput } from "~/components/FriendCodeInput";
|
||||
import * as UserRepository from "~/features/user-page/UserRepository.server";
|
||||
import { tournamentFromDB } from "~/features/tournament-bracket/core/Tournament.server";
|
||||
@@ -64,7 +64,7 @@ export const action: ActionFunction = async ({ request, params }) => {
|
||||
"Cannot join this team or invite code is invalid",
|
||||
);
|
||||
validate(
|
||||
await UserRepository.currentFriendCodeByUserId(user.id),
|
||||
(await UserRepository.findLeanById(user.id))?.friendCode,
|
||||
"No friend code",
|
||||
);
|
||||
|
||||
@@ -123,7 +123,6 @@ export default function JoinTeamPage() {
|
||||
const user = useUser();
|
||||
const tournament = useTournament();
|
||||
const data = useLoaderData<typeof loader>();
|
||||
const friendCode = useTournamentFriendCode();
|
||||
|
||||
const teamToJoin = data.teamId ? tournament.teamById(data.teamId) : undefined;
|
||||
const captain = teamToJoin?.members.find((member) => member.isOwner);
|
||||
@@ -175,7 +174,7 @@ export default function JoinTeamPage() {
|
||||
<div className="text-center text-lg font-semi-bold">{textPrompt()}</div>
|
||||
<div className="stack sm items-center">
|
||||
{validationStatus === "VALID" ? (
|
||||
<FriendCodeInput friendCode={friendCode} />
|
||||
<FriendCodeInput friendCode={user?.friendCode} />
|
||||
) : null}
|
||||
{user?.inGameName ? (
|
||||
<div className="font-bold">
|
||||
@@ -186,10 +185,10 @@ export default function JoinTeamPage() {
|
||||
<Form method="post" className="tournament__invite-container">
|
||||
{validationStatus === "VALID" ? (
|
||||
<div className="stack md items-center">
|
||||
<SubmitButton size="big" disabled={!friendCode}>
|
||||
<SubmitButton size="big" disabled={!user?.friendCode}>
|
||||
{t("common:actions.join")}
|
||||
</SubmitButton>
|
||||
{!friendCode ? (
|
||||
{!user?.friendCode ? (
|
||||
<div className="text-warning">
|
||||
Save friend code before joining the team
|
||||
</div>
|
||||
|
||||
@@ -69,7 +69,7 @@ import {
|
||||
isOneModeTournamentOf,
|
||||
tournamentIdFromParams,
|
||||
} from "../tournament-utils";
|
||||
import { useTournament, useTournamentFriendCode } from "./to.$id";
|
||||
import { useTournament } from "./to.$id";
|
||||
import Markdown from "markdown-to-jsx";
|
||||
import { NewTabs } from "~/components/NewTabs";
|
||||
import { useSearchParamState } from "~/hooks/useSearchParamState";
|
||||
@@ -118,7 +118,7 @@ export const action: ActionFunction = async ({ request, params }) => {
|
||||
} else {
|
||||
validate(!tournament.isInvitational, "Event is invite only");
|
||||
validate(
|
||||
await UserRepository.currentFriendCodeByUserId(user.id),
|
||||
(await UserRepository.findLeanById(user.id))?.friendCode,
|
||||
"No friend code",
|
||||
);
|
||||
validate(
|
||||
@@ -232,7 +232,7 @@ export const action: ActionFunction = async ({ request, params }) => {
|
||||
"No trust given from this user",
|
||||
);
|
||||
validate(
|
||||
await UserRepository.currentFriendCodeByUserId(data.userId),
|
||||
(await UserRepository.findLeanById(user.id))?.friendCode,
|
||||
"No friend code",
|
||||
);
|
||||
validate(tournament.registrationOpen, "Registration is closed");
|
||||
@@ -524,7 +524,6 @@ function RegistrationForms() {
|
||||
const data = useLoaderData<typeof loader>();
|
||||
const user = useUser();
|
||||
const tournament = useTournament();
|
||||
const friendCode = useTournamentFriendCode();
|
||||
|
||||
const ownTeam = tournament.ownedTeamByUser(user);
|
||||
const ownTeamCheckedIn = Boolean(ownTeam && ownTeam.checkIns.length > 0);
|
||||
@@ -564,7 +563,7 @@ function RegistrationForms() {
|
||||
{showRegisterNewTeam() ? (
|
||||
<>
|
||||
<FriendCode />
|
||||
{friendCode ? (
|
||||
{user?.friendCode ? (
|
||||
<TeamInfo
|
||||
name={ownTeam?.name}
|
||||
prefersNotToHost={ownTeam?.prefersNotToHost}
|
||||
@@ -905,17 +904,17 @@ function TeamInfo({
|
||||
}
|
||||
|
||||
function FriendCode() {
|
||||
const friendCode = useTournamentFriendCode();
|
||||
const user = useUser();
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h3 className="tournament__section-header">1. Friend code</h3>
|
||||
<section className="tournament__section">
|
||||
<div className="tournament__section__input-container mx-auto">
|
||||
<FriendCodeInput friendCode={friendCode} />
|
||||
<FriendCodeInput friendCode={user?.friendCode} />
|
||||
</div>
|
||||
</section>
|
||||
{friendCode ? (
|
||||
{user?.friendCode ? (
|
||||
<div className="tournament__section__warning">
|
||||
Is the friend code above wrong? Contact Sendou directly to change it.
|
||||
</div>
|
||||
|
||||
@@ -26,7 +26,6 @@ import {
|
||||
HACKY_resolvePicture,
|
||||
tournamentIdFromParams,
|
||||
} from "../tournament-utils";
|
||||
import * as UserRepository from "~/features/user-page/UserRepository.server";
|
||||
import * as TournamentRepository from "~/features/tournament/TournamentRepository.server";
|
||||
import { databaseTimestampToDate } from "~/utils/dates";
|
||||
import { isAdmin } from "~/permissions";
|
||||
@@ -135,9 +134,6 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {
|
||||
tournament,
|
||||
streamingParticipants: streams.flatMap((s) => (s.userId ? [s.userId] : [])),
|
||||
streamsCount: streams.length,
|
||||
friendCode: user
|
||||
? await UserRepository.currentFriendCodeByUserId(user.id)
|
||||
: undefined,
|
||||
friendCodes: showFriendCodes
|
||||
? await TournamentRepository.friendCodesByTournamentId(tournamentId)
|
||||
: undefined,
|
||||
@@ -231,7 +227,6 @@ export default function TournamentLayout() {
|
||||
bracketExpanded,
|
||||
setBracketExpanded,
|
||||
streamingParticipants: data.streamingParticipants,
|
||||
friendCode: data.friendCode?.friendCode,
|
||||
friendCodes: data.friendCodes,
|
||||
} satisfies TournamentContext
|
||||
}
|
||||
@@ -265,10 +260,6 @@ export function useStreamingParticipants() {
|
||||
return useOutletContext<TournamentContext>().streamingParticipants;
|
||||
}
|
||||
|
||||
export function useTournamentFriendCode() {
|
||||
return useOutletContext<TournamentContext>().friendCode;
|
||||
}
|
||||
|
||||
export function useTournamentFriendCodes() {
|
||||
return useOutletContext<TournamentContext>().friendCodes;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ export function findLeanById(id: number) {
|
||||
.selectFrom("User")
|
||||
.leftJoin("PlusTier", "PlusTier.userId", "User.id")
|
||||
.where("User.id", "=", id)
|
||||
.select([
|
||||
.select(({ eb }) => [
|
||||
...COMMON_USER_FIELDS,
|
||||
"User.isArtist",
|
||||
"User.isVideoAdder",
|
||||
@@ -102,6 +102,13 @@ export function findLeanById(id: number) {
|
||||
"User.languages",
|
||||
"User.inGameName",
|
||||
"PlusTier.tier as plusTier",
|
||||
eb
|
||||
.selectFrom("UserFriendCode")
|
||||
.select("UserFriendCode.friendCode")
|
||||
.where("UserFriendCode.userId", "=", id)
|
||||
.orderBy("UserFriendCode.createdAt", "desc")
|
||||
.limit(1)
|
||||
.as("friendCode"),
|
||||
])
|
||||
.executeTakeFirst();
|
||||
}
|
||||
|
||||
@@ -122,6 +122,7 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
|
||||
isArtist: user.isArtist,
|
||||
isVideoAdder: user.isVideoAdder,
|
||||
inGameName: user.inGameName,
|
||||
friendCode: user.friendCode,
|
||||
languages: user.languages ? user.languages.split(",") : [],
|
||||
}
|
||||
: undefined,
|
||||
|
||||
7
migrations/061-fc-index.js
Normal file
7
migrations/061-fc-index.js
Normal file
@@ -0,0 +1,7 @@
|
||||
export function up(db) {
|
||||
db.transaction(() => {
|
||||
db.prepare(
|
||||
/* sql */ `create index user_friend_code_user_id on "UserFriendCode"("userId")`,
|
||||
).run();
|
||||
})();
|
||||
}
|
||||
Reference in New Issue
Block a user