2019-12-20 13:04:34 +01:00
< template >
< section class = "container section hero is-fullheight" >
< div class = "hero-body" >
< div class = "container" >
< form @submit.prevent ="joinEvent" >
< p > { { $t ( 'This Mobilizon instance and this event organizer allows anonymous participations, but requires validation through email confirmation.' ) } } < / p >
< b -message type = "is-info" > { { $t ( "Your email will only be used to confirm that you're a real person and send you eventual updates for this event. It will NOT be transmitted to other instances or to the event organizer." ) } } < / b - m e s s a g e >
< b -message type = "is-danger" v-if ="error" > {{ error }} < / b -message >
< b -field :label ="$t('Email')" >
2020-03-05 19:32:34 +01:00
< b -input
type = "email"
v - model = "anonymousParticipation.email"
placeholder = "Your email"
required >
< / b - i n p u t >
2019-12-20 13:04:34 +01:00
< / b - f i e l d >
2020-03-05 19:32:34 +01:00
< p v-if ="event.joinOptions === EventJoinOptions.RESTRICTED" > {{ $ t ( " The event organizer manually approves participations. Since you ' ve chosen to participate without an account , please explain why you want to participate to this event. " ) }} < / p >
< p v-else > {{ $ t ( " If you want , you may send a message to the event organizer here. " ) }} < / p >
< b -field :label ="$t('Message')" >
< b -input
type = "textarea"
v - model = "anonymousParticipation.message"
minlength = "10"
: required = "event.joinOptions === EventJoinOptions.RESTRICTED" >
< / b - i n p u t >
< / b - f i e l d >
< b -button type = "is-primary" native -type = " submit " > { { $t ( 'Send email' ) } } < / b - b u t t o n >
2019-12-20 13:04:34 +01:00
< 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 - b u t t o n >
< / div >
< / form >
< / div >
< / div >
< / section >
< / template >
< script lang = "ts" >
import { Component , Prop , Vue } from 'vue-property-decorator' ;
2020-03-05 19:32:34 +01:00
import { EventModel , IEvent , IParticipant , ParticipantRole , EventJoinOptions } from '@/types/event.model' ;
2019-12-20 13:04:34 +01:00
import { FETCH _EVENT , JOIN _EVENT } from '@/graphql/event' ;
import { IConfig } from '@/types/config.model' ;
import { CONFIG } from '@/graphql/config' ;
import { addLocalUnconfirmedAnonymousParticipation } from '@/services/AnonymousParticipationStorage' ;
import { RouteName } from '@/router' ;
@ Component ( {
apollo : {
event : {
query : FETCH _EVENT ,
variables ( ) {
return {
uuid : this . uuid ,
} ;
} ,
skip ( ) { return ! this . uuid ; } ,
update : ( data ) => new EventModel ( data . event ) ,
} ,
config : CONFIG ,
} ,
} )
export default class ParticipationWithoutAccount extends Vue {
@ Prop ( { type : String , required : true } ) uuid ! : string ;
2020-03-05 19:32:34 +01:00
anonymousParticipation : { email : String , message : String } = { email : '' , message : '' } ;
2019-12-20 13:04:34 +01:00
event ! : IEvent ;
config ! : IConfig ;
error : String | boolean = false ;
2020-03-05 19:32:34 +01:00
EventJoinOptions = EventJoinOptions ;
2019-12-20 13:04:34 +01:00
async joinEvent ( ) {
this . error = false ;
try {
const { data } = await this . $apollo . mutate < { joinEvent : IParticipant } > ( {
mutation : JOIN _EVENT ,
variables : {
eventId : this . event . id ,
actorId : this . config . anonymous . actorId ,
email : this . anonymousParticipation . email ,
2020-03-05 19:32:34 +01:00
message : this . anonymousParticipation . message ,
2019-12-20 13:04:34 +01:00
} ,
update : ( store , { data } ) => {
if ( data == null ) return ;
const cachedData = store . readQuery < { event : IEvent } > ( {
query : FETCH _EVENT ,
variables : { uuid : this . event . uuid } ,
} ) ;
if ( cachedData == null ) return ;
const { event } = cachedData ;
if ( event === null ) {
console . error ( 'Cannot update event participant cache, because of null value.' ) ;
return ;
}
if ( data . joinEvent . role === ParticipantRole . NOT _CONFIRMED ) {
event . participantStats . notConfirmed = event . participantStats . notConfirmed + 1 ;
} else {
event . participantStats . going = event . participantStats . going + 1 ;
event . participantStats . participant = event . participantStats . participant + 1 ;
}
store . writeQuery ( { query : FETCH _EVENT , variables : { uuid : this . event . uuid } , data : { event } } ) ;
} ,
} ) ;
if ( data && data . joinEvent . metadata . cancellationToken ) {
await addLocalUnconfirmedAnonymousParticipation ( this . event , data . joinEvent . metadata . cancellationToken ) ;
return this . $router . push ( { name : RouteName . EVENT , params : { uuid : this . event . uuid } } ) ;
}
} catch ( e ) {
console . log ( JSON . stringify ( e ) ) ;
if ( e . message === 'GraphQL error: You are already a participant of this event' ) {
this . error = this . $t ( 'This email is already registered as participant for this event' ) as string ;
}
}
}
}
< / script >