To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Verified Commit b6f679dc authored by Sandro Lutz's avatar Sandro Lutz
Browse files

Improve feedback for email event signup

parent 50b5a91a
Pipeline #59087 passed with stages
in 11 minutes and 14 seconds
import React, { useEffect, useState } from 'react'
import PropTypes from 'prop-types'
import { useSelector, useDispatch } from 'react-redux'
import { Parser as HtmlToReactParser } from 'html-to-react'
import { makeStyles } from '@material-ui/styles'
import { Toolbar, Button, TextField } from '@material-ui/core'
import { useIntl, FormattedMessage } from 'gatsby-plugin-intl'
......@@ -344,6 +345,9 @@ const EventDetails = ({ eventId, ...props }) => {
.then(() => {
setStoredNotification({
severity: 'success',
label: !auth.isLoggedIn
? intl.formatMessage({ id: 'events.signup.email_success' })
: undefined,
})
})
.catch(err => {
......@@ -354,12 +358,12 @@ const EventDetails = ({ eventId, ...props }) => {
) {
setStoredNotification({
severity: 'error',
label: <FormattedMessage id="events.signup.blacklisted" />,
label: intl.formatMessage({ id: 'events.signup.blacklisted' }),
})
} else {
setStoredNotification({
severity: 'error',
label: <FormattedMessage id="events.signup.failed" />,
label: intl.formatMessage({ id: 'events.signup.failed' }),
})
}
})
......@@ -403,14 +407,14 @@ const EventDetails = ({ eventId, ...props }) => {
>
<FormattedMessage
id={
signup && signup.data
auth.isLoggedIn && signup && signup.data
? 'events.signup.updateAction'
: 'events.signup.action'
}
/>
</Button>
)}
{signup && signup.data && (
{auth.isLoggedIn && signup && signup.data && (
<Button onClick={deleteAction} disabled={signup.isPending}>
<FormattedMessage id="events.signoff.action" />
</Button>
......@@ -419,6 +423,8 @@ const EventDetails = ({ eventId, ...props }) => {
)
}
const htmlToReactParser = new HtmlToReactParser()
return (
<div className={[classes.root].join(' ')} {...props}>
{notification && (
......@@ -426,7 +432,7 @@ const EventDetails = ({ eventId, ...props }) => {
className={classes.notification}
severity={notification.severity}
>
{notification.label}
{htmlToReactParser.parse(notification.label)}
</Alert>
)}
<div
......
......@@ -143,6 +143,7 @@
"events.signup.action": "anmelden",
"events.signup.updateAction": "Anmeldung ändern",
"events.signup.success": "Du hast einen Platz ergattert!",
"events.signup.email_success": "Fast geschafft!<br/>Bestätige deine Anmeldung mit der Nachricht, die wir an deine Email-Adresse geschickt haben, um einen Platz zu ergattern!",
"events.signup.failed": "Anmeldung fehlgeschlagen",
"events.signup.blacklisted": "Du kannst dich im Moment nicht anmelden, da du auf der Blacklist bist.",
"events.signup.waitingList": "Du bist auf der Warteliste.",
......
......@@ -141,6 +141,7 @@
"events.signup.action": "signup",
"events.signup.updateAction": "change signup",
"events.signup.success": "Success! you're in",
"events.signup.email_success": "Success! Confirm your signup with the message we sent to you in order to get a spot!",
"events.signup.failed": "Signup failed",
"events.signup.blacklisted": "You cannot register for this event because you are on the blacklist.",
"events.signup.waitingList": "You are on the waiting list.",
......
......@@ -2,6 +2,7 @@ import {
EVENTS,
EVENTS_SIGNUP_PENDING,
EVENTS_SIGNUP_SUCCESS,
EVENTS_SIGNUP_EMAIL_SUCCESS,
EVENTS_SIGNUP_DELETED,
EVENTS_SIGNUP_ERROR,
} from './constants'
......@@ -81,22 +82,28 @@ const postSignup = ({ eventId, additionalFields = null, email = null }) => (
dispatch,
getState
) => {
const { auth: { session } = {} } = getState()
const { auth: { session, isLoggedIn } = {} } = getState()
console.log(isLoggedIn)
return dispatch({
types: [
{ type: EVENTS_SIGNUP_PENDING, eventId },
{ type: EVENTS_SIGNUP_SUCCESS, eventId },
{
type: isLoggedIn ? EVENTS_SIGNUP_SUCCESS : EVENTS_SIGNUP_EMAIL_SUCCESS,
eventId,
},
{ type: EVENTS_SIGNUP_ERROR, eventId },
],
resource: 'eventsignups',
method: 'POST',
data: {
event: eventId,
user: session ? session.user : null,
user: session ? session.user : undefined,
additional_fields: additionalFields
? JSON.stringify(additionalFields)
: undefined,
email,
email: email || undefined,
},
dataType: 'application/json',
})
......
......@@ -2,5 +2,6 @@ export const EVENTS = 'events'
export const EVENTS_SIGNUP_PENDING = 'EVENTS_SIGNUP_PENDING'
export const EVENTS_SIGNUP_SUCCESS = 'EVENTS_SIGNUP_SUCCESS'
export const EVENTS_SIGNUP_EMAIL_SUCCESS = 'EVENTS_SIGNUP_EMAIL_SUCCESS'
export const EVENTS_SIGNUP_DELETED = 'EVENTS_SIGNUP_DELETED'
export const EVENTS_SIGNUP_ERROR = 'EVENTS_SIGNUP_ERROR'
......@@ -2,6 +2,7 @@ import {
EVENTS,
EVENTS_SIGNUP_PENDING,
EVENTS_SIGNUP_SUCCESS,
EVENTS_SIGNUP_EMAIL_SUCCESS,
EVENTS_SIGNUP_DELETED,
EVENTS_SIGNUP_ERROR,
} from './constants'
......@@ -123,6 +124,14 @@ const reducer = (state, action) => {
},
},
}
case EVENTS_SIGNUP_EMAIL_SUCCESS:
return {
...state,
signups: {
...state.signups,
[action.eventId]: undefined,
},
}
case EVENTS_SIGNUP_DELETED:
return {
...state,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment