trusted-setup-server/pages/authorize-contribution.vue

136 lines
3.6 KiB
Vue
Raw Normal View History

2020-02-06 17:16:38 +01:00
<template>
<div class="ceremony">
<h1 class="title is-size-1 is-size-2-mobile is-spaced">
2020-02-08 19:47:21 +01:00
Hello, <span>@{{ handle }}</span>
2020-02-06 17:16:38 +01:00
</h1>
<h2 class="subtitle">
2020-02-07 10:21:53 +01:00
Do you want to authorize your contribution #{{ contributionIndex }}? Please sign in.
2020-02-06 17:16:38 +01:00
</h2>
<fieldset :disabled="hideSaveBtn" class="authorize">
2020-02-06 17:16:38 +01:00
<Form />
</fieldset>
<div class="buttons is-centered">
2020-02-08 19:47:21 +01:00
<b-button
v-if="isLoggedIn && !hideSaveBtn"
@click="authorize"
:disabled="hasErrorName.invalid"
type="is-primary"
outlined
>
2020-02-06 17:16:38 +01:00
Save information
</b-button>
2020-02-08 19:47:21 +01:00
<b-button
v-if="status.type === 'is-success'"
@click="makeTweet"
type="is-primary"
tag="a"
target="_blank"
outlined
>
Tweet about your contribution
</b-button>
</div>
<div v-show="status.type === 'is-danger' || status.type === 'is-success'" class="status">
<div :class="status.type" class="status-message">{{ status.msg }}</div>
2020-02-06 17:16:38 +01:00
</div>
</div>
</template>
<script>
2020-02-08 19:47:21 +01:00
import { mapGetters, mapActions, mapState } from 'vuex'
2020-02-06 17:16:38 +01:00
import Form from '@/components/Form'
export default {
components: {
Form
},
2020-02-07 10:21:53 +01:00
data() {
return {
2020-02-08 19:47:21 +01:00
contributionIndex: 1,
token: null,
status: {
type: '',
msg: ''
},
hideSaveBtn: false
2020-02-07 10:21:53 +01:00
}
},
2020-02-06 17:16:38 +01:00
computed: {
2020-02-08 19:47:21 +01:00
...mapState('user', ['name', 'handle', 'company']),
...mapGetters('user', ['isLoggedIn', 'hasErrorName'])
2020-02-06 17:16:38 +01:00
},
async mounted() {
this.$root.$emit('enableLoading')
2020-02-06 17:16:38 +01:00
await this.getUserData()
2020-02-08 19:47:21 +01:00
this.token = this.$route.query.token
if (!this.token) {
window.location.replace(window.location.origin)
} else {
await this.getContributionIndex()
2020-02-08 19:47:21 +01:00
}
setTimeout(() => {
this.$root.$emit('disableLoading')
}, 800)
2020-02-06 17:16:38 +01:00
},
methods: {
2020-02-08 19:47:21 +01:00
...mapActions('user', ['getUserData', 'makeTweet']),
async authorize() {
const body = {
token: this.token,
name: this.name,
company: this.company
}
try {
const response = await fetch('/api/authorize_contribution', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
})
if (response.ok) {
this.status.msg = `Your contribution is verified and authorized. Thank you.`
this.status.type = 'is-success'
this.hideSaveBtn = true
} else {
const error = await response.text()
this.status.msg = error
this.status.type = 'is-danger'
}
} catch (e) {
this.status.msg = 'Something went wrong. Please contact support'
this.status.type = 'is-danger'
}
2020-02-11 10:53:41 +01:00
},
async getContributionIndex() {
2020-02-11 10:53:41 +01:00
const body = {
token: this.token
}
try {
const response = await fetch('/api/get_contribution_index', {
2020-02-11 10:53:41 +01:00
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
})
if (response.ok) {
const { id } = await response.json()
this.contributionIndex = id
} else {
const error = await response.text()
this.status.msg = error
this.status.type = 'is-danger'
this.hideSaveBtn = true
}
} catch (e) {
this.status.msg = 'Something went wrong. Please contact support'
this.status.type = 'is-danger'
}
2020-02-08 19:47:21 +01:00
}
2020-02-06 17:16:38 +01:00
}
}
</script>