diff --git a/src/components/MatchResultForm/MatchResultForm.tsx b/src/components/MatchResultForm/MatchResultForm.tsx index b34c3e27..cd8844b0 100644 --- a/src/components/MatchResultForm/MatchResultForm.tsx +++ b/src/components/MatchResultForm/MatchResultForm.tsx @@ -65,7 +65,6 @@ export const MatchResultForm = ({ const form = useForm({ defaultValues: { ...defaultValues, - player0UserId: currentUser?._id ?? null, ...existingValues, ...forcedValues, }, diff --git a/src/components/MatchResultForm/components/PlayerField/PlayerField.tsx b/src/components/MatchResultForm/components/PlayerField/PlayerField.tsx index 9d519887..83a616d6 100644 --- a/src/components/MatchResultForm/components/PlayerField/PlayerField.tsx +++ b/src/components/MatchResultForm/components/PlayerField/PlayerField.tsx @@ -63,6 +63,13 @@ export const PlayerField = ({ setPlaceholder(e.target.value); }; + // Automatically set player if possible: + useEffect(() => { + if (competitorUserOptions.length === 1) { + setValue(`player${index}UserId`, competitorUserOptions[0]._id, { shouldDirty: false }); + } + }, [competitorUserOptions, setValue, index]); + // Automatically set bye placeholder if possible: useEffect(() => { if (isBye) { @@ -91,7 +98,8 @@ export const PlayerField = ({ selectedUserRef.current = selectedUser; } - const readOnly = competitorUserOptions.length === 1 || currentUser && !tournamentPairing && userId === currentUser._id || isBye; + const isOwnSingleMatch = !tournamentPairing && currentUser?._id === userId; + const readOnly = (competitorUserOptions.length === 1) || isBye || isOwnSingleMatch; return (