Improve anonymous participation and confirmation

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2020-10-07 17:05:15 +02:00
parent 9382e8fc74
commit 77970b8091
7 changed files with 92 additions and 65 deletions

View File

@@ -1,33 +1,35 @@
<template>
<section class="section container">
<h1 class="title" v-if="loading">{{ $t("Your participation is being validated") }}</h1>
<h1 class="title" v-if="loading">{{ $t("Your participation request is being validated") }}</h1>
<div v-else>
<div v-if="failed">
<b-message :title="$t('Error while validating participation')" type="is-danger">
<b-message :title="$t('Error while validating participation request')" type="is-danger">
{{
$t(
"Either the participation has already been validated, either the validation token is incorrect."
"Either the participation request has already been validated, either the validation token is incorrect."
)
}}
</b-message>
</div>
<div v-else>
<h1 class="title">{{ $t("Your participation has been validated") }}</h1>
<form @submit.prevent="askToSaveParticipation">
<b-field>
<b-checkbox v-model="saveParticipation">
<b>{{ $t("Remember my participation in this browser") }}</b>
<p>
{{
$t(
"Will allow to display and manage your participation status on the event page when using this device. Uncheck if you're using a public device."
)
}}
</p>
</b-checkbox>
</b-field>
<b-button native-type="submit" type="is-primary">{{ $t("Visit event page") }}</b-button>
</form>
<h1 class="title">{{ $t("Your participation request has been validated") }}</h1>
<p class="content" v-if="participation.event.joinOptions == EventJoinOptions.RESTRICTED">
{{ $t("Your participation still has to be approved by the organisers.") }}
</p>
<div class="columns has-text-centered">
<div class="column">
<router-link
native-type="button"
tag="a"
class="button is-primary is-large"
:to="{
name: RouteName.EVENT,
params: { uuid: this.participation.event.uuid },
}"
>{{ $t("Go to the event page") }}</router-link
>
</div>
</div>
</div>
</div>
</section>
@@ -35,11 +37,9 @@
<script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator";
import { SnackbarProgrammatic as Snackbar } from "buefy";
import RouteName from "../../router/name";
import { IParticipant } from "../../types/event.model";
import { EventJoinOptions, IParticipant } from "../../types/event.model";
import { CONFIRM_PARTICIPATION } from "../../graphql/event";
import { confirmLocalAnonymousParticipation } from "../../services/AnonymousParticipationStorage";
@Component
export default class ConfirmParticipation extends Vue {
@@ -51,7 +51,9 @@ export default class ConfirmParticipation extends Vue {
participation!: IParticipant;
saveParticipation = true;
EventJoinOptions = EventJoinOptions;
RouteName = RouteName;
async created(): Promise<void> {
await this.validateAction();
@@ -74,30 +76,10 @@ export default class ConfirmParticipation extends Vue {
}
} catch (err) {
console.error(err);
Snackbar.open({ message: err.message, type: "is-danger", position: "is-bottom" });
this.failed = true;
} finally {
this.loading = false;
}
}
askToSaveParticipation(): void {
if (this.saveParticipation) {
this.saveParticipationInBrowser();
}
this.forwardToEventPage();
}
async saveParticipationInBrowser(): Promise<void> {
await confirmLocalAnonymousParticipation(this.participation.event.uuid);
}
async forwardToEventPage(): Promise<void> {
await this.$router.replace({
name: RouteName.EVENT,
params: { uuid: this.participation.event.uuid },
});
}
}
</script>

View File

@@ -2,7 +2,7 @@
<section class="container section hero is-fullheight">
<div class="hero-body" v-if="event">
<div class="container">
<form @submit.prevent="joinEvent">
<form @submit.prevent="joinEvent" v-if="!formSent">
<p>
{{
$t(
@@ -18,11 +18,11 @@
}}
</b-message>
<b-message type="is-danger" v-if="error">{{ error }}</b-message>
<b-field :label="$t('Email')">
<b-field :label="$t('Email address')">
<b-input
type="email"
v-model="anonymousParticipation.email"
placeholder="Your email"
:placeholder="$t('Your email')"
required
></b-input>
</b-field>
@@ -42,13 +42,32 @@
:required="event.joinOptions === EventJoinOptions.RESTRICTED"
></b-input>
</b-field>
<b-button type="is-primary" native-type="submit">{{ $t("Send email") }}</b-button>
<b-field>
<b-checkbox v-model="anonymousParticipation.saveParticipation">
<b>{{ $t("Remember my participation in this browser") }}</b>
<p>
{{
$t(
"Will allow to display and manage your participation status on the event page when using this device. Uncheck if you're using a public device."
)
}}
</p>
</b-checkbox>
</b-field>
<b-button :disabled="sendingForm" type="is-primary" native-type="submit">{{
$t("Send email")
}}</b-button>
<div class="has-text-centered">
<b-button native-type="button" tag="a" type="is-text" @click="$router.go(-1)">{{
$t("Back to previous page")
}}</b-button>
</div>
</form>
<div v-else>
<h1 class="title">{{ $t("Request for participation confirmation sent") }}</h1>
<p class="content">{{ $t("Check your inbox (and your junk mail folder).") }}</p>
<p class="content">{{ $t("You may now close this window.") }}</p>
</div>
</div>
</div>
</section>
@@ -89,9 +108,10 @@ import RouteName from "../../router/name";
export default class ParticipationWithoutAccount extends Vue {
@Prop({ type: String, required: true }) uuid!: string;
anonymousParticipation: { email: string; message: string } = {
anonymousParticipation: { email: string; message: string; saveParticipation: boolean } = {
email: "",
message: "",
saveParticipation: true,
};
event!: IEvent;
@@ -100,10 +120,15 @@ export default class ParticipationWithoutAccount extends Vue {
error: string | boolean = false;
formSent = false;
sendingForm = false;
EventJoinOptions = EventJoinOptions;
async joinEvent(): Promise<Route> {
async joinEvent(): Promise<void> {
this.error = false;
this.sendingForm = true;
try {
const { data } = await this.$apollo.mutate<{ joinEvent: IParticipant }>({
mutation: JOIN_EVENT,
@@ -150,7 +175,11 @@ export default class ParticipationWithoutAccount extends Vue {
},
});
console.log("finished with store", data);
if (data && data.joinEvent.metadata.cancellationToken) {
if (
data &&
data.joinEvent.metadata.cancellationToken &&
this.anonymousParticipation.saveParticipation
) {
await addLocalUnconfirmedAnonymousParticipation(
this.event,
data.joinEvent.metadata.cancellationToken
@@ -160,10 +189,8 @@ export default class ParticipationWithoutAccount extends Vue {
} catch (e) {
this.error = e.message;
}
return this.$router.push({
name: RouteName.EVENT,
params: { uuid: this.event.uuid },
});
this.sendingForm = false;
this.formSent = true;
}
}
</script>