Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/components/MatchResultForm/MatchResultForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ export const MatchResultForm = ({
loading: tournamentPairingsLoading,
} = useGetActiveTournamentPairingsByUser(currentUser ? { userId: currentUser._id } : 'skip');

const singleMatchDefaults = !existingValues && !forcedValues?.tournamentPairingId && currentUser ? {
player0UserId: currentUser._id,
} : {};

const form = useForm<FormData>({
defaultValues: merge({}, defaultValues, existingValues, forcedValues),
defaultValues: merge({}, defaultValues, singleMatchDefaults, existingValues, forcedValues),
mode: 'onSubmit',
});

Expand Down Expand Up @@ -181,11 +185,13 @@ export const MatchResultForm = ({
<MatchResultPlayerFields
className={styles.MatchResultForm_Player0Fields}
index={0}
playerReadOnly={!!existingValues || !tournamentPairingId}
tournamentPairing={selectedPairing}
/>
<MatchResultPlayerFields
className={styles.MatchResultForm_Player1Fields}
index={1}
playerReadOnly={!!existingValues}
tournamentPairing={selectedPairing}
/>
<MatchResultDetailFields className={styles.MatchResultForm_MatchResultDetailFields} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
export interface MatchResultPlayerFieldsProps {
index: 0 | 1;
tournamentPairing?: TournamentPairing | null;
playerReadOnly?: boolean;

// Passed by FormField via Controller:
className?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const FlamesOfWarV4MatchResultPlayerFields = ({
index,
className,
disabled = false,
playerReadOnly,
tournamentPairing,
}: MatchResultPlayerFieldsProps): JSX.Element => {

Expand Down Expand Up @@ -80,7 +81,7 @@ export const FlamesOfWarV4MatchResultPlayerFields = ({

return (
<div className={clsx(styles.FlamesOfWarV4MatchResultPlayerFields, className)}>
<PlayerField tournamentPairing={tournamentPairing} index={index} />
<PlayerField tournamentPairing={tournamentPairing} index={index} readOnly={playerReadOnly} />
<FormField
name={`details.player${index}Faction`}
label="Faction"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const TeamYankeeV2MatchResultPlayerFields = ({
index,
className,
disabled = false,
playerReadOnly,
tournamentPairing,
}: MatchResultPlayerFieldsProps): JSX.Element => {

Expand Down Expand Up @@ -80,7 +81,7 @@ export const TeamYankeeV2MatchResultPlayerFields = ({

return (
<div className={clsx(styles.TeamYankeeV2MatchResultPlayerFields, className)}>
<PlayerField tournamentPairing={tournamentPairing} index={index} />
<PlayerField tournamentPairing={tournamentPairing} index={index} readOnly={playerReadOnly} />
<FormField
name={`details.player${index}Faction`}
label="Faction"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
User,
UserId,
} from '~/api';
import { useAuth } from '~/components/AuthProvider';
import { Label } from '~/components/generic/Label';
import { DeviceSize, useDeviceSize } from '~/hooks/useDeviceSize';
import { useGetUser } from '~/services/users';
Expand All @@ -44,9 +43,9 @@ export type PlayerFieldProps = Omit<InputPanelProps<PlayerFieldValue>, 'renderCo
export const PlayerField = ({
tournamentPairing,
index,
readOnly: readOnlyProp,
...props
}: PlayerFieldProps): JSX.Element => {
const currentUser = useAuth();
const [deviceSize] = useDeviceSize();
const isMobile = deviceSize === DeviceSize.Mobile;

Expand Down Expand Up @@ -100,8 +99,7 @@ export const PlayerField = ({
selectedUserRef.current = selectedUser;
}

const isOwnSingleMatch = !tournamentPairing && currentUser?._id === userId;
const readOnly = (competitorUserOptions.length === 1) || isBye || isOwnSingleMatch;
const readOnly = readOnlyProp || (competitorUserOptions.length === 1) || isBye;

const fieldId = `player${index}UserId`;

Expand Down
2 changes: 2 additions & 0 deletions src/components/MatchResultPlayers/MatchResultPlayers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const MatchResultPlayers = ({
size="large"
user={matchResult.player0User}
placeholder={{ displayName: matchResult.player0Placeholder }}
disableLink={!!matchResult.player0Placeholder}
/>
{/* TODO: Add factions */}
{/* <Popover.Root>
Expand All @@ -45,6 +46,7 @@ export const MatchResultPlayers = ({
size="large"
user={matchResult.player1User}
placeholder={{ displayName: matchResult.player1Placeholder }}
disableLink={!!matchResult.player1Placeholder}
/>
{/* TODO: Add factions */}
{/* <Popover.Root>
Expand Down