2019-12-20 13:04:34 +01:00
< template >
2020-02-18 08:57:00 +01:00
< 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')" >
< b -input
type = "email"
v - model = "anonymousParticipation.email"
placeholder = "Your email"
required
> < / b - i n p u t >
< / b - f i e l d >
< 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 >
< 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 >
2019-12-20 13:04:34 +01:00
< / template >
< script lang = "ts" >
2020-02-18 08:57:00 +01:00
import { Component , Prop , Vue } from "vue-property-decorator" ;
import {
EventModel ,
IEvent ,
IParticipant ,
ParticipantRole ,
EventJoinOptions ,
} from "@/types/event.model" ;
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/name" ;
2019-12-20 13:04:34 +01:00
@ Component ( {
apollo : {
event : {
query : FETCH _EVENT ,
variables ( ) {
return {
uuid : this . uuid ,
} ;
} ,
2020-02-18 08:57:00 +01:00
skip ( ) {
return ! this . uuid ;
} ,
2019-12-20 13:04:34 +01:00
update : ( data ) => new EventModel ( data . event ) ,
} ,
config : CONFIG ,
} ,
} )
export default class ParticipationWithoutAccount extends Vue {
@ Prop ( { type : String , required : true } ) uuid ! : string ;
2020-02-18 08:57:00 +01:00
anonymousParticipation : { email : string ; message : string } = {
email : "" ,
message : "" ,
} ;
2019-12-20 13:04:34 +01:00
event ! : IEvent ;
2020-02-18 08:57:00 +01:00
2019-12-20 13:04:34 +01:00
config ! : IConfig ;
2020-02-18 08:57:00 +01:00
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 ) {
2020-02-18 08:57:00 +01:00
console . error ( "Cannot update event participant cache, because of null value." ) ;
2019-12-20 13:04:34 +01:00
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 ;
}
2020-02-18 08:57:00 +01:00
store . writeQuery ( {
query : FETCH _EVENT ,
variables : { uuid : this . event . uuid } ,
data : { event } ,
} ) ;
2019-12-20 13:04:34 +01:00
} ,
} ) ;
if ( data && data . joinEvent . metadata . cancellationToken ) {
2020-02-18 08:57:00 +01:00
await addLocalUnconfirmedAnonymousParticipation (
this . event ,
data . joinEvent . metadata . cancellationToken
) ;
return this . $router . push ( {
name : RouteName . EVENT ,
params : { uuid : this . event . uuid } ,
} ) ;
2019-12-20 13:04:34 +01:00
}
} catch ( e ) {
console . log ( JSON . stringify ( e ) ) ;
2020-02-18 08:57:00 +01:00
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 ;
2019-12-20 13:04:34 +01:00
}
}
}
}
2020-02-18 08:57:00 +01:00
< / script >