feat: add delete class action and confirm dialog in class list and detail views
This commit is contained in:
@@ -11,6 +11,16 @@
|
||||
@click="$router.push(`/financial-reports?classId=${classId}`)"
|
||||
/>
|
||||
</PermissionGate>
|
||||
<PermissionGate permission="classes:delete">
|
||||
<Button
|
||||
label="حذف کلاس"
|
||||
icon="pi pi-trash"
|
||||
severity="danger"
|
||||
text
|
||||
class="ml-2"
|
||||
@click="confirmDeleteClass"
|
||||
/>
|
||||
</PermissionGate>
|
||||
<Button label="ویرایش" icon="pi pi-pencil" class="ml-2" @click="$router.push(`/classes/edit/${classId}`)" />
|
||||
<Button label="بازگشت" icon="pi pi-arrow-left" text severity="secondary" @click="$router.push('/classes')" />
|
||||
</PageHeader>
|
||||
@@ -135,12 +145,20 @@
|
||||
:loading="!!removingUserId"
|
||||
@confirm="handleRemoveStudent"
|
||||
/>
|
||||
|
||||
<ConfirmDeleteDialog
|
||||
v-model="deleteClassDialogVisible"
|
||||
title="حذف کلاس"
|
||||
:message="deleteClassDialogMessage"
|
||||
:loading="isDeletingClass"
|
||||
@confirm="handleDeleteClass"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, onMounted } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { classApi } from '@/api/classApi';
|
||||
import { formatClassDays, formatClassTime } from '@/utils/classSchedule';
|
||||
import { sessionApi } from '@/api/sessionApi';
|
||||
@@ -157,6 +175,7 @@ import DataTable from 'primevue/datatable';
|
||||
import Column from 'primevue/column';
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const classId = route.params.id;
|
||||
const { toPersianDigits, formatJalali } = usePersianDate();
|
||||
const { showError, showSuccess } = useToast();
|
||||
@@ -170,6 +189,34 @@ const removeDialogVisible = ref(false);
|
||||
const removingUserId = ref('');
|
||||
const studentToRemove = ref(null);
|
||||
|
||||
const deleteClassDialogVisible = ref(false);
|
||||
const isDeletingClass = ref(false);
|
||||
|
||||
const deleteClassDialogMessage = computed(() => {
|
||||
const name = classData.value?.name;
|
||||
return name
|
||||
? `آیا از حذف کلاس «${name}» اطمینان دارید؟ تمام جلسات و پیوندهای مرتبط با این کلاس نیز به سطل زباله منتقل میشوند.`
|
||||
: 'آیا از حذف این کلاس اطمینان دارید؟ تمام جلسات و پیوندهای مرتبط با این کلاس نیز به سطل زباله منتقل میشوند.';
|
||||
});
|
||||
|
||||
const confirmDeleteClass = () => {
|
||||
deleteClassDialogVisible.value = true;
|
||||
};
|
||||
|
||||
const handleDeleteClass = async () => {
|
||||
isDeletingClass.value = true;
|
||||
try {
|
||||
await classApi.delete(classId);
|
||||
showSuccess('کلاس و جلسات مرتبط با موفقیت حذف شدند');
|
||||
deleteClassDialogVisible.value = false;
|
||||
router.push('/classes');
|
||||
} catch (err) {
|
||||
showError(err);
|
||||
} finally {
|
||||
isDeletingClass.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const removeDialogMessage = computed(() => {
|
||||
const name = studentToRemove.value?.name;
|
||||
return name
|
||||
|
||||
Reference in New Issue
Block a user