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

Add ticket in /me #94

Merged
merged 1 commit into from
Feb 4, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/models/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface BaseRegistration {
id: number;
payment_status: PaymentStatus;
user: number;
ticket: number;
ticket: string;
}

export interface Registration extends BaseRegistration {
Expand Down
13 changes: 13 additions & 0 deletions src/stores/tournament.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,18 @@ export const useTournamentStore = defineStore('tournament', () => {
});
}

async function get_ticket_pdf(token: string) {
const response = await axios.get(`/tickets/generate/${token}`, {
responseType: 'blob',
});
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', `ticket_${token}.pdf`);
document.body.appendChild(link);
link.click();
}

function $reset() {
eventsList.value = {};
tournamentsList.value = {};
Expand Down Expand Up @@ -300,5 +312,6 @@ export const useTournamentStore = defineStore('tournament', () => {
patch_registration,
$reset,
groupBy,
get_ticket_pdf,
};
});
37 changes: 26 additions & 11 deletions src/views/Me.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const userStore = useUserStore();
const tournamentStore = useTournamentStore();
const { user, role, inscriptions } = storeToRefs(userStore);
const { fetch_user_inscription_full, patch_user } = userStore;
const { patch_registration, payRegistration } = tournamentStore;
const { patch_registration, payRegistration, get_ticket_pdf } = tournamentStore;

onMounted(async () => {
await fetch_user_inscription_full();
Expand Down Expand Up @@ -258,11 +258,10 @@ const editField = (field: string) => {
Edition Actuelle
</h1>
<div class="m-1 grid gap-3 md:grid-cols-3">
<router-link
<div
v-for="inscription in inscriptions.ongoing"
:key="inscription[1].id"
:class="{ /*[`bg-red-900`]: inscriptions.unpaid[inscription.team.id]*/ }"
:to="`/tournament/${inscription[1].team.tournament.id }?s=teams`"
class="container flex max-w-xs flex-col-reverse break-words bg-cyan-900 text-center"
>
<div class="my-1 block">
Expand Down Expand Up @@ -315,18 +314,34 @@ const editField = (field: string) => {
Règlement du tournoi
</router-link>
</div>
<img
:src="inscription[1].team.tournament.logo"
alt="image du tournoi"
class="h-32 w-32 max-w-full overflow-hidden"
style="width: 100%; object-fit: cover;"
/>
<div class="m-1 flex flex-1 flex-col justify-center">
<div
:class="{ ['hover:cursor-pointer']: inscription[1].ticket }"
@click="inscription[1].ticket && get_ticket_pdf(inscription[1].ticket)"
@keydown="inscription[1].ticket && get_ticket_pdf(inscription[1].ticket)"
>
<img
:src="inscription[1].team.tournament.logo"
alt="image du tournoi"
class="h-32 w-32 max-w-full overflow-hidden"
style="width: 100%; object-fit: cover;"
/>
<div
v-if="inscription[1].ticket"
class="m-1 flex flex-1 flex-col justify-center"
>
<p class="text-xs">
Télecharger son billet
</p>
</div>
</div>
<div
class="m-1 flex flex-1 flex-col justify-center"
>
<p class="text-xl">
{{ inscription[1].team.name }}
</p>
</div>
</router-link>
</div>
</div>
</div>
<div v-if="inscriptions.past?.length > 0" class="m-4">
Expand Down
Loading