refactor: use email of backend response in Signup

This commit is contained in:
roschaefer 2019-11-05 14:24:02 +01:00
parent 0cf59743ab
commit 2a53eb2e6c
2 changed files with 10 additions and 14 deletions

View File

@ -48,7 +48,7 @@ describe('Signup', () => {
describe('submit', () => {
beforeEach(async () => {
wrapper = Wrapper()
wrapper.find('input#email').setValue('mail@example.org')
wrapper.find('input#email').setValue('mAIL@exAMPLE.org')
await wrapper.find('form').trigger('submit')
})
@ -59,7 +59,7 @@ describe('Signup', () => {
it('delivers email to backend', () => {
const expected = expect.objectContaining({
variables: { email: 'mail@example.org', token: null },
variables: { email: 'mAIL@exAMPLE.org', token: null },
})
expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expected)
})

View File

@ -1,5 +1,5 @@
<template>
<ds-space v-if="!success && !error" margin="large">
<ds-space v-if="!data && !error" margin="large">
<ds-form
@input="handleInput"
@input-valid="handleInputValid"
@ -63,7 +63,6 @@
<script>
import gql from 'graphql-tag'
import { SweetalertIcon } from 'vue-sweetalert-icons'
import { normalizeEmail } from 'validator'
export const SignupMutation = gql`
mutation($email: String!) {
@ -101,16 +100,13 @@ export default {
},
},
disabled: true,
success: false,
data: null,
error: null,
}
},
computed: {
email() {
return normalizeEmail(this.formData.email)
},
submitMessage() {
const { email } = this
const { email } = this.data.Signup
return this.$t('components.registration.signup.form.success', { email })
},
},
@ -123,14 +119,14 @@ export default {
},
async handleSubmit() {
const mutation = this.token ? SignupByInvitationMutation : SignupMutation
const { email, token } = this
const { token } = this
const { email } = this.formData
try {
await this.$apollo.mutate({ mutation, variables: { email, token } })
this.success = true
const response = await this.$apollo.mutate({ mutation, variables: { email, token } })
this.data = response.data
setTimeout(() => {
this.$emit('submit', { email })
this.$emit('submit', { email: this.data.Signup.email })
}, 3000)
} catch (err) {
const { message } = err