Skip to content

Commit 81e2078

Browse files
delete classroom
1 parent dadc2d4 commit 81e2078

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

src/api/classroom.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ export const classroom = {
2626
return res.data
2727
},
2828

29+
async delete (pk: Classroom['pk']): Promise<void> {
30+
const endpoint = replacePk(endpoints.classroom.classroomDelete, pk)
31+
await Vue.axios.delete(endpoint)
32+
},
33+
2934
async addStudents (pk: Classroom['pk'], payload: AddStudentReq[]): Promise<void> {
3035
const endpoint = replacePk(endpoints.classroom.addStudents, pk)
3136
await Vue.axios.post(endpoint, payload)

src/api/endpoints.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const endpoints = {
1515
classroomDetail: '/classroom/classrooms/<pk>/',
1616
classroomCreate: '/classroom/classrooms/',
1717
classroomUpdate: '/classroom/classrooms/<pk>/',
18+
classroomDelete: '/classroom/classrooms/<pk>/',
1819
addStudents: '/classroom/classrooms/<pk>/add-students/',
1920
removeStudents: '/classroom/classrooms/<pk>/remove-students/',
2021
addReadingExercises: '/classroom/classrooms/<pk>/add-reading-exercises/',

src/layouts/LayoutClassroomTeacher.vue

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<v-list-item-title>Edit</v-list-item-title>
4747
</v-list-item-content>
4848
</v-list-item>
49-
<v-list-item>
49+
<v-list-item @click="confirmDelete = true">
5050
<v-list-item-icon>
5151
<v-icon>mdi-delete-outline</v-icon>
5252
</v-list-item-icon>
@@ -77,6 +77,45 @@
7777
<router-view v-if="classroomFound" class="mt-5"></router-view>
7878
</div>
7979
</v-container>
80+
81+
<v-dialog
82+
v-model="confirmDelete"
83+
width="500"
84+
>
85+
<v-card>
86+
<v-card-title>
87+
Please confirm
88+
</v-card-title>
89+
<v-card-text>
90+
<p>
91+
You are deleting classroom <strong>{{ classroom.name }}</strong>.
92+
</p>
93+
<div class="error--text">
94+
<v-icon color="error">
95+
mdi-alert-outline
96+
</v-icon>
97+
This cannot be undone!
98+
</div>
99+
</v-card-text>
100+
<v-card-actions>
101+
<v-spacer></v-spacer>
102+
<v-btn
103+
text
104+
@click="confirmDelete = false"
105+
>
106+
Cancel
107+
</v-btn>
108+
<v-btn
109+
color="primary"
110+
depressed
111+
:loading="deleting"
112+
@click="deleteClassroom"
113+
>
114+
Confirm
115+
</v-btn>
116+
</v-card-actions>
117+
</v-card>
118+
</v-dialog>
80119
</LayoutDefault>
81120
</template>
82121

@@ -147,6 +186,26 @@ export default class LayoutClassroomTeacher extends Vue {
147186
{ text: 'Listening exercises', to: { name: 'ClassroomExercisesListening' } }
148187
]
149188
189+
/**
190+
* Delete classroom
191+
*/
192+
confirmDelete = false
193+
deleting = false
194+
195+
deleteClassroom (): void {
196+
if (this.deleting) return
197+
this.deleting = true
198+
199+
this.$store.dispatch('classroom/delete', this.classroom.pk)
200+
.then(() => {
201+
this.$router.push({ name: 'ClassroomList' })
202+
})
203+
.catch(unexpectedExc)
204+
.finally(() => {
205+
this.deleting = false
206+
})
207+
}
208+
150209
// @ts-expect-error: don't care
151210
// eslint-disable-next-line
152211
beforeRouteLeave (to, from, next): void {

src/store/classroom.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ export const classroom: Module<ClassroomState, RootState> = {
4646
state.classrooms.splice(index, 1, classroom)
4747
},
4848

49+
REMOVE_CLASSROOM (state, pkDeleted) {
50+
state.classrooms = state.classrooms.filter(classroom => classroom.pk !== pkDeleted)
51+
},
52+
4953
ADD_STUDENT_TO_CURRENT_CLASSROOM (state, student) {
5054
if (state.currentClassroom !== undefined) {
5155
state.currentClassroom.students.push(student)
@@ -114,6 +118,11 @@ export const classroom: Module<ClassroomState, RootState> = {
114118
commit('EDIT_CLASSROOM', data)
115119
},
116120

121+
async delete ({ commit }, pk: Classroom['pk']): Promise<void> {
122+
await Api.classroom.delete(pk)
123+
commit('REMOVE_CLASSROOM', pk)
124+
},
125+
117126
async addStudents ({ state, commit }, payload: AddStudentReq[]): Promise<void> {
118127
if (state.currentClassroom === undefined) return
119128
await Api.classroom.addStudents(state.currentClassroom.pk, payload)

0 commit comments

Comments
 (0)