Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use player name as team name when solo game #146

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion src/components/TeamCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ storeToRefs(useUserStore());

defineProps<{
team: Team;
soloGame?: boolean;
}>();
</script>

Expand All @@ -19,7 +20,10 @@ defineProps<{
{{ team.name }}
<img v-if="team.validated" src="/src/assets/images/check_with_bg.svg" alt="Logo validé" class="inline-block size-6"/>
</h1>
<ul class="ml-4 list-disc text-xl">
<ul
v-if="soloGame"
class="ml-4 list-disc text-xl"
>
<li v-for="player in team.players" :key="((player as PlayerRegistration).user)">
<p>
{{ (player as PlayerRegistration).name_in_game }}
Expand Down
3 changes: 2 additions & 1 deletion src/components/TournamentTeams.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { getTournamentTeams } = tournamentStore;

getTournamentTeams();

const { tourney_teams } = storeToRefs(tournamentStore);
const { tourney_teams, soloGame } = storeToRefs(tournamentStore);
</script>

<template>
Expand All @@ -30,6 +30,7 @@ const { tourney_teams } = storeToRefs(tournamentStore);
v-for="team in tourney_teams.validated_teams"
:key="team.id"
:team="team"
:solo-game="soloGame"
/>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/stores/tournament.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,8 @@ export const useTournamentStore = defineStore('tournament', () => {
return res;
};

const soloGame = computed(() => (tournament.value as TournamentDeref | undefined)?.game.players_per_team === 1);

function $reset() {
eventsList.value = {};
tournamentsList.value = {};
Expand Down Expand Up @@ -543,5 +545,6 @@ export const useTournamentStore = defineStore('tournament', () => {
get_ticket_pdf,
get_unpaid_registration,
validate_registration,
soloGame,
};
});
35 changes: 30 additions & 5 deletions src/views/TournamentRegister.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ const tournamentStore = useTournamentStore();
const {
registerTeam, registerPlayerOrManager, getTournamentFull, payRegistration,
} = tournamentStore;
const { tournamentsList } = storeToRefs(tournamentStore);
const tournament = computed<Tournament | undefined>(() => tournamentsList.value[props.id]);
// const tournament = ref<Tournament>();
const { tournament, soloGame } = storeToRefs(tournamentStore);

const acceptRules = helpers.withParams(
{ type: 'acceptRules' },
Expand All @@ -52,7 +50,7 @@ const selected_team = computed(() => {
});

const rules = computed(() => ({
team: { required },
team: soloGame ? {} : { required },
name_in_game: register_form.role === 'player' ? { required } : {},
password: { required, minLengthValue: minLength(8) },
role: { required },
Expand All @@ -68,6 +66,10 @@ const register_team = async () => {
const isValid = await v$.value.$validate();
if (!isValid) return;

if (soloGame) {
register_form.team = register_form.name_in_game;
}

try {
await registerTeam(
tournament.value?.id as number,
Expand Down Expand Up @@ -177,7 +179,7 @@ const view_password = ref<boolean>(false);
@submit.prevent="create ? register_team() : register_player()"
>
<FormField
v-if="create"
v-if="create && !soloGame"
v-slot="context"
:validations="v$.team"
class="flex flex-col text-xl"
Expand All @@ -196,6 +198,27 @@ const view_password = ref<boolean>(false);
@blur="v$.team.$touch"
/>
</FormField>
<FormField
v-else-if="soloGame"
v-slot="context"
:validations="v$.name_in_game"
class="flex flex-col text-xl"
>
<label for="name_in_game">
Pseudo en jeu
</label>
<input
id="name_in_game"
v-model="register_form.name_in_game"
class="text-black disabled:opacity-75"
:class="{ error: context.invalid }"
:disabled="register_form.role === 'manager'"
placeholder="Pseudo"
type="text"
required
@blur="v$.name_in_game.$touch"
/>
</FormField>
<FormField
v-else
v-slot="context"
Expand All @@ -221,6 +244,7 @@ const view_password = ref<boolean>(false);
</select>
</FormField>
<FormField
v-if="!soloGame"
v-slot="context"
:validations="v$.name_in_game"
class="flex flex-col text-xl"
Expand All @@ -240,6 +264,7 @@ const view_password = ref<boolean>(false);
@blur="v$.name_in_game.$touch"
/>
</FormField>
<div v-else/> <!-- for padding -->
<FormField
v-slot="context"
:validations="v$.password"
Expand Down