Add option for admins to remove courses

This commit is contained in:
2022-11-06 18:55:21 +01:00
parent 74b61de983
commit 860e50831d
4 changed files with 71 additions and 2 deletions

View File

@@ -0,0 +1,64 @@
<template>
<v-dialog v-model="show" max-width="500" persistent>
<template #activator="{ on, attrs }">
<v-card v-bind="attrs" v-on="on">
<v-card-text class="text-h6 error--text">
<v-icon left color="error">mdi-delete</v-icon>
Kurs löschen
</v-card-text>
</v-card>
</template>
<v-card>
<v-card-title>Kurs löschen</v-card-title>
<v-card-text class="text-subtitle-1">
Möchtest du den Kurs <strong>{{ courseId.toUpperCase() }}</strong> dauerhaft und unwiderruflich löschen?
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn text color="primary" @click="show = false">Abbrechen</v-btn>
<v-btn depressed color="primary" :loading="loading" @click="deleteCourse">Löschen</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</template>
<script>
import { doc, deleteDoc } from 'firebase/firestore'
export default {
name: 'RemoveCourseDialog',
props: {
courseId: {
type: String,
required: true
}
},
data () {
return {
show: false,
loading: false
}
},
methods: {
deleteCourse () {
this.loading = true
// Delete document
deleteDoc(doc(this.$db, `kurse/${this.courseId}`))
.then((docRef) => {
// Successfully deleted the course from the database.
this.$store.commit('setCourse', { courseId: this.courseId, courseData: null })
this.$toast({content: `Der Kurs "${this.courseId.toUpperCase()}" wurde gelöscht.`, color: 'success'})
this.show = false
this.$router.push({ name: 'dashboard' })
})
.catch((error) => {
// Failed to add a new course to the database; display error message
this.$toast({content: error, color: 'error'})
})
.then(() => { this.loading = false })
}
}
}
</script>

View File

@@ -1,5 +1,10 @@
<template> <template>
<v-container fluid> <v-container fluid>
<v-row v-if="$store.getters.isAdmin">
<v-col cols="12">
<RemoveCourse :course-id="courseID" />
</v-col>
</v-row>
<v-row> <v-row>
<v-col cols="12" sm="6"> <v-col cols="12" sm="6">
<v-card height="100%" class="d-flex align-center pa-2"> <v-card height="100%" class="d-flex align-center pa-2">

View File

@@ -83,7 +83,6 @@ export default {
return new Date(str).toLocaleString('de-DE') return new Date(str).toLocaleString('de-DE')
}, },
changeProfilePic () { changeProfilePic () {
// TODO
this.$toast({ content: 'Diese Funktion ist in der Demo-Version nicht verfügbar.', color: 'info', timeout: 3000 }) this.$toast({ content: 'Diese Funktion ist in der Demo-Version nicht verfügbar.', color: 'info', timeout: 3000 })
}, },
save () { save () {

View File

@@ -48,7 +48,8 @@ export const mutations = {
state.user.courses.splice(index, 1) state.user.courses.splice(index, 1)
}, },
setCourse (state, { courseID, courseData }) { setCourse (state, { courseID, courseData }) {
this._vm.$set(state.courses, courseID, courseData) if (courseData) this._vm.$set(state.courses, courseID, courseData)
else this._vm.$delete(state.courses, courseID)
}, },
setSelectedCourse (state, courseID) { setSelectedCourse (state, courseID) {
state.selectedCourse = courseID state.selectedCourse = courseID