2019-12-20 13:04:34 +01:00
< template >
2020-02-18 08:57:00 +01:00
< section class = "container section hero is-fullheight" >
2020-06-09 10:07:30 +02:00
< div class = "hero-body" v-if ="event" >
2020-02-18 08:57:00 +01:00
< div class = "container" >
2020-10-07 17:05:15 +02:00
< form @submit.prevent ="joinEvent" v-if ="!formSent" >
2020-02-18 08:57:00 +01:00
< 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 >
2020-10-07 17:05:15 +02:00
< b -field : label = "$t('Email address')" >
2020-02-18 08:57:00 +01:00
< b -input
type = "email"
v - model = "anonymousParticipation.email"
2020-10-07 17:05:15 +02:00
: placeholder = "$t('Your email')"
2020-02-18 08:57:00 +01:00
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 >
2020-11-30 10:24:11 +01:00
< p v-else >
{ {
$t (
"If you want, you may send a message to the event organizer here."
)
} }
< / p >
2020-02-18 08:57:00 +01:00
< 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 >
2020-10-07 17:05:15 +02:00
< 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 - c h e c k b o x >
< / b - f i e l d >
2020-11-30 10:24:11 +01:00
< b -button
: disabled = "sendingForm"
type = "is-primary"
native - type = "submit"
> { { $t ( "Send email" ) } } < / b - b u t t o n
>
2020-02-18 08:57:00 +01:00
< div class = "has-text-centered" >
2020-11-30 10:24:11 +01:00
< 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
>
2020-02-18 08:57:00 +01:00
< / div >
< / form >
2020-10-07 17:05:15 +02:00
< div v-else >
2020-11-30 10:24:11 +01:00
< h1 class = "title" >
{ { $t ( "Request for participation confirmation sent" ) } }
< / h1 >
< p class = "content" >
{ { $t ( "Check your inbox (and your junk mail folder)." ) } }
< / p >
2020-10-07 17:05:15 +02:00
< p class = "content" > { { $t ( "You may now close this window." ) } } < / p >
< / div >
2020-02-18 08:57:00 +01:00
< / 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" ;
2020-11-27 19:27:44 +01:00
import { EventModel , IEvent } from "@/types/event.model" ;
2020-02-18 08:57:00 +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" ;
2020-11-27 19:27:44 +01:00
import { EventJoinOptions , ParticipantRole } from "@/types/enums" ;
import { IParticipant } from "../../types/participant.model" ;
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
2020-11-30 10:24:11 +01:00
anonymousParticipation : {
email : string ;
message : string ;
saveParticipation : boolean ;
} = {
2020-02-18 08:57:00 +01:00
email : "" ,
message : "" ,
2020-10-07 17:05:15 +02:00
saveParticipation : true ,
2020-02-18 08:57:00 +01:00
} ;
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-10-07 17:05:15 +02:00
formSent = false ;
sendingForm = false ;
2020-03-05 19:32:34 +01:00
EventJoinOptions = EventJoinOptions ;
2019-12-20 13:04:34 +01:00
2020-10-07 17:05:15 +02:00
async joinEvent ( ) : Promise < void > {
2019-12-20 13:04:34 +01:00
this . error = false ;
2020-10-07 17:05:15 +02:00
this . sendingForm = true ;
2019-12-20 13:04:34 +01:00
try {
const { data } = await this . $apollo . mutate < { joinEvent : IParticipant } > ( {
mutation : JOIN _EVENT ,
variables : {
eventId : this . event . id ,
2020-12-04 09:40:42 +01:00
actorId : this . config . anonymous . actorId ,
2019-12-20 13:04:34 +01:00
email : this . anonymousParticipation . email ,
2020-03-05 19:32:34 +01:00
message : this . anonymousParticipation . message ,
2020-06-09 10:07:30 +02:00
locale : this . $i18n . locale ,
2019-12-20 13:04:34 +01:00
} ,
2020-11-06 11:34:32 +01:00
update : ( store , { data : updateData } ) => {
if ( updateData == null ) {
2020-11-30 10:24:11 +01:00
console . error (
"Cannot update event participant cache, because of data null value."
) ;
2020-06-09 10:07:30 +02:00
return ;
}
2019-12-20 13:04:34 +01:00
const cachedData = store . readQuery < { event : IEvent } > ( {
query : FETCH _EVENT ,
variables : { uuid : this . event . uuid } ,
} ) ;
2020-06-09 10:07:30 +02:00
if ( cachedData == null ) {
2020-11-30 10:24:11 +01:00
console . error (
"Cannot update event participant cache, because of cached null value."
) ;
2020-06-09 10:07:30 +02:00
return ;
}
2019-12-20 13:04:34 +01:00
const { event } = cachedData ;
if ( event === null ) {
2020-11-30 10:24:11 +01:00
console . error (
"Cannot update event participant cache, because of null value."
) ;
2019-12-20 13:04:34 +01:00
return ;
}
2020-11-06 11:34:32 +01:00
if ( updateData . joinEvent . role === ParticipantRole . NOT _CONFIRMED ) {
2020-09-29 09:53:48 +02:00
event . participantStats . notConfirmed += 1 ;
2019-12-20 13:04:34 +01:00
} else {
2020-09-29 09:53:48 +02:00
event . participantStats . going += 1 ;
event . participantStats . participant += 1 ;
2019-12-20 13:04:34 +01:00
}
2020-06-09 10:07:30 +02:00
console . log ( "just before writequery" ) ;
2019-12-20 13:04:34 +01:00
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
} ,
} ) ;
2020-06-09 10:07:30 +02:00
console . log ( "finished with store" , data ) ;
2020-10-07 17:05:15 +02:00
if (
data &&
data . joinEvent . metadata . cancellationToken &&
this . anonymousParticipation . saveParticipation
) {
2020-02-18 08:57:00 +01:00
await addLocalUnconfirmedAnonymousParticipation (
this . event ,
data . joinEvent . metadata . cancellationToken
) ;
2020-06-09 10:07:30 +02:00
console . log ( "done with crypto stuff" ) ;
2019-12-20 13:04:34 +01:00
}
} catch ( e ) {
2020-09-29 09:53:48 +02:00
this . error = e . message ;
2019-12-20 13:04:34 +01:00
}
2020-10-07 17:05:15 +02:00
this . sendingForm = false ;
this . formSent = true ;
2019-12-20 13:04:34 +01:00
}
}
2020-02-18 08:57:00 +01:00
< / script >