This commit is contained in:
Matthieu Bessat 2020-07-14 23:58:34 +02:00
parent e3fbebe1b8
commit 4791bd8037
30 changed files with 15738 additions and 278 deletions

214
src/layouts/Delegate.vue Normal file
View file

@ -0,0 +1,214 @@
<template>
<v-main>
<div v-if="enabled">
<v-toolbar
color="primary"
dark
flat
>
<v-toolbar-title>Gestion de l'association We Robot</v-toolbar-title>
<v-spacer></v-spacer>
<v-btn outlined>
Publier
</v-btn>
<v-btn icon @click="logout()">
<v-icon>exit_to_app</v-icon>
</v-btn>
<template v-slot:extension>
<v-tabs
v-model="tab"
centered
show-arrows
slider-color="yellow"
ref="tabs"
>
<v-tab @click="navigate('DelegateMain')">
Résumé
</v-tab>
<v-tab @click="navigate('DelegateGallery')">
Images/vidéos
</v-tab>
<v-tab @click="navigate('DelegatePresentation')">
Présentation
</v-tab>
<v-tab @click="navigate('DelegateSchedule')">
Horaires
</v-tab>
<v-tab @click="navigate('DelegatePricing')">
Tarifs
</v-tab>
<v-tab @click="navigate('DelegateContact')">
Contact
</v-tab>
</v-tabs>
</template>
</v-toolbar>
<v-container fluid>
<v-row class="justify-center">
<v-col cols="12" sm="12" md="8">
<router-view></router-view>
<div class="mt-3 d-flex justify-end">
<v-btn color="success" :loading="isSaving" @click="save()">Sauvegarder</v-btn>
</div>
</v-col>
</v-row>
</v-container>
</div>
<div v-if="!enabled && loading" class="d-flex align-center justify-center mt-10 pt-10">
<v-progress-circular indeterminate color="primary" />
</div>
<div v-if="!enabled && !loading" class="d-flex align-center justify-center mt-5">
<v-card max-width="600">
<v-card-title>
Connexion au panel de modification
</v-card-title>
<v-card-text>
<p>
Vous n'êtes pas encore connecté à l'interface de modification de votre association, veuillez copier-coller la clée qui vous a été envoyé par e-mail dans la boîte ci-dessous.
</p>
<v-text-field
v-on:keydown.enter="submitForm()"
autofocus
label="Clée"
v-model="token" />
</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn
color="primary"
@click="submitForm()"
:disabled="token === ''">
Se connecter
</v-btn>
</v-card-actions>
</v-card>
</div>
</v-main>
</template>
<script>
export default {
data: () => ({
enabled: false,
loading: true,
token: '',
loadingHandle: null,
isSaving: false,
tab: 0
}),
created () {
this.init()
},
mounted () {
const path = this.$route.path.split('/')
const name = path[path.length - 1]
const routes = ['', 'gallery', 'presentation', 'schedule', 'pricing', 'contact']
this.tab = routes.indexOf(name)
/**
* this is very ugly I kown
*/
// setTimeout(() => {
// window.dispatchEvent(new Event('resize'))
// }, 100)
// const i = setInterval(() => {
// window.dispatchEvent(new Event('resize'))
// }, 500)
// setTimeout(() => {
// window.dispatchEvent(new Event('resize'))
// }, 1000)
// setTimeout(() => {
// clearInterval(i)
// }, 3000)
},
methods: {
init () {
this.enabled = false
this.loadingHandle = setTimeout(() => {
this.loading = true
}, 300)
let inUrl = false
let delegateToken = (new URL(window.location)).searchParams.get('delegateToken')
if (this.token !== '') {
delegateToken = this.token
}
if (delegateToken === null) {
delegateToken = window.localStorage.getItem('delegateToken')
if (delegateToken === null || delegateToken === 'null') {
clearTimeout(this.loadingHandle)
this.loading = false
return
}
} else {
inUrl = true
}
this.$apitator.setAuthorizationToken(delegateToken)
// verify the token
this.$apitator.get('/delegate', { withAuth: true }).then(res => {
window.localStorage.setItem('delegateToken', delegateToken)
if (this.token !== '') {
this.$router.push({ query: { delegateToken: this.token } })
}
clearTimeout(this.loadingHandle)
this.loading = false
this.enabled = true
const organization = res.data.data
this.$store.commit('SET_DATA', organization.proposedVersion)
this.$nextTick(() => {
setTimeout(this.$refs.tabs.callSlider, 200)
setTimeout(this.$refs.tabs.callSlider, 400)
setTimeout(this.$refs.tabs.callSlider, 500)
setTimeout(this.$refs.tabs.callSlider, 1000)
setTimeout(this.$refs.tabs.callSlider, 1500)
})
}).catch(() => {
clearTimeout(this.loadingHandle)
this.loading = false
if (this.token !== '' || inUrl) {
this.$store.commit('ADD_ALERT', {
color: 'error',
text: 'Clée invalide !'
})
}
})
},
logout () {
window.localStorage.removeItem('delegateToken')
this.$router.push('/')
},
save () {
this.isSaving = true
const data = this.$store.state.data
data.pricing = data.pricing.map(i => {
delete i._id
return i
})
this.$apitator.put('/delegate', data, { withAuth: true }).then(() => {
this.isSaving = false
this.$store.commit('ADD_ALERT', {
color: 'success',
text: 'Vos changements ont été sauvegardés !'
})
}).catch(() => {
this.isSaving = false
this.$store.commit('ADD_ALERT', {
color: 'error',
text: 'Impossible de sauvegarder vos changements'
})
})
},
navigate (routeName) {
if (routeName !== this.$route.name) {
this.$router.push({ name: routeName })
}
},
submitForm () {
if (this.token !== '') {
this.init()
}
}
}
}
</script>