From b49f2434eb9e1ff2f476f96daf78c20af88a6f7b Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Sat, 12 Mar 2022 15:02:11 +0200 Subject: [PATCH] Fix admin score editing --- app/routes/play/match.$id.tsx | 40 +++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/app/routes/play/match.$id.tsx b/app/routes/play/match.$id.tsx index 24503937a..0b5f2e628 100644 --- a/app/routes/play/match.$id.tsx +++ b/app/routes/play/match.$id.tsx @@ -108,9 +108,14 @@ export const action: ActionFunction = async ({ const match = await LFGMatch.findById(params.id); invariant(match, "Match is undefined"); - const ownGroup = match.groups.find((g) => + + let ownGroup = match.groups.find((g) => g.members.some((m) => m.memberId === user.id) ); + if (!ownGroup && isAdmin(user.id)) { + ownGroup = match.groups[0]; + } + validate(ownGroup, "Not own match"); validate(isGroupAdmin({ group: ownGroup, user }), "Not group admin"); @@ -457,20 +462,23 @@ export default function LFGMatchPage() { > {adminEditActive ? "Cancel" : "Edit"} - { - if (!confirm("Delete match?")) { - e.preventDefault(); - } - }} - loadingText="Deleting..." - > - Delete - + {!adminEditActive && ( + { + if (!confirm("Delete match?")) { + e.preventDefault(); + } + }} + loadingText="Deleting..." + > + Delete + + )} )} @@ -503,7 +511,7 @@ export default function LFGMatchPage() { invariant(winnerGroup, "Unexpected winnerGroup is undefined"); return winnerGroup.id; })} - canSubmitScore={data.isCaptain} + canSubmitScore={data.isCaptain || isAdmin(user?.id)} groupIds={{ our: data.groups[0].id, their: data.groups[1].id,