This commit is contained in:
sajjadtalkhabi
2026-05-21 15:51:32 +03:30
parent 8990ceaddd
commit 74227d5021
71 changed files with 2014 additions and 1666 deletions
@@ -96,14 +96,16 @@ import NoItems from '@/components/blocks/NoItems.vue'
import CircleButton from '@/components/CircleButton.vue'
import { adminTermsKeys } from '@/services/query/admin-terms'
import SkeletonLoaderBlock from '@/components/blocks/SkeletonLoaderBlock.vue'
import { useAdminCourseTemplatesListQuery } from '@/services/query/admin-course-templates'
import {
adminCoursesKeys,
useAddAdminCourseMutation,
useAdminCoursesListQuery,
useDeleteAdminCourseMutation,
useUpdateAdminCourseMutation,
} from '@/services/query/admin-courses'
// TODO: repurpose this modal as "copy course from another term" — the original
// flow (link a stand-alone template to a term) no longer matches the unified
// course model. Until then, this stays a stand-alone-course → new-offered-course copy.
defineOptions({ name: 'AttachCourseToTermModal' })
const queryClient = useQueryClient()
@@ -116,7 +118,7 @@ const searchQuery = ref('')
const templateFilters = computed(() => ({ title: searchQuery.value }))
const templatePagination = ref({ page: 1, perPage: 20 })
const { data: templatesResponse, isLoading } = useAdminCourseTemplatesListQuery(
const { data: templatesResponse, isLoading } = useAdminCoursesListQuery(
templateFilters,
templatePagination
)
@@ -124,18 +126,24 @@ const { data: templatesResponse, isLoading } = useAdminCourseTemplatesListQuery(
const templates = computed(() => templatesResponse.value?.data ?? [])
const courseFilters = computed(() => ({ termId: termId.value }))
const coursePagination = ref({ page: 1, perPage: 100 })
const coursePagination = ref({ page: 1, perPage: 10 })
const { data: coursesResponse } = useAdminCoursesListQuery(courseFilters, coursePagination, {
enabled: () => !!termId.value,
})
const attachedCourses = computed(() => coursesResponse.value?.data ?? [])
const attachedCourseByTemplate = (templateId) =>
attachedCourses.value.find((c) => c.template?.id === templateId || c.templateId === templateId)
// Tracks which stand-alone course (termId=null) has already been copied
// into this term. We match by title since the unified model no longer
// keeps a back-reference to the source course.
const attachedCourseByTemplate = (sourceId) => {
const source = templates.value.find((t) => t.id === sourceId)
if (!source) return null
return attachedCourses.value.find((c) => c.title === source.title)
}
const teacherName = (template) => {
const t = template.defaultTeacher || template.teacher
const teacherName = (course) => {
const t = course.teacher
if (!t) return '—'
return `${t.firstName || ''} ${t.lastName || ''}`.trim() || t.fullName || '—'
}
@@ -147,8 +155,7 @@ const onSearch = useDebounce((event) => {
const pendingId = ref(null)
const addMutation = useAddAdminCourseMutation()
const deleteMutation = useDeleteAdminCourseMutation()
const updateMutation = useUpdateAdminCourseMutation()
const invalidate = () => {
queryClient.invalidateQueries({ queryKey: adminCoursesKeys.all })
@@ -156,16 +163,12 @@ const invalidate = () => {
}
const onAttach = async (template) => {
console.log(template)
if (!termId.value) return
pendingId.value = template.id
try {
await addMutation.mutateAsync({
termId: termId.value,
templateId: template.id,
title: template.title,
capacity: template.defaultCapacity ?? null,
isActive: template.isActiveByDefault ?? true,
})
await updateMutation.mutateAsync({ id: template.id, payload: { termId: termId.value } })
invalidate()
} finally {
pendingId.value = null
@@ -177,7 +180,7 @@ const onDetach = async (template) => {
if (!offered) return
pendingId.value = template.id
try {
await deleteMutation.mutateAsync(offered.id)
await updateMutation.mutateAsync({ id: template.id, payload: { termId: null } })
invalidate()
} finally {
pendingId.value = null
@@ -303,7 +306,7 @@ watch(termId, () => {
&__footer {
display: flex;
justify-content: flex-start;
justify-content: flex-end;
}
&__close-btn {