first commit
This commit is contained in:
@@ -0,0 +1,227 @@
|
||||
<template>
|
||||
<div class="term-item">
|
||||
<div class="term-item__main">
|
||||
<div v-if="term.image" class="term-item__image">
|
||||
<img :src="term.image" :alt="term.title" />
|
||||
</div>
|
||||
<div v-else class="term-item__image term-item__image--placeholder">
|
||||
<SvgIcon name="book" :size="24" color="#bcbcbc" />
|
||||
</div>
|
||||
<p class="term-item__title">{{ term.title }}</p>
|
||||
</div>
|
||||
|
||||
<div class="term-item__dates">
|
||||
<div class="term-item__date">
|
||||
<span class="term-item__date-label">تاریخ شروع:</span>
|
||||
<span class="term-item__date-value">{{ startDate || '—' }}</span>
|
||||
</div>
|
||||
<div class="term-item__date">
|
||||
<span class="term-item__date-label">تاریخ پایان:</span>
|
||||
<span class="term-item__date-value">{{ endDate || '—' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="!term.isActive" class="term-item__status">
|
||||
<span class="term-item__status-badge">
|
||||
<span class="term-item__status-dot" />
|
||||
غیرفعال
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="term-item__actions">
|
||||
<ToggleSwitch
|
||||
:model-value="!!term.isActive"
|
||||
@update:model-value="emit('change-status', { id: term.id, isActive: !term.isActive })"
|
||||
/>
|
||||
<CircleButton
|
||||
tooltip="حذف"
|
||||
bg-color="rgba(104, 104, 104, 0.05)"
|
||||
size="2.5rem"
|
||||
@click="emit('delete', term)"
|
||||
>
|
||||
<template #icon>
|
||||
<SvgIcon name="trash" :size="18" color="var(--color-error)" />
|
||||
</template>
|
||||
</CircleButton>
|
||||
<CircleButton
|
||||
tooltip="کپی"
|
||||
bg-color="rgba(104, 104, 104, 0.05)"
|
||||
size="2.5rem"
|
||||
@click="emit('clone', term)"
|
||||
>
|
||||
<template #icon>
|
||||
<SvgIcon name="copy" :size="18" color="var(--color-sec-gray)" />
|
||||
</template>
|
||||
</CircleButton>
|
||||
<CircleButton
|
||||
tooltip="ویرایش"
|
||||
bg-color="rgba(104, 104, 104, 0.05)"
|
||||
size="2.5rem"
|
||||
@click="emit('edit', term)"
|
||||
>
|
||||
<template #icon>
|
||||
<SvgIcon name="pencil" :size="18" color="var(--color-sec-gray)" />
|
||||
</template>
|
||||
</CircleButton>
|
||||
<BaseButton
|
||||
text="جزئیات ترم"
|
||||
custom-class="term-item__details-btn"
|
||||
@click="emit('show-details', term)"
|
||||
>
|
||||
<template #appendIcon>
|
||||
<SvgIcon name="caret-left" :size="16" color="#fff" />
|
||||
</template>
|
||||
</BaseButton>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
|
||||
import BaseButton from '@/components/BaseButton.vue'
|
||||
import CircleButton from '@/components/CircleButton.vue'
|
||||
import ToggleSwitch from '@/components/form/ToggleSwitch.vue'
|
||||
import SvgIcon from '@/components/icons/SvgIcon.vue'
|
||||
import { formatJalaaliDate } from '@/utils/date-utils'
|
||||
|
||||
const props = defineProps({
|
||||
term: { type: Object, required: true },
|
||||
})
|
||||
|
||||
const emit = defineEmits(['edit', 'delete', 'clone', 'change-status', 'show-details'])
|
||||
|
||||
const startDate = computed(
|
||||
() => props.term.faStartDate || formatJalaaliDate(props.term.startDate) || ''
|
||||
)
|
||||
const endDate = computed(() => props.term.faEndDate || formatJalaaliDate(props.term.endDate) || '')
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.term-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.625rem;
|
||||
padding: 0.75rem;
|
||||
background: rgba(255, 255, 255, 50%);
|
||||
box-shadow: 0 4px 10px -6px rgba(241, 241, 241, 70%);
|
||||
border-radius: 0.875rem;
|
||||
margin-bottom: 0.625rem;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
flex-flow: row wrap;
|
||||
align-items: center;
|
||||
gap: 0.625rem;
|
||||
}
|
||||
|
||||
&__main {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.625rem;
|
||||
min-width: 0;
|
||||
flex: 1 1 33%;
|
||||
}
|
||||
|
||||
&__image {
|
||||
width: 3rem;
|
||||
height: 3rem;
|
||||
min-width: 3rem;
|
||||
border-radius: 0.375rem;
|
||||
border: 1px solid #eee;
|
||||
overflow: hidden;
|
||||
flex-shrink: 0;
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
&--placeholder {
|
||||
background: #f5f5f5;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
|
||||
&__title {
|
||||
font-family: var(--font-family-fa);
|
||||
font-size: 1rem;
|
||||
color: #4b4b4b;
|
||||
margin: 0;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
&__dates {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.375rem;
|
||||
flex: 1 1 33%;
|
||||
}
|
||||
|
||||
&__date {
|
||||
background: rgba(107, 107, 107, 5%);
|
||||
padding: 0.25rem 1rem;
|
||||
border-radius: 0.875rem;
|
||||
line-height: 1.5;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
&__date-label {
|
||||
font-family: var(--font-family-fa);
|
||||
font-weight: 300;
|
||||
font-size: 0.75rem;
|
||||
color: #848484;
|
||||
margin-inline-end: 0.25rem;
|
||||
}
|
||||
|
||||
&__date-value {
|
||||
font-family: var(--font-family-en);
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
&__status {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
&__status-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
padding: 0.25rem 1rem;
|
||||
border-radius: 0.875rem;
|
||||
background: rgba(204, 40, 49, 6%);
|
||||
color: var(--color-error);
|
||||
font-family: var(--font-family-fa);
|
||||
font-size: 0.7rem;
|
||||
}
|
||||
|
||||
&__status-dot {
|
||||
width: 0.375rem;
|
||||
height: 0.375rem;
|
||||
border-radius: 9999px;
|
||||
background: currentcolor;
|
||||
}
|
||||
|
||||
&__actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
flex: 1 1 100%;
|
||||
|
||||
@media (min-width: 1024px) {
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
}
|
||||
|
||||
&__details-btn {
|
||||
min-width: 8rem;
|
||||
padding: 0 0.875rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,124 @@
|
||||
<template>
|
||||
<form class="terms-filters" @submit.prevent="onSubmit">
|
||||
<div class="terms-filters__grid">
|
||||
<TextField v-model="form.title" name="title" label="عنوان">
|
||||
<template #appendIcon>
|
||||
<SvgIcon name="book" :size="20" color="var(--color-thd-gray)" />
|
||||
</template>
|
||||
</TextField>
|
||||
<SelectField
|
||||
v-model="form.status"
|
||||
name="status"
|
||||
label="وضعیت"
|
||||
:options="statusOptions"
|
||||
option-label="label"
|
||||
option-value="value"
|
||||
/>
|
||||
<DatePickerField v-model="form.fromDate" name="fromDate" label="از تاریخ" :max="todayIso" />
|
||||
<DatePickerField v-model="form.toDate" name="toDate" label="تا تاریخ" :max="todayIso" />
|
||||
</div>
|
||||
|
||||
<div class="terms-filters__actions">
|
||||
<CircleButton
|
||||
v-if="hasFilters"
|
||||
tooltip="حذف فیلتر"
|
||||
bg-color="transparent"
|
||||
size="2.5rem"
|
||||
type="button"
|
||||
@click="onReset"
|
||||
>
|
||||
<template #icon>
|
||||
<SvgIcon name="close" :size="20" />
|
||||
</template>
|
||||
</CircleButton>
|
||||
<CircleButton
|
||||
tooltip="اعمال فیلتر"
|
||||
bg-color="rgba(104, 104, 104, 0.05)"
|
||||
size="2.5rem"
|
||||
type="submit"
|
||||
>
|
||||
<template #icon>
|
||||
<SvgIcon name="funnel" :size="20" color="var(--color-error)" />
|
||||
</template>
|
||||
</CircleButton>
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref, watch } from 'vue'
|
||||
|
||||
import TextField from '@/components/form/TextField.vue'
|
||||
import SelectField from '@/components/form/SelectField.vue'
|
||||
import DatePickerField from '@/components/form/DatePickerField.vue'
|
||||
import CircleButton from '@/components/CircleButton.vue'
|
||||
import SvgIcon from '@/components/icons/SvgIcon.vue'
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: {
|
||||
type: Object,
|
||||
default: () => ({ title: '', status: '', fromDate: '', toDate: '' }),
|
||||
},
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:modelValue', 'apply', 'reset'])
|
||||
|
||||
const emptyForm = () => ({ title: '', status: '', fromDate: '', toDate: '' })
|
||||
const form = ref({ ...emptyForm(), ...props.modelValue })
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(next) => {
|
||||
form.value = { ...emptyForm(), ...next }
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
const todayIso = new Date().toISOString()
|
||||
|
||||
const statusOptions = [
|
||||
{ value: 1, label: 'فعال' },
|
||||
{ value: 0, label: 'غیرفعال' },
|
||||
]
|
||||
|
||||
const hasFilters = computed(() =>
|
||||
Object.values(form.value).some((v) => v !== '' && v !== null && v !== undefined)
|
||||
)
|
||||
|
||||
const onSubmit = () => {
|
||||
emit('update:modelValue', { ...form.value })
|
||||
emit('apply', { ...form.value })
|
||||
}
|
||||
|
||||
const onReset = () => {
|
||||
form.value = emptyForm()
|
||||
emit('update:modelValue', { ...form.value })
|
||||
emit('reset')
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.terms-filters {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.625rem;
|
||||
|
||||
&__grid {
|
||||
flex: 1;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: 0.5rem;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
&__actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
padding-top: 1.75rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,304 @@
|
||||
<template>
|
||||
<BasicModal width="95%" max-width="42rem" min-width="auto" :show-close-button="true">
|
||||
<template #default="{ close }">
|
||||
<div class="add-term-student">
|
||||
<LineTitleBlock title="افزودن دانشجو" title-en="Add Student" />
|
||||
|
||||
<div class="add-term-student__search">
|
||||
<SvgIcon name="user" :size="18" color="var(--color-thd-gray)" />
|
||||
<input
|
||||
v-model="searchInput"
|
||||
type="text"
|
||||
class="add-term-student__search-input"
|
||||
placeholder="اسم دانشجو را وارد نمایید"
|
||||
@input="onSearchInput"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<SkeletonLoaderBlock v-if="isLoading" :rows="4" :cols-per-row="1" />
|
||||
|
||||
<div v-else-if="users.length > 0" class="add-term-student__list">
|
||||
<div v-for="user in users" :key="user.id" class="add-term-student__row">
|
||||
<div class="add-term-student__main">
|
||||
<div v-if="user.avatarUrl" class="add-term-student__avatar">
|
||||
<img :src="user.avatarUrl" :alt="userLabel(user)" />
|
||||
</div>
|
||||
<div v-else class="add-term-student__avatar add-term-student__avatar--placeholder">
|
||||
<SvgIcon name="user" :size="20" color="#bcbcbc" />
|
||||
</div>
|
||||
<div class="add-term-student__text">
|
||||
<p class="add-term-student__name">{{ userLabel(user) }}</p>
|
||||
<p class="add-term-student__meta">
|
||||
<span>{{ user.address?.province?.name || '—' }}</span>
|
||||
<span class="add-term-student__sep">،</span>
|
||||
<span>{{ user.address?.city?.name || '—' }}</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<CircleButton
|
||||
v-if="isAttached(user.id)"
|
||||
tooltip="حذف از ترم"
|
||||
bg-color="rgba(104, 104, 104, 0.05)"
|
||||
size="2.25rem"
|
||||
type="button"
|
||||
:loading="pendingId === user.id"
|
||||
@click="onDetach(user)"
|
||||
>
|
||||
<template #icon>
|
||||
<SvgIcon name="trash" :size="16" color="var(--color-error)" />
|
||||
</template>
|
||||
</CircleButton>
|
||||
<CircleButton
|
||||
v-else
|
||||
tooltip="افزودن به ترم"
|
||||
bg-color="rgba(104, 104, 104, 0.05)"
|
||||
size="2.25rem"
|
||||
type="button"
|
||||
:loading="pendingId === user.id"
|
||||
@click="onAttach(user)"
|
||||
>
|
||||
<template #icon>
|
||||
<SvgIcon name="plus" :size="16" color="var(--color-sec-gray)" />
|
||||
</template>
|
||||
</CircleButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<NoItems v-else title="بدون نتیجه" desc="دانشجویی یافت نشد." />
|
||||
|
||||
<div class="add-term-student__divider" />
|
||||
|
||||
<div class="add-term-student__footer">
|
||||
<BaseButton text="تایید" custom-class="add-term-student__close-btn" @click="close">
|
||||
<template #appendIcon>
|
||||
<SvgIcon name="arrow-left" :size="18" color="#fff" />
|
||||
</template>
|
||||
</BaseButton>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</BasicModal>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { useQueryClient } from '@tanstack/vue-query'
|
||||
|
||||
import BasicModal from '@/components/BasicModal.vue'
|
||||
import BaseButton from '@/components/BaseButton.vue'
|
||||
import CircleButton from '@/components/CircleButton.vue'
|
||||
import LineTitleBlock from '@/components/LineTitleBlock.vue'
|
||||
import NoItems from '@/components/blocks/NoItems.vue'
|
||||
import SkeletonLoaderBlock from '@/components/blocks/SkeletonLoaderBlock.vue'
|
||||
import SvgIcon from '@/components/icons/SvgIcon.vue'
|
||||
import useModal from '@/composables/useModal'
|
||||
import useDebounce from '@/composables/useDebounce'
|
||||
import {
|
||||
adminTermsKeys,
|
||||
useAddAdminTermStudentsMutation,
|
||||
useAdminTermStudentsQuery,
|
||||
useRemoveAdminTermStudentMutation,
|
||||
} from '@/services/query/admin-terms'
|
||||
import { useAdminUsersListQuery } from '@/services/query/admin-users'
|
||||
|
||||
defineOptions({ name: 'AddTermStudentModal' })
|
||||
|
||||
const queryClient = useQueryClient()
|
||||
const { getModal } = useModal()
|
||||
|
||||
const modalData = computed(() => getModal('AddTermStudentModal')?.data ?? {})
|
||||
const termId = computed(() => modalData.value.termId ?? null)
|
||||
|
||||
const searchInput = ref('')
|
||||
const searchQuery = ref('')
|
||||
const userFilters = computed(() => ({ name: searchQuery.value }))
|
||||
const userPagination = ref({ page: 1, perPage: 20 })
|
||||
|
||||
const { data: usersResponse, isLoading } = useAdminUsersListQuery(userFilters, userPagination)
|
||||
const users = computed(() => usersResponse.value?.data ?? [])
|
||||
|
||||
const attachedFilters = computed(() => ({}))
|
||||
const attachedPagination = ref({ page: 1, perPage: 200 })
|
||||
const { data: attachedResponse } = useAdminTermStudentsQuery(
|
||||
termId,
|
||||
attachedFilters,
|
||||
attachedPagination,
|
||||
{ enabled: () => !!termId.value }
|
||||
)
|
||||
const attachedIds = computed(() => new Set((attachedResponse.value?.data ?? []).map((u) => u.id)))
|
||||
|
||||
const isAttached = (id) => attachedIds.value.has(id)
|
||||
|
||||
const userLabel = (user) =>
|
||||
`${user.firstName || ''} ${user.lastName || ''}`.trim() ||
|
||||
user.fullName ||
|
||||
user.phoneNumber ||
|
||||
'—'
|
||||
|
||||
const onSearchInput = useDebounce(() => {
|
||||
searchQuery.value = searchInput.value || ''
|
||||
userPagination.value = { ...userPagination.value, page: 1 }
|
||||
}, 400)
|
||||
|
||||
const pendingId = ref(null)
|
||||
|
||||
const addMutation = useAddAdminTermStudentsMutation()
|
||||
const removeMutation = useRemoveAdminTermStudentMutation()
|
||||
|
||||
const invalidate = () => queryClient.invalidateQueries({ queryKey: adminTermsKeys.all })
|
||||
|
||||
const onAttach = async (user) => {
|
||||
if (!termId.value) return
|
||||
pendingId.value = user.id
|
||||
try {
|
||||
await addMutation.mutateAsync({
|
||||
termId: termId.value,
|
||||
payload: { userIds: [user.id] },
|
||||
})
|
||||
invalidate()
|
||||
} finally {
|
||||
pendingId.value = null
|
||||
}
|
||||
}
|
||||
|
||||
const onDetach = async (user) => {
|
||||
if (!termId.value) return
|
||||
pendingId.value = user.id
|
||||
try {
|
||||
await removeMutation.mutateAsync({ termId: termId.value, userId: user.id })
|
||||
invalidate()
|
||||
} finally {
|
||||
pendingId.value = null
|
||||
}
|
||||
}
|
||||
|
||||
watch(termId, () => {
|
||||
searchInput.value = ''
|
||||
searchQuery.value = ''
|
||||
pendingId.value = null
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.add-term-student {
|
||||
width: 100%;
|
||||
text-align: start;
|
||||
padding: 0.5rem 0.25rem;
|
||||
|
||||
&__search {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
margin-block: 1rem;
|
||||
padding: 0 1rem;
|
||||
height: 2.75rem;
|
||||
border: 1px solid var(--color-thd-gray);
|
||||
border-radius: 9999px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
&__search-input {
|
||||
flex: 1;
|
||||
border: none;
|
||||
outline: none;
|
||||
background: transparent;
|
||||
font-family: var(--font-family-fa);
|
||||
font-size: 0.875rem;
|
||||
color: #4b4b4b;
|
||||
text-align: start;
|
||||
|
||||
&::placeholder {
|
||||
color: var(--color-prim-gray);
|
||||
}
|
||||
}
|
||||
|
||||
&__list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
max-height: 22rem;
|
||||
overflow-y: auto;
|
||||
padding-inline-end: 0.25rem;
|
||||
}
|
||||
|
||||
&__row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.625rem;
|
||||
padding: 0.625rem 0.875rem;
|
||||
background: rgba(255, 255, 255, 85%);
|
||||
border-radius: 0.875rem;
|
||||
box-shadow: 0 4px 10px -6px rgba(241, 241, 241, 70%);
|
||||
}
|
||||
|
||||
&__main {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.625rem;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
&__avatar {
|
||||
width: 2.5rem;
|
||||
height: 2.5rem;
|
||||
border-radius: 9999px;
|
||||
overflow: hidden;
|
||||
border: 1px solid #eee;
|
||||
flex-shrink: 0;
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
&--placeholder {
|
||||
background: #f5f5f5;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
|
||||
&__text {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
&__name {
|
||||
font-family: var(--font-family-fa);
|
||||
font-size: 0.95rem;
|
||||
color: #4b4b4b;
|
||||
margin: 0 0 0.25rem;
|
||||
}
|
||||
|
||||
&__meta {
|
||||
font-family: var(--font-family-fa);
|
||||
font-size: 0.75rem;
|
||||
font-weight: 300;
|
||||
color: #848484;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
&__sep {
|
||||
color: #c4c4c4;
|
||||
margin-inline: 0.25rem;
|
||||
}
|
||||
|
||||
&__divider {
|
||||
border-block-end: 1px solid var(--color-thd-gray);
|
||||
margin-block: 1rem;
|
||||
}
|
||||
|
||||
&__footer {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
&__close-btn {
|
||||
min-width: 12rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,315 @@
|
||||
<template>
|
||||
<BasicModal
|
||||
title="افزودن دوره"
|
||||
title-en="Add Course"
|
||||
width="95%"
|
||||
max-width="42rem"
|
||||
min-width="auto"
|
||||
:show-close-button="true"
|
||||
>
|
||||
<template #default="{ close }">
|
||||
<div class="attach-course">
|
||||
<div class="attach-course__search">
|
||||
<SvgIcon name="book" :size="18" color="var(--color-thd-gray)" />
|
||||
<input
|
||||
v-model="searchQuery"
|
||||
type="text"
|
||||
class="attach-course__search-input"
|
||||
placeholder="عنوان دوره مورد نظر را جستوجو کنید"
|
||||
@input="onSearch"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<SkeletonLoaderBlock v-if="isLoading" :rows="4" :cols-per-row="1" />
|
||||
|
||||
<div v-else-if="templates.length > 0" class="attach-course__list">
|
||||
<div v-for="template in templates" :key="template.id" class="attach-course__row">
|
||||
<div class="attach-course__main">
|
||||
<div class="attach-course__image">
|
||||
<img v-if="template.image" :src="template.image" :alt="template.title" />
|
||||
<SvgIcon v-else name="book" :size="20" color="#bcbcbc" />
|
||||
</div>
|
||||
<div class="attach-course__text">
|
||||
<p class="attach-course__title">{{ template.title }}</p>
|
||||
<p class="attach-course__teacher">
|
||||
<SvgIcon name="user" :size="11" color="#bcbcbc" />
|
||||
<span class="attach-course__teacher-label">استاد:</span>
|
||||
<span class="attach-course__teacher-name">{{ teacherName(template) }}</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<CircleButton
|
||||
v-if="attachedCourseByTemplate(template.id)"
|
||||
tooltip="حذف از ترم"
|
||||
bg-color="rgba(104, 104, 104, 0.05)"
|
||||
size="2.25rem"
|
||||
type="button"
|
||||
:loading="pendingId === template.id"
|
||||
@click="onDetach(template)"
|
||||
>
|
||||
<template #icon>
|
||||
<SvgIcon name="trash" :size="16" color="var(--color-error)" />
|
||||
</template>
|
||||
</CircleButton>
|
||||
<CircleButton
|
||||
v-else
|
||||
tooltip="افزودن به ترم"
|
||||
bg-color="rgba(104, 104, 104, 0.05)"
|
||||
size="2.25rem"
|
||||
type="button"
|
||||
:loading="pendingId === template.id"
|
||||
@click="onAttach(template)"
|
||||
>
|
||||
<template #icon>
|
||||
<SvgIcon name="plus" :size="16" color="var(--color-sec-gray)" />
|
||||
</template>
|
||||
</CircleButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<NoItems v-else title="بدون نتیجه" desc="دوره الگویی یافت نشد." />
|
||||
|
||||
<div class="attach-course__divider" />
|
||||
|
||||
<div class="attach-course__footer">
|
||||
<BaseButton text="تایید" custom-class="attach-course__close-btn" @click="close">
|
||||
<template #appendIcon>
|
||||
<SvgIcon name="arrow-left" :size="18" color="#fff" />
|
||||
</template>
|
||||
</BaseButton>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</BasicModal>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { useQueryClient } from '@tanstack/vue-query'
|
||||
|
||||
import BasicModal from '@/components/BasicModal.vue'
|
||||
import BaseButton from '@/components/BaseButton.vue'
|
||||
import CircleButton from '@/components/CircleButton.vue'
|
||||
import LineTitleBlock from '@/components/LineTitleBlock.vue'
|
||||
import NoItems from '@/components/blocks/NoItems.vue'
|
||||
import SkeletonLoaderBlock from '@/components/blocks/SkeletonLoaderBlock.vue'
|
||||
import SvgIcon from '@/components/icons/SvgIcon.vue'
|
||||
import useModal from '@/composables/useModal'
|
||||
import useDebounce from '@/composables/useDebounce'
|
||||
import { useAdminCourseTemplatesListQuery } from '@/services/query/admin-course-templates'
|
||||
import {
|
||||
adminCoursesKeys,
|
||||
useAddAdminCourseMutation,
|
||||
useAdminCoursesListQuery,
|
||||
useDeleteAdminCourseMutation,
|
||||
} from '@/services/query/admin-courses'
|
||||
import { adminTermsKeys } from '@/services/query/admin-terms'
|
||||
|
||||
defineOptions({ name: 'AttachCourseToTermModal' })
|
||||
|
||||
const queryClient = useQueryClient()
|
||||
const { getModal } = useModal()
|
||||
|
||||
const modalData = computed(() => getModal('AttachCourseToTermModal')?.data ?? {})
|
||||
const termId = computed(() => modalData.value.termId ?? null)
|
||||
|
||||
const searchQuery = ref('')
|
||||
const templateFilters = computed(() => ({ title: searchQuery.value }))
|
||||
const templatePagination = ref({ page: 1, perPage: 20 })
|
||||
|
||||
const { data: templatesResponse, isLoading } = useAdminCourseTemplatesListQuery(
|
||||
templateFilters,
|
||||
templatePagination
|
||||
)
|
||||
|
||||
const templates = computed(() => templatesResponse.value?.data ?? [])
|
||||
|
||||
const courseFilters = computed(() => ({ termId: termId.value }))
|
||||
const coursePagination = ref({ page: 1, perPage: 100 })
|
||||
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)
|
||||
|
||||
const teacherName = (template) => {
|
||||
const t = template.defaultTeacher || template.teacher
|
||||
if (!t) return '—'
|
||||
return `${t.firstName || ''} ${t.lastName || ''}`.trim() || t.fullName || '—'
|
||||
}
|
||||
|
||||
const onSearch = useDebounce((event) => {
|
||||
searchQuery.value = event.target?.value || ''
|
||||
templatePagination.value = { ...templatePagination.value, page: 1 }
|
||||
}, 400)
|
||||
|
||||
const pendingId = ref(null)
|
||||
|
||||
const addMutation = useAddAdminCourseMutation()
|
||||
const deleteMutation = useDeleteAdminCourseMutation()
|
||||
|
||||
const invalidate = () => {
|
||||
queryClient.invalidateQueries({ queryKey: adminCoursesKeys.all })
|
||||
queryClient.invalidateQueries({ queryKey: adminTermsKeys.all })
|
||||
}
|
||||
|
||||
const onAttach = async (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,
|
||||
})
|
||||
invalidate()
|
||||
} finally {
|
||||
pendingId.value = null
|
||||
}
|
||||
}
|
||||
|
||||
const onDetach = async (template) => {
|
||||
const offered = attachedCourseByTemplate(template.id)
|
||||
if (!offered) return
|
||||
pendingId.value = template.id
|
||||
try {
|
||||
await deleteMutation.mutateAsync(offered.id)
|
||||
invalidate()
|
||||
} finally {
|
||||
pendingId.value = null
|
||||
}
|
||||
}
|
||||
|
||||
watch(termId, () => {
|
||||
searchQuery.value = ''
|
||||
pendingId.value = null
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.attach-course {
|
||||
width: 100%;
|
||||
text-align: start;
|
||||
padding: 0.5rem 0.25rem;
|
||||
|
||||
&__search {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
margin-block: 1rem;
|
||||
padding: 0 1rem;
|
||||
height: 2.75rem;
|
||||
border: 1px solid var(--color-thd-gray);
|
||||
border-radius: 9999px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
&__search-input {
|
||||
flex: 1;
|
||||
border: none;
|
||||
outline: none;
|
||||
background: transparent;
|
||||
font-family: var(--font-family-fa);
|
||||
font-size: 0.875rem;
|
||||
color: #4b4b4b;
|
||||
text-align: start;
|
||||
|
||||
&::placeholder {
|
||||
color: var(--color-prim-gray);
|
||||
}
|
||||
}
|
||||
|
||||
&__list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
max-height: 22rem;
|
||||
overflow-y: auto;
|
||||
padding-inline-end: 0.25rem;
|
||||
}
|
||||
|
||||
&__row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.625rem;
|
||||
padding: 0.625rem 0.875rem;
|
||||
background: rgba(255, 255, 255, 85%);
|
||||
border-radius: 0.875rem;
|
||||
box-shadow: 0 4px 10px -6px rgba(241, 241, 241, 70%);
|
||||
}
|
||||
|
||||
&__main {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.625rem;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
&__image {
|
||||
width: 2.5rem;
|
||||
height: 2.5rem;
|
||||
border-radius: 0.5rem;
|
||||
overflow: hidden;
|
||||
background: #f5f5f5;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
}
|
||||
|
||||
&__text {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
&__title {
|
||||
font-family: var(--font-family-fa);
|
||||
font-size: 0.95rem;
|
||||
color: #4b4b4b;
|
||||
margin: 0 0 0.25rem;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
&__teacher {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
font-family: var(--font-family-fa);
|
||||
font-size: 0.75rem;
|
||||
color: #848484;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
&__teacher-label {
|
||||
color: #b7b7b7;
|
||||
}
|
||||
|
||||
&__divider {
|
||||
border-block-end: 1px solid var(--color-thd-gray);
|
||||
margin-block: 1rem;
|
||||
}
|
||||
|
||||
&__footer {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
&__close-btn {
|
||||
min-width: 12rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,465 @@
|
||||
<template>
|
||||
<BasicModal width="95%" max-width="80rem" min-width="auto" :show-close-button="true">
|
||||
<template #default="{ data, close }">
|
||||
<div v-if="!term" class="term-details">
|
||||
<p class="term-details__loading">در حال بارگذاری…</p>
|
||||
</div>
|
||||
<div v-else class="term-details">
|
||||
<section class="term-details__section">
|
||||
<LineTitleBlock title="جزئیات ترم" title-en="Term Details" />
|
||||
<div class="term-details__overview">
|
||||
<div class="term-details__image">
|
||||
<img v-if="term.image" :src="term.image" :alt="term.title" />
|
||||
<SvgIcon v-else name="book" :size="32" color="#bcbcbc" />
|
||||
</div>
|
||||
<div class="term-details__overview-grid">
|
||||
<LineInfoBlock title="عنوان ترم" :desc="term.title || '-'" />
|
||||
<LineInfoBlock
|
||||
title="تاریخ شروع"
|
||||
:numeric-desc="term.faStartDate || formatJalaaliDate(term.startDate) || '-'"
|
||||
/>
|
||||
<LineInfoBlock
|
||||
title="تاریخ پایان"
|
||||
:numeric-desc="term.faEndDate || formatJalaaliDate(term.endDate) || '-'"
|
||||
/>
|
||||
<LineInfoBlock title="تعداد دانشجویان" :numeric-desc="term.studentsCount ?? 0" />
|
||||
<LineInfoBlock title="تعداد دورهها" :numeric-desc="term.coursesCount ?? 0" />
|
||||
<LineInfoBlock title="وضعیت" :desc="term.isActive ? 'فعال' : 'غیرفعال'" />
|
||||
<div v-if="term.description" class="term-details__cell--full">
|
||||
<LineInfoBlock title="توضیحات" :desc="term.description" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<TabsBlock :tabs="tabs" v-model="activeTab">
|
||||
<template #students>
|
||||
<div class="term-details__panel-header">
|
||||
<LineTitleBlock title="لیست دانشجویان این ترم" title-en="Students List" />
|
||||
<BaseButton
|
||||
text="افزودن دانشجو"
|
||||
custom-class="term-details__panel-btn"
|
||||
@click="onOpenAddStudent"
|
||||
>
|
||||
<template #appendIcon>
|
||||
<SvgIcon name="arrow-left" :size="16" color="#fff" />
|
||||
</template>
|
||||
</BaseButton>
|
||||
</div>
|
||||
|
||||
<SkeletonLoaderBlock v-if="studentsPending" :rows="4" :cols-per-row="1" />
|
||||
<div v-else-if="students.length > 0">
|
||||
<div v-for="student in students" :key="student.id" class="term-details__student-row">
|
||||
<div class="term-details__student-main">
|
||||
<div v-if="student.avatarUrl" class="term-details__avatar">
|
||||
<img :src="student.avatarUrl" :alt="studentName(student)" />
|
||||
</div>
|
||||
<div v-else class="term-details__avatar term-details__avatar--placeholder">
|
||||
<SvgIcon name="user" :size="20" color="#bcbcbc" />
|
||||
</div>
|
||||
<div>
|
||||
<p class="term-details__student-name">{{ studentName(student) }}</p>
|
||||
<p class="term-details__student-meta">
|
||||
<span>{{ student.address?.province?.name || '—' }}</span>
|
||||
<span class="term-details__sep">،</span>
|
||||
<span>{{ student.address?.city?.name || '—' }}</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="term-details__student-actions">
|
||||
<ToggleSwitch
|
||||
:model-value="!!student.isOnLeave"
|
||||
@update:model-value="onToggleLeave(student, $event)"
|
||||
/>
|
||||
<CircleButton
|
||||
tooltip="حذف از ترم"
|
||||
bg-color="rgba(104, 104, 104, 0.05)"
|
||||
size="2.5rem"
|
||||
@click="onAskRemoveStudent(student)"
|
||||
>
|
||||
<template #icon>
|
||||
<SvgIcon name="trash" :size="18" color="var(--color-error)" />
|
||||
</template>
|
||||
</CircleButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<NoItems v-else title="متاسفیم" desc="دانشجویی برای نمایش وجود ندارد." />
|
||||
|
||||
<PaginationBlock :pagination="studentPaginationMeta" @update:page="setStudentPage" />
|
||||
</template>
|
||||
|
||||
<template #courses>
|
||||
<div class="term-details__panel-header">
|
||||
<LineTitleBlock title="لیست دورههای این ترم" title-en="Courses List" />
|
||||
<BaseButton
|
||||
text="افزودن دوره"
|
||||
custom-class="term-details__panel-btn"
|
||||
@click="onOpenAddCourse"
|
||||
>
|
||||
<template #appendIcon>
|
||||
<SvgIcon name="arrow-left" :size="16" color="#fff" />
|
||||
</template>
|
||||
</BaseButton>
|
||||
</div>
|
||||
|
||||
<SkeletonLoaderBlock v-if="coursesPending" :rows="4" :cols-per-row="1" />
|
||||
<div v-else-if="termCourses.length > 0">
|
||||
<CourseItem
|
||||
v-for="course in termCourses"
|
||||
:key="course.id"
|
||||
:course="course"
|
||||
@edit="onEditCourse"
|
||||
@delete="onAskDeleteCourse"
|
||||
@change-status="onChangeCourseStatus"
|
||||
@show-details="onShowCourseDetails"
|
||||
/>
|
||||
</div>
|
||||
<NoItems v-else title="متاسفیم" desc="دورهای برای نمایش وجود ندارد." />
|
||||
|
||||
<PaginationBlock :pagination="coursePaginationMeta" @update:page="setCoursePage" />
|
||||
</template>
|
||||
</TabsBlock>
|
||||
|
||||
<div class="term-details__divider" />
|
||||
|
||||
<div class="term-details__footer">
|
||||
<BaseButton text="بستن" custom-class="term-details__close-btn" @click="close">
|
||||
<template #appendIcon>
|
||||
<SvgIcon name="arrow-left" :size="18" color="#fff" />
|
||||
</template>
|
||||
</BaseButton>
|
||||
</div>
|
||||
</div>
|
||||
<span class="term-details__data-tap" v-if="false">{{ data }}</span>
|
||||
</template>
|
||||
</BasicModal>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref } from 'vue'
|
||||
import { useQueryClient } from '@tanstack/vue-query'
|
||||
|
||||
import BasicModal from '@/components/BasicModal.vue'
|
||||
import BaseButton from '@/components/BaseButton.vue'
|
||||
import CircleButton from '@/components/CircleButton.vue'
|
||||
import LineTitleBlock from '@/components/LineTitleBlock.vue'
|
||||
import LineInfoBlock from '@/components/blocks/LineInfoBlock.vue'
|
||||
import NoItems from '@/components/blocks/NoItems.vue'
|
||||
import SkeletonLoaderBlock from '@/components/blocks/SkeletonLoaderBlock.vue'
|
||||
import PaginationBlock from '@/components/blocks/PaginationBlock.vue'
|
||||
import TabsBlock from '@/components/blocks/TabsBlock.vue'
|
||||
import ToggleSwitch from '@/components/form/ToggleSwitch.vue'
|
||||
import SvgIcon from '@/components/icons/SvgIcon.vue'
|
||||
import useModal from '@/composables/useModal'
|
||||
import { usePagination } from '@/composables/usePagination'
|
||||
import CourseItem from '@/features/admin/courses/components/CourseItem.vue'
|
||||
import {
|
||||
adminTermsKeys,
|
||||
useAdminTermQuery,
|
||||
useAdminTermStudentsQuery,
|
||||
useRemoveAdminTermStudentMutation,
|
||||
useToggleAdminTermStudentLeaveMutation,
|
||||
} from '@/services/query/admin-terms'
|
||||
import {
|
||||
adminCoursesKeys,
|
||||
useAdminCoursesListQuery,
|
||||
useChangeAdminCourseStatusMutation,
|
||||
useDeleteAdminCourseMutation,
|
||||
} from '@/services/query/admin-courses'
|
||||
import { formatJalaaliDate } from '@/utils/date-utils'
|
||||
|
||||
defineOptions({ name: 'TermDetailsModal' })
|
||||
|
||||
const queryClient = useQueryClient()
|
||||
const { openModal, getModal } = useModal()
|
||||
|
||||
const modalData = computed(() => getModal('TermDetailsModal')?.data ?? {})
|
||||
const termId = computed(() => modalData.value.id ?? null)
|
||||
|
||||
const { data: term } = useAdminTermQuery(termId, {
|
||||
enabled: () => !!termId.value,
|
||||
})
|
||||
|
||||
const tabs = [
|
||||
{ name: 'students', label: 'دانشجویان', icon: 'users' },
|
||||
{ name: 'courses', label: 'دورهها', icon: 'list-bullets' },
|
||||
]
|
||||
const activeTab = ref('students')
|
||||
|
||||
const studentFilters = ref({})
|
||||
const {
|
||||
pagination: studentPagination,
|
||||
setPage: setStudentPage,
|
||||
reset: resetStudentPagination,
|
||||
} = usePagination({ page: 1, perPage: 10 })
|
||||
|
||||
const { data: studentsData, isLoading: studentsPending } = useAdminTermStudentsQuery(
|
||||
termId,
|
||||
studentFilters,
|
||||
studentPagination,
|
||||
{
|
||||
enabled: () => !!termId.value && activeTab.value === 'students',
|
||||
keepPreviousData: true,
|
||||
}
|
||||
)
|
||||
|
||||
const students = computed(() => studentsData.value?.data ?? [])
|
||||
const studentPaginationMeta = computed(() => ({
|
||||
page: studentPagination.value.page,
|
||||
perPage: studentPagination.value.perPage,
|
||||
...studentsData.value?.meta,
|
||||
}))
|
||||
|
||||
const studentName = (student) =>
|
||||
`${student.firstName || ''} ${student.lastName || ''}`.trim() || student.fullName || '—'
|
||||
|
||||
const invalidate = () => queryClient.invalidateQueries({ queryKey: adminTermsKeys.all })
|
||||
|
||||
const toggleLeaveMutation = useToggleAdminTermStudentLeaveMutation()
|
||||
const removeStudentMutation = useRemoveAdminTermStudentMutation()
|
||||
|
||||
const onToggleLeave = (student, isOnLeave) => {
|
||||
toggleLeaveMutation.mutate(
|
||||
{
|
||||
termId: termId.value,
|
||||
userId: student.id,
|
||||
payload: { setLeave: isOnLeave },
|
||||
},
|
||||
{ onSuccess: invalidate }
|
||||
)
|
||||
}
|
||||
|
||||
const onAskRemoveStudent = (student) => {
|
||||
openModal('ConfirmModal', {
|
||||
title: `حذف ${studentName(student)}`,
|
||||
message: `آیا از حذف <strong>${studentName(student)}</strong> از این ترم اطمینان دارید؟`,
|
||||
onConfirm: () =>
|
||||
removeStudentMutation.mutate(
|
||||
{ termId: termId.value, userId: student.id },
|
||||
{ onSuccess: invalidate }
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
const courseFilters = computed(() => ({ termId: termId.value }))
|
||||
const { pagination: coursePagination, setPage: setCoursePage } = usePagination({
|
||||
page: 1,
|
||||
perPage: 10,
|
||||
})
|
||||
|
||||
const { data: coursesData, isLoading: coursesPending } = useAdminCoursesListQuery(
|
||||
courseFilters,
|
||||
coursePagination,
|
||||
{
|
||||
enabled: () => !!termId.value && activeTab.value === 'courses',
|
||||
keepPreviousData: true,
|
||||
}
|
||||
)
|
||||
|
||||
const termCourses = computed(() => coursesData.value?.data ?? [])
|
||||
const coursePaginationMeta = computed(() => ({
|
||||
page: coursePagination.value.page,
|
||||
perPage: coursePagination.value.perPage,
|
||||
...coursesData.value?.meta,
|
||||
}))
|
||||
|
||||
const invalidateCourses = () => queryClient.invalidateQueries({ queryKey: adminCoursesKeys.all })
|
||||
|
||||
const deleteCourseMutation = useDeleteAdminCourseMutation()
|
||||
const changeCourseStatusMutation = useChangeAdminCourseStatusMutation()
|
||||
|
||||
const onOpenAddCourse = () => {
|
||||
openModal('AttachCourseToTermModal', { termId: termId.value })
|
||||
}
|
||||
|
||||
const onEditCourse = (course) => {
|
||||
openModal('AddOfferedCourseModal', { mode: 'edit', courseId: course.id })
|
||||
}
|
||||
|
||||
const onShowCourseDetails = (course) => {
|
||||
openModal('CourseDetailsModal', { id: course.id })
|
||||
}
|
||||
|
||||
const onAskDeleteCourse = (course) => {
|
||||
openModal('ConfirmModal', {
|
||||
title: `حذف ${course.title}`,
|
||||
message: `بعد از حذف امکان بازگشت وجود ندارد، آیا از حذف <strong>${course.title}</strong> اطمینان دارید؟`,
|
||||
onConfirm: () => deleteCourseMutation.mutate(course.id, { onSuccess: invalidateCourses }),
|
||||
})
|
||||
}
|
||||
|
||||
const onChangeCourseStatus = ({ id, isActive }) => {
|
||||
changeCourseStatusMutation.mutate({ id, payload: { isActive } }, { onSuccess: invalidateCourses })
|
||||
}
|
||||
|
||||
const onOpenAddStudent = () => {
|
||||
openModal('AddTermStudentModal', { termId: termId.value })
|
||||
resetStudentPagination()
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.term-details {
|
||||
width: 100%;
|
||||
text-align: start;
|
||||
|
||||
&__loading {
|
||||
text-align: center;
|
||||
padding: 2rem;
|
||||
color: var(--color-prim-gray);
|
||||
}
|
||||
|
||||
&__section {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
&__overview {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
align-items: flex-start;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
&__image {
|
||||
width: 5rem;
|
||||
height: 5rem;
|
||||
border-radius: 0.5rem;
|
||||
background: #f5f5f5;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
}
|
||||
|
||||
&__overview-grid {
|
||||
flex: 1;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: 0.25rem;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
}
|
||||
|
||||
@media (min-width: 1280px) {
|
||||
grid-template-columns: repeat(5, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
&__cell--full {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
&__panel-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.625rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
&__panel-btn {
|
||||
min-width: 11rem;
|
||||
padding: 0 1rem;
|
||||
margin-inline-start: auto;
|
||||
}
|
||||
|
||||
&__placeholder {
|
||||
text-align: center;
|
||||
color: var(--color-prim-gray);
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
&__student-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 0.625rem 0.875rem;
|
||||
background: rgba(255, 255, 255, 85%);
|
||||
border-radius: 0.875rem;
|
||||
box-shadow: 0 4px 10px -6px rgba(241, 241, 241, 70%);
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
&__student-main {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.625rem;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
&__avatar {
|
||||
width: 2.5rem;
|
||||
height: 2.5rem;
|
||||
border-radius: 9999px;
|
||||
overflow: hidden;
|
||||
border: 1px solid #eee;
|
||||
flex-shrink: 0;
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
&--placeholder {
|
||||
background: #f5f5f5;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
|
||||
&__student-name {
|
||||
font-family: var(--font-family-fa);
|
||||
font-size: 0.95rem;
|
||||
color: #4b4b4b;
|
||||
margin: 0 0 0.25rem;
|
||||
}
|
||||
|
||||
&__student-meta {
|
||||
font-family: var(--font-family-fa);
|
||||
font-size: 0.75rem;
|
||||
font-weight: 300;
|
||||
color: #848484;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
&__sep {
|
||||
color: #c4c4c4;
|
||||
margin-inline: 0.25rem;
|
||||
}
|
||||
|
||||
&__student-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
}
|
||||
|
||||
&__divider {
|
||||
border-block-end: 1px solid var(--color-thd-gray);
|
||||
margin-block: 1.5rem;
|
||||
}
|
||||
|
||||
&__footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
&__close-btn {
|
||||
min-width: 12rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,298 @@
|
||||
<template>
|
||||
<div class="term-form">
|
||||
<BoxedIconTitleBlock
|
||||
class="term-form__heading"
|
||||
:title="isEditMode ? 'ویرایش ترم' : 'افزودن ترم جدید'"
|
||||
:desc="
|
||||
isEditMode ? 'اطلاعات ترم را بهروز کنید' : 'در این قسمت میتوانید ترم جدید اضافه کنید'
|
||||
"
|
||||
>
|
||||
<template #icon>
|
||||
<SvgIcon name="book" :size="24" color="var(--color-primary)" />
|
||||
</template>
|
||||
</BoxedIconTitleBlock>
|
||||
|
||||
<form class="term-form__form" @submit.prevent="onSubmit">
|
||||
<div class="term-form__grid">
|
||||
<div class="term-form__image-col">
|
||||
<ImageCropper
|
||||
v-model="image"
|
||||
name="image"
|
||||
bg-color="#eeeeee"
|
||||
@crop="onImageCropped"
|
||||
@error="onImageError"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="term-form__main-col">
|
||||
<LineTitleBlock title="اطلاعات ترم" title-en="Term Details" />
|
||||
<div class="term-form__row">
|
||||
<div class="term-form__cell term-form__cell--third">
|
||||
<TextField
|
||||
v-model="form.title"
|
||||
name="title"
|
||||
label="عنوان ترم"
|
||||
:error="errors.title"
|
||||
@blur="validateAt('title', form.title)"
|
||||
>
|
||||
<template #appendIcon>
|
||||
<SvgIcon name="book" :size="20" color="var(--color-thd-gray)" />
|
||||
</template>
|
||||
</TextField>
|
||||
</div>
|
||||
<div class="term-form__cell term-form__cell--third">
|
||||
<DatePickerField
|
||||
v-model="form.startDate"
|
||||
name="startDate"
|
||||
label="تاریخ شروع"
|
||||
:min="todayIso"
|
||||
:error="errors.startDate"
|
||||
/>
|
||||
</div>
|
||||
<div class="term-form__cell term-form__cell--third">
|
||||
<DatePickerField
|
||||
v-model="form.endDate"
|
||||
name="endDate"
|
||||
label="تاریخ پایان"
|
||||
:min="todayIso"
|
||||
:error="errors.endDate"
|
||||
/>
|
||||
</div>
|
||||
<div class="term-form__cell term-form__cell--full">
|
||||
<TextareaField
|
||||
v-model="form.description"
|
||||
name="description"
|
||||
label="توضیحات"
|
||||
:row="5"
|
||||
:error="errors.description"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="term-form__divider" />
|
||||
|
||||
<div class="term-form__actions">
|
||||
<BaseButton
|
||||
variant="transparent"
|
||||
text="منصرف شدم"
|
||||
custom-class="term-form__btn-cancel"
|
||||
@click="onCancel"
|
||||
>
|
||||
<template #prependIcon>
|
||||
<SvgIcon name="caret-right" :size="14" color="var(--color-sec-gray)" />
|
||||
</template>
|
||||
</BaseButton>
|
||||
<BaseButton
|
||||
type="submit"
|
||||
:text="isEditMode ? 'ذخیره تغییرات' : 'تایید اطلاعات'"
|
||||
:loading="submitting"
|
||||
custom-class="term-form__btn-submit"
|
||||
>
|
||||
<template #appendIcon>
|
||||
<SvgIcon name="arrow-left" :size="20" color="#fff" />
|
||||
</template>
|
||||
</BaseButton>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { toast } from 'vue3-toastify'
|
||||
import { useQueryClient } from '@tanstack/vue-query'
|
||||
import BoxedIconTitleBlock from '@/components/blocks/BoxedIconTitleBlock.vue'
|
||||
import LineTitleBlock from '@/components/LineTitleBlock.vue'
|
||||
import BaseButton from '@/components/BaseButton.vue'
|
||||
import TextField from '@/components/form/TextField.vue'
|
||||
import TextareaField from '@/components/form/TextareaField.vue'
|
||||
import DatePickerField from '@/components/form/DatePickerField.vue'
|
||||
import ImageCropper from '@/components/form/ImageCropper.vue'
|
||||
import SvgIcon from '@/components/icons/SvgIcon.vue'
|
||||
import useYup from '@/composables/useYup'
|
||||
import {
|
||||
adminTermsKeys,
|
||||
useAddAdminTermMutation,
|
||||
useAdminTermQuery,
|
||||
useUpdateAdminTermMutation,
|
||||
} from '@/services/query/admin-terms'
|
||||
import { useUploadTemporaryMutation } from '@/services/query/auth'
|
||||
import { termSchema } from '@/features/admin/terms/schema'
|
||||
import { objectToFormData } from '@/utils/object-to-formdata'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
const termId = computed(() => (route.params.id ? Number(route.params.id) : null))
|
||||
const isEditMode = computed(() => !!termId.value)
|
||||
|
||||
const todayIso = new Date().toISOString()
|
||||
|
||||
const form = ref({
|
||||
title: '',
|
||||
startDate: '',
|
||||
endDate: '',
|
||||
description: '',
|
||||
imageId: null,
|
||||
})
|
||||
|
||||
const image = ref(null)
|
||||
|
||||
const schema = termSchema
|
||||
|
||||
const { validate, validateAt, errors } = useYup(schema)
|
||||
|
||||
const { data: existingTerm } = useAdminTermQuery(termId, {
|
||||
enabled: () => !!termId.value,
|
||||
})
|
||||
|
||||
watch(existingTerm, (term) => {
|
||||
if (!term) return
|
||||
form.value = {
|
||||
title: term.title || '',
|
||||
startDate: term.startDate || '',
|
||||
endDate: term.endDate || '',
|
||||
description: term.description || '',
|
||||
imageId: term.imageId || null,
|
||||
}
|
||||
if (term.image) image.value = { url: term.image }
|
||||
})
|
||||
|
||||
const uploadMutation = useUploadTemporaryMutation()
|
||||
|
||||
const onImageCropped = async (file) => {
|
||||
try {
|
||||
const formData = objectToFormData({ file, subType: 'avatar', context: 'term' })
|
||||
const response = await uploadMutation.mutateAsync(formData)
|
||||
const payload = response?.data ?? response
|
||||
image.value = { url: payload?.url, uploadId: payload?.uploadId, ...payload }
|
||||
form.value.imageId = payload?.uploadId || payload?.id
|
||||
} catch {
|
||||
/* handled globally */
|
||||
}
|
||||
}
|
||||
|
||||
const onImageError = (msg) => toast.error(msg)
|
||||
|
||||
const addMutation = useAddAdminTermMutation()
|
||||
const updateMutation = useUpdateAdminTermMutation()
|
||||
|
||||
const submitting = computed(() => addMutation.isPending.value || updateMutation.isPending.value)
|
||||
|
||||
const onSubmit = async () => {
|
||||
const { isValid, payload } = await validate(form.value)
|
||||
if (!isValid) return
|
||||
if (isEditMode.value) {
|
||||
await updateMutation.mutateAsync({ id: termId.value, payload })
|
||||
} else {
|
||||
await addMutation.mutateAsync(payload)
|
||||
}
|
||||
await queryClient.invalidateQueries({ queryKey: adminTermsKeys.all })
|
||||
router.push({ name: 'admin-terms' })
|
||||
}
|
||||
|
||||
const onCancel = () => router.push({ name: 'admin-terms' })
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.term-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
|
||||
&__heading {
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
&__form {
|
||||
background: rgba(255, 255, 255, 60%);
|
||||
padding: 1rem;
|
||||
border-radius: 1rem;
|
||||
}
|
||||
|
||||
&__grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: 1rem;
|
||||
|
||||
@media (min-width: 1024px) {
|
||||
grid-template-columns: 4fr 8fr;
|
||||
}
|
||||
|
||||
@media (min-width: 1280px) {
|
||||
grid-template-columns: 3fr 9fr;
|
||||
}
|
||||
}
|
||||
|
||||
&__image-col {
|
||||
order: 2;
|
||||
|
||||
@media (min-width: 1024px) {
|
||||
order: 1;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
&__main-col {
|
||||
order: 1;
|
||||
|
||||
@media (min-width: 1024px) {
|
||||
order: 2;
|
||||
padding-inline-start: 1.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
&__row {
|
||||
display: flex;
|
||||
flex-flow: column wrap;
|
||||
gap: 0.5rem;
|
||||
align-items: stretch;
|
||||
margin-bottom: 0.5rem;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
flex-direction: row;
|
||||
}
|
||||
}
|
||||
|
||||
&__cell {
|
||||
width: 100%;
|
||||
|
||||
&--third {
|
||||
@media (min-width: 768px) {
|
||||
width: 49%;
|
||||
}
|
||||
|
||||
@media (min-width: 1280px) {
|
||||
width: 32.3%;
|
||||
}
|
||||
}
|
||||
|
||||
&--full {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
&__divider {
|
||||
border-block-end: 1px solid var(--color-thd-gray);
|
||||
margin-block: 1.5rem;
|
||||
}
|
||||
|
||||
&__actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 0.625rem;
|
||||
}
|
||||
|
||||
&__btn-cancel {
|
||||
min-width: 9rem;
|
||||
}
|
||||
|
||||
&__btn-submit {
|
||||
min-width: 12rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,165 @@
|
||||
<template>
|
||||
<div class="terms-page">
|
||||
<BoxedIconTitleBlock
|
||||
class="terms-page__heading"
|
||||
title="مدیریت ترم"
|
||||
desc="در این قسمت میتوانید ترمهای خود را مدیریت کنید"
|
||||
>
|
||||
<template #icon>
|
||||
<SvgIcon name="book" :size="24" color="var(--color-primary)" />
|
||||
</template>
|
||||
</BoxedIconTitleBlock>
|
||||
|
||||
<TermsFilters v-model="filters" @apply="onFilterApply" @reset="onFilterReset" />
|
||||
|
||||
<div class="terms-page__list-header">
|
||||
<SimpleTitleIconBlock title="لیست همه ترمها" class="terms-page__list-title">
|
||||
<template #header-icon>
|
||||
<SvgIcon name="list-bullets" :size="16" color="#bcbcbc" />
|
||||
</template>
|
||||
</SimpleTitleIconBlock>
|
||||
<BaseButton text="افزودن ترم جدید" custom-class="terms-page__add-btn" @click="onAdd">
|
||||
<template #appendIcon>
|
||||
<SvgIcon name="plus" :size="18" color="#fff" />
|
||||
</template>
|
||||
</BaseButton>
|
||||
</div>
|
||||
|
||||
<SkeletonLoaderBlock v-if="isLoading" :rows="6" :cols-per-row="1" />
|
||||
<div v-else-if="terms.length > 0">
|
||||
<TermItem
|
||||
v-for="term in terms"
|
||||
:key="term.id"
|
||||
:term="term"
|
||||
@edit="onEdit"
|
||||
@delete="onAskDelete"
|
||||
@clone="onClone"
|
||||
@change-status="onChangeStatus"
|
||||
@show-details="onShowDetails"
|
||||
/>
|
||||
</div>
|
||||
<NoItems v-else title="متاسفیم" desc="ترمی برای نمایش وجود ندارد." />
|
||||
|
||||
<PaginationBlock :pagination="paginationMeta" @update:page="setPage" />
|
||||
|
||||
<TermDetailsModal v-if="isModal('TermDetailsModal')" />
|
||||
<AddTermStudentModal v-if="isModal('AddTermStudentModal')" />
|
||||
<AttachCourseToTermModal v-if="isModal('AttachCourseToTermModal')" />
|
||||
<AddOfferedCourseModal v-if="isModal('AddOfferedCourseModal')" />
|
||||
<CourseDetailsModal v-if="isModal('CourseDetailsModal')" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useQueryClient } from '@tanstack/vue-query'
|
||||
|
||||
import BoxedIconTitleBlock from '@/components/blocks/BoxedIconTitleBlock.vue'
|
||||
import SimpleTitleIconBlock from '@/components/blocks/SimpleTitleIconBlock.vue'
|
||||
import NoItems from '@/components/blocks/NoItems.vue'
|
||||
import SkeletonLoaderBlock from '@/components/blocks/SkeletonLoaderBlock.vue'
|
||||
import PaginationBlock from '@/components/blocks/PaginationBlock.vue'
|
||||
import BaseButton from '@/components/BaseButton.vue'
|
||||
import SvgIcon from '@/components/icons/SvgIcon.vue'
|
||||
import TermsFilters from '@/features/admin/terms/components/TermsFilters.vue'
|
||||
import TermItem from '@/features/admin/terms/components/TermItem.vue'
|
||||
import TermDetailsModal from '@/features/admin/terms/components/modals/TermDetailsModal.vue'
|
||||
import AddTermStudentModal from '@/features/admin/terms/components/modals/AddTermStudentModal.vue'
|
||||
import AttachCourseToTermModal from '@/features/admin/terms/components/modals/AttachCourseToTermModal.vue'
|
||||
import AddOfferedCourseModal from '@/features/admin/courses/components/modals/AddOfferedCourseModal.vue'
|
||||
import CourseDetailsModal from '@/features/admin/courses/components/modals/CourseDetailsModal.vue'
|
||||
import {
|
||||
adminTermsKeys,
|
||||
useAdminTermsListQuery,
|
||||
useChangeAdminTermStatusMutation,
|
||||
useCloneAdminTermMutation,
|
||||
useDeleteAdminTermMutation,
|
||||
} from '@/services/query/admin-terms'
|
||||
import { usePagination } from '@/composables/usePagination'
|
||||
import useModal from '@/composables/useModal'
|
||||
|
||||
const router = useRouter()
|
||||
const queryClient = useQueryClient()
|
||||
const { openModal, isModal } = useModal()
|
||||
|
||||
const filters = ref({ title: '', status: '', fromDate: '', toDate: '' })
|
||||
const { pagination, setPage, reset: resetPagination } = usePagination({ page: 1, perPage: 10 })
|
||||
|
||||
const { data, isLoading } = useAdminTermsListQuery(filters, pagination, {
|
||||
keepPreviousData: true,
|
||||
})
|
||||
|
||||
const terms = computed(() => data.value?.data ?? [])
|
||||
const paginationMeta = computed(() => ({
|
||||
page: pagination.value.page,
|
||||
perPage: pagination.value.perPage,
|
||||
...data.value?.meta,
|
||||
}))
|
||||
|
||||
const onFilterApply = () => resetPagination()
|
||||
const onFilterReset = () => resetPagination()
|
||||
|
||||
const onAdd = () => {
|
||||
router.push({ name: 'admin-add-term' }).catch(() => {})
|
||||
}
|
||||
|
||||
const onEdit = (term) => {
|
||||
router.push({ name: 'admin-edit-term', params: { id: term.id } }).catch(() => {})
|
||||
}
|
||||
|
||||
const invalidate = () => queryClient.invalidateQueries({ queryKey: adminTermsKeys.all })
|
||||
|
||||
const deleteMutation = useDeleteAdminTermMutation()
|
||||
const cloneMutation = useCloneAdminTermMutation()
|
||||
const changeStatusMutation = useChangeAdminTermStatusMutation()
|
||||
|
||||
const onAskDelete = (term) => {
|
||||
openModal('ConfirmModal', {
|
||||
title: `حذف ${term.title}`,
|
||||
message: `بعد از حذف امکان بازگشت وجود ندارد، آیا مطمئن هستید که میخواهید <strong>${term.title}</strong> را حذف کنید؟`,
|
||||
onConfirm: () => deleteMutation.mutate(term.id, { onSuccess: invalidate }),
|
||||
})
|
||||
}
|
||||
|
||||
const onClone = (term) => {
|
||||
cloneMutation.mutate(term.id, { onSuccess: invalidate })
|
||||
}
|
||||
|
||||
const onChangeStatus = ({ id, isActive }) => {
|
||||
changeStatusMutation.mutate({ id, payload: { isActive } }, { onSuccess: invalidate })
|
||||
}
|
||||
|
||||
const onShowDetails = (term) => {
|
||||
openModal('TermDetailsModal', { id: term.id })
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.terms-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
|
||||
&__heading {
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
&__list-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.625rem;
|
||||
margin-bottom: 0.375rem;
|
||||
}
|
||||
|
||||
&__list-title {
|
||||
flex: 1;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
&__add-btn {
|
||||
min-width: fit-content;
|
||||
padding: 0 1.25rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { array, mixed, object, string } from 'yup'
|
||||
|
||||
export const termSchema = object().shape({
|
||||
title: string().required().min(3),
|
||||
startDate: string().required(),
|
||||
endDate: string().required(),
|
||||
description: string().nullable().notRequired(),
|
||||
})
|
||||
|
||||
export const addTermStudentSchema = object().shape({
|
||||
studentIds: array().of(mixed()).min(1, 'حداقل یک دانشجو را انتخاب کنید').required(),
|
||||
})
|
||||
Reference in New Issue
Block a user