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" >
2020-12-07 14:48:48 +01:00
< span > { {
$t ( "Check your inbox (and your junk mail folder)." )
} } < / span >
< span
class = "details"
v - if = "event.joinOptions === EventJoinOptions.RESTRICTED"
>
{ {
$t (
"Your participation will be validated once you click the confirmation link into the email, and after the organizer manually validates your participation."
)
} } < / s p a n
> < span class = "details" v-else > {{
$t (
"Your participation will be validated once you click the confirmation link into the email."
)
} } < / span >
< / p >
< b -message type = "is-warning" v-if ="error" > {{ error }} < / b -message >
< p class = "content" >
< i18n path = "You may now close this window, or {return_to_event}." >
< router -link
slot = "return_to_event"
: to = "{ name: RouteName.EVENT, params: { uuid: event.uuid } }"
> { { $t ( "return to the event's page" ) } } < / r o u t e r - l i n k
>
< / i18n >
2020-11-30 10:24:11 +01:00
< / p >
2020-10-07 17:05:15 +02:00
< / div >
2020-02-18 08:57:00 +01:00
< / div >
< / div >
2020-12-07 14:48:48 +01:00
< b -message type = "is-danger" v -else -if = " ! $ apollo.loading "
> { {
$t (
"Unable to load event for participation. The error details are provided below:"
)
} }
< details >
< pre > { { error } } < / pre >
< / details >
< / b - m e s s a g e >
2020-02-18 08:57:00 +01:00
< / 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-12-07 14:48:48 +01:00
import { FETCH _EVENT _BASIC , JOIN _EVENT } from "@/graphql/event" ;
2020-02-18 08:57:00 +01:00
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" ;
2020-12-07 14:48:48 +01:00
import RouteName from "@/router/name" ;
2020-11-27 19:27:44 +01:00
import { IParticipant } from "../../types/participant.model" ;
2021-05-12 18:10:07 +02:00
import { ApolloCache , FetchResult , InMemoryCache } from "@apollo/client/core" ;
2019-12-20 13:04:34 +01:00
@ Component ( {
apollo : {
event : {
2020-12-07 14:48:48 +01:00
query : FETCH _EVENT _BASIC ,
2019-12-20 13:04:34 +01:00
variables ( ) {
return {
uuid : this . uuid ,
} ;
} ,
2020-12-07 14:48:48 +01:00
error ( e ) {
this . error = e ;
} ,
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-12-07 14:48:48 +01:00
RouteName = RouteName ;
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
} ,
2021-05-12 18:10:07 +02:00
update : (
store : ApolloCache < InMemoryCache > ,
{ data : updateData } : FetchResult
) => {
2020-11-06 11:34:32 +01:00
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 } > ( {
2020-12-07 14:48:48 +01:00
query : FETCH _EVENT _BASIC ,
2019-12-20 13:04:34 +01:00
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-02-18 08:57:00 +01:00
store . writeQuery ( {
2020-12-07 14:48:48 +01:00
query : FETCH _EVENT _BASIC ,
2020-02-18 08:57:00 +01:00
variables : { uuid : this . event . uuid } ,
data : { event } ,
} ) ;
2019-12-20 13:04:34 +01:00
} ,
} ) ;
2020-12-07 14:48:48 +01:00
this . formSent = true ;
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
) ;
2019-12-20 13:04:34 +01:00
}
} catch ( e ) {
2020-12-07 14:48:48 +01:00
if (
[ "TextEncoder is not defined" , "crypto.subtle is undefined" ] . includes (
e . message
)
) {
this . error = this . $t (
"Unable to save your participation in this browser."
) as string ;
} else if ( e . graphQLErrors && e . graphQLErrors . length > 0 ) {
this . error = e . graphQLErrors [ 0 ] . message ;
} else if ( e . networkError ) {
this . error = e . networkError . message ;
}
2019-12-20 13:04:34 +01:00
}
2020-10-07 17:05:15 +02:00
this . sendingForm = false ;
2019-12-20 13:04:34 +01:00
}
}
2020-02-18 08:57:00 +01:00
< / script >
2020-12-07 14:48:48 +01:00
< style lang = "scss" scoped >
section . container . section {
background : $white ;
}
< / style >