mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-08-28 14:18:04 -05:00
Fix updating secondary team avatar/banner not possible Closes #1888
This commit is contained in:
@@ -34,7 +34,7 @@ export const action = async ({ request }: ActionFunctionArgs) => {
|
||||
|
||||
const team =
|
||||
validatedType === "team-pfp" || validatedType === "team-banner"
|
||||
? await validatedTeam(user)
|
||||
? await validatedTeam({ user, request })
|
||||
: undefined;
|
||||
const organization =
|
||||
validatedType === "org-pfp"
|
||||
@@ -87,10 +87,21 @@ export const action = async ({ request }: ActionFunctionArgs) => {
|
||||
return null;
|
||||
};
|
||||
|
||||
async function validatedTeam(user: { id: number }) {
|
||||
const team = await TeamRepository.findMainByUserId(user.id);
|
||||
async function validatedTeam({
|
||||
user,
|
||||
request,
|
||||
}: { user: { id: number }; request: Request }) {
|
||||
const { team: teamCustomUrl } = parseSearchParams({
|
||||
request,
|
||||
schema: z.object({ team: z.string() }),
|
||||
});
|
||||
const team = await TeamRepository.findByCustomUrl(teamCustomUrl);
|
||||
|
||||
validate(team, "You must be on a team to upload images");
|
||||
validate(
|
||||
team.members.some((member) => member.id === user.id && member.isOwner),
|
||||
"You must be on the team to upload images",
|
||||
);
|
||||
const detailedTeam = await TeamRepository.findByCustomUrl(team.customUrl);
|
||||
validate(
|
||||
detailedTeam && isTeamOwner({ team: detailedTeam, user }),
|
||||
|
||||
@@ -27,8 +27,14 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
|
||||
}
|
||||
|
||||
if (validatedType === "team-pfp" || validatedType === "team-banner") {
|
||||
const team = await TeamRepository.findMainByUserId(user.id);
|
||||
if (!team) throw redirect("/");
|
||||
const teamCustomUrl = new URL(request.url).searchParams.get("team") ?? "";
|
||||
const team = await TeamRepository.findByCustomUrl(teamCustomUrl);
|
||||
if (
|
||||
!team ||
|
||||
!team.members.some((member) => member.id === user.id && member.isOwner)
|
||||
) {
|
||||
throw redirect("/");
|
||||
}
|
||||
|
||||
const detailedTeam = await TeamRepository.findByCustomUrl(team.customUrl);
|
||||
|
||||
|
||||
@@ -31,21 +31,6 @@ export function findAllUndisbanded() {
|
||||
.execute();
|
||||
}
|
||||
|
||||
export function findMainByUserId(userId: number) {
|
||||
return db
|
||||
.selectFrom("TeamMember")
|
||||
.innerJoin("Team", "Team.id", "TeamMember.teamId")
|
||||
.leftJoin("UserSubmittedImage", "UserSubmittedImage.id", "Team.avatarImgId")
|
||||
.select([
|
||||
"Team.id",
|
||||
"Team.customUrl",
|
||||
"Team.name",
|
||||
"UserSubmittedImage.url as logoUrl",
|
||||
])
|
||||
.where("TeamMember.userId", "=", userId)
|
||||
.executeTakeFirst();
|
||||
}
|
||||
|
||||
export function findAllMemberOfByUserId(userId: number) {
|
||||
return db
|
||||
.selectFrom("TeamMemberWithSecondary")
|
||||
|
||||
@@ -174,17 +174,29 @@ export default function EditTeamPage() {
|
||||
|
||||
function ImageUploadLinks() {
|
||||
const { t } = useTranslation(["team"]);
|
||||
const { team } = useLoaderData<typeof loader>();
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Label>{t("team:forms.fields.uploadImages")}</Label>
|
||||
<ol className="team__image-links-list">
|
||||
<li>
|
||||
<Link to={uploadImagePage({ type: "team-pfp" })}>
|
||||
<Link
|
||||
to={uploadImagePage({
|
||||
type: "team-pfp",
|
||||
teamCustomUrl: team.customUrl,
|
||||
})}
|
||||
>
|
||||
{t("team:forms.fields.uploadImages.pfp")}
|
||||
</Link>
|
||||
</li>
|
||||
<li>
|
||||
<Link to={uploadImagePage({ type: "team-banner" })}>
|
||||
<Link
|
||||
to={uploadImagePage({
|
||||
type: "team-banner",
|
||||
teamCustomUrl: team.customUrl,
|
||||
})}
|
||||
>
|
||||
{t("team:forms.fields.uploadImages.banner")}
|
||||
</Link>
|
||||
</li>
|
||||
|
||||
@@ -347,12 +347,12 @@ export const objectDamageCalculatorPage = (weaponId?: MainWeaponId) =>
|
||||
|
||||
export const uploadImagePage = (
|
||||
args:
|
||||
| { type: "team-pfp" | "team-banner" }
|
||||
| { type: "team-pfp" | "team-banner"; teamCustomUrl: string }
|
||||
| { type: "org-pfp"; slug: string },
|
||||
) =>
|
||||
args.type === "org-pfp"
|
||||
? `/upload?type=${args.type}&slug=${args.slug}`
|
||||
: `/upload?type=${args.type}`;
|
||||
: `/upload?type=${args.type}&team=${args.teamCustomUrl}`;
|
||||
|
||||
export const vodVideoPage = (videoId: number) => `${VODS_PAGE}/${videoId}`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user