Compare commits
14 Commits
55ed80e652
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| c99df794b9 | |||
| af9d55e651 | |||
| 6c4bc4e575 | |||
| a967479c9f | |||
| 259bc55c86 | |||
| 43ed9740f2 | |||
| d9d573256c | |||
| 4402fb6a3d | |||
| 1cfd48f35a | |||
| 052ec8a54f | |||
| 887eb2589d | |||
| 2eb7c68f9f | |||
| d4dc4a76f8 | |||
| e10cfba09d |
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<Transition name="fade-scale" @after-enter="onOpened" @after-leave="onClosed">
|
||||
<div v-if="isOpen" class="basic-modal" @click="onBackdropClick">
|
||||
<div v-if="isOpen" class="basic-modal" :style="{ zIndex }" @click="onBackdropClick">
|
||||
<div class="basic-modal__container" :style="containerStyle" @click.stop>
|
||||
<div class="basic-modal__card scrollbar-thin">
|
||||
<header v-if="hasHeader" class="basic-modal__header">
|
||||
@@ -43,6 +43,7 @@ const props = defineProps({
|
||||
width: { type: String, default: '' },
|
||||
maxWidth: { type: String, default: '98%' },
|
||||
minWidth: { type: String, default: '85%' },
|
||||
zIndex: { type: [Number, String], default: 50 },
|
||||
})
|
||||
|
||||
const emit = defineEmits(['open', 'close'])
|
||||
@@ -101,7 +102,6 @@ onBeforeUnmount(() => window.removeEventListener('keydown', onKeydown))
|
||||
.basic-modal {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 50;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<BasicModal min-width="0" max-width="640px" width="95%" :show-close-button="false">
|
||||
<BasicModal min-width="0" max-width="640px" width="95%" :show-close-button="false" :z-index="60">
|
||||
<template #default="{ data }">
|
||||
<div class="confirm-modal">
|
||||
<h3 class="confirm-modal__title">{{ data?.title || 'تأیید حذف' }}</h3>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div class="copyright">
|
||||
<div class="copyright__text">
|
||||
<a href="https://mugweb.ir/" target="_blank" rel="noopener">
|
||||
<a href="https://madresebanoo.ir/" target="_blank" rel="noopener">
|
||||
<p class="copyright__en">All Rights Reserved. 2026</p>
|
||||
<p class="copyright__fa">تمام حقوق مادی و معنوی این وبسایت محفوظ هست.</p>
|
||||
</a>
|
||||
|
||||
@@ -283,6 +283,7 @@ onBeforeUnmount(() => unmountFloating())
|
||||
|
||||
&__value {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
text-align: start;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
<template>
|
||||
<div class="certificate-item">
|
||||
<div class="certificate-item__main">
|
||||
<p class="certificate-item__title">{{ certificate.title || '—' }}</p>
|
||||
<p class="certificate-item__student">{{ certificate.user?.name || '—' }}</p>
|
||||
</div>
|
||||
|
||||
<div class="certificate-item__meta">
|
||||
<div class="certificate-item__pill">
|
||||
<span class="certificate-item__pill-label">تاریخ صدور:</span>
|
||||
<span class="certificate-item__pill-value">{{ issuedAt }}</span>
|
||||
</div>
|
||||
<div class="certificate-item__pill">
|
||||
<span class="certificate-item__pill-label">فایلها:</span>
|
||||
<span class="certificate-item__pill-value">{{ filesLabel }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="certificate-item__actions">
|
||||
<CircleButton
|
||||
tooltip="حذف"
|
||||
bg-color="rgba(104, 104, 104, 0.05)"
|
||||
size="2.5rem"
|
||||
@click="emit('delete', certificate)"
|
||||
>
|
||||
<template #icon>
|
||||
<SvgIcon name="trash" :size="18" color="var(--color-error)" />
|
||||
</template>
|
||||
</CircleButton>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
import SvgIcon from '@/components/icons/SvgIcon.vue'
|
||||
import { formatJalaaliDate } from '@/utils/date-utils'
|
||||
import CircleButton from '@/components/CircleButton.vue'
|
||||
|
||||
const props = defineProps({
|
||||
certificate: { type: Object, required: true },
|
||||
})
|
||||
|
||||
const emit = defineEmits(['delete'])
|
||||
|
||||
const issuedAt = computed(() => formatJalaaliDate(props.certificate.issuedAt) || '—')
|
||||
|
||||
const filesLabel = computed(() => {
|
||||
const parts = []
|
||||
if (props.certificate.hasImage) parts.push('تصویر')
|
||||
if (props.certificate.hasPdf) parts.push('PDF')
|
||||
return parts.length > 0 ? parts.join(' / ') : '—'
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.certificate-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: 1024px) {
|
||||
flex-flow: row wrap;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
&__main {
|
||||
flex: 1 1 33%;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
&__title {
|
||||
font-family: var(--font-family-fa);
|
||||
font-size: 1rem;
|
||||
color: #4b4b4b;
|
||||
margin: 0 0 0.25rem;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
&__student {
|
||||
font-family: var(--font-family-fa);
|
||||
font-size: 0.75rem;
|
||||
color: #848484;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
&__meta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.375rem;
|
||||
flex: 1 1 33%;
|
||||
}
|
||||
|
||||
&__pill {
|
||||
background: rgba(107, 107, 107, 5%);
|
||||
padding: 0.25rem 1rem;
|
||||
border-radius: 0.875rem;
|
||||
line-height: 1.5;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
&__pill-label {
|
||||
font-family: var(--font-family-fa);
|
||||
font-weight: 300;
|
||||
font-size: 0.7rem;
|
||||
color: #535353;
|
||||
margin-inline-end: 0.25rem;
|
||||
}
|
||||
|
||||
&__pill-value {
|
||||
font-family: var(--font-family-en);
|
||||
font-size: 0.7rem;
|
||||
font-weight: 500;
|
||||
color: #535353;
|
||||
}
|
||||
|
||||
&__actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
flex: 1 1 100%;
|
||||
|
||||
@media (min-width: 1024px) {
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,292 @@
|
||||
<template>
|
||||
<BasicModal
|
||||
title="صدور گواهینامه"
|
||||
title-en="Issue Certificate"
|
||||
width="95%"
|
||||
max-width="56rem"
|
||||
min-width="auto"
|
||||
:show-close-button="true"
|
||||
>
|
||||
<template #default="{ close }">
|
||||
<form class="issue-certificate" @submit.prevent="onSubmit(close)">
|
||||
<div class="issue-certificate__grid">
|
||||
<SelectField
|
||||
v-model="form.userId"
|
||||
name="userId"
|
||||
label="طلبه"
|
||||
placeholder="نام طلبه را جستجو کنید"
|
||||
:options="userOptions"
|
||||
option-label="name"
|
||||
option-value="id"
|
||||
:searchable="true"
|
||||
:on-search="searchUsers"
|
||||
:error="errors.userId"
|
||||
/>
|
||||
<SelectField
|
||||
v-model="form.termId"
|
||||
name="termId"
|
||||
label="ترم گذراندهشده"
|
||||
placeholder="ترم را انتخاب کنید"
|
||||
:options="termOptions"
|
||||
option-label="title"
|
||||
option-value="id"
|
||||
:searchable="true"
|
||||
:on-search="searchTerms"
|
||||
:error="errors.termId"
|
||||
/>
|
||||
<SelectField
|
||||
v-model="form.courseId"
|
||||
name="courseId"
|
||||
label="دوره گذراندهشده"
|
||||
placeholder="دوره را انتخاب کنید"
|
||||
:options="courseOptions"
|
||||
option-label="title"
|
||||
option-value="id"
|
||||
:searchable="true"
|
||||
:on-search="searchCourses"
|
||||
/>
|
||||
<DatePickerField v-model="form.issuedAt" name="issuedAt" label="تاریخ صدور" />
|
||||
<DatePickerField v-model="form.startedAt" name="startedAt" label="تاریخ شروع" />
|
||||
<DatePickerField v-model="form.endedAt" name="endedAt" label="تاریخ پایان" />
|
||||
</div>
|
||||
|
||||
<p v-if="errors.termId" class="issue-certificate__hint">{{ errors.termId }}</p>
|
||||
|
||||
<div class="issue-certificate__files">
|
||||
<div class="issue-certificate__file-col">
|
||||
<label class="issue-certificate__file-label">تصویر گواهینامه (JPG/PNG)</label>
|
||||
<FileUploader
|
||||
v-model="imageFiles"
|
||||
accept="image/*"
|
||||
:multiple="false"
|
||||
:max-files="1"
|
||||
@select="onImageSelect"
|
||||
@error="onFileError"
|
||||
/>
|
||||
</div>
|
||||
<div class="issue-certificate__file-col">
|
||||
<label class="issue-certificate__file-label">فایل PDF گواهینامه</label>
|
||||
<FileUploader
|
||||
v-model="pdfFiles"
|
||||
accept="application/pdf"
|
||||
:multiple="false"
|
||||
:max-files="1"
|
||||
@select="onPdfSelect"
|
||||
@error="onFileError"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="errors.imageMediaId" class="issue-certificate__hint">{{ errors.imageMediaId }}</p>
|
||||
|
||||
<div class="issue-certificate__divider" />
|
||||
|
||||
<div class="issue-certificate__actions">
|
||||
<BaseButton
|
||||
variant="transparent"
|
||||
text="منصرف شدم"
|
||||
custom-class="issue-certificate__btn-cancel"
|
||||
@click="close"
|
||||
>
|
||||
<template #prependIcon>
|
||||
<SvgIcon name="caret-right" :size="14" color="var(--color-sec-gray)" />
|
||||
</template>
|
||||
</BaseButton>
|
||||
<BaseButton
|
||||
type="submit"
|
||||
text="صدور گواهینامه"
|
||||
:loading="submitting"
|
||||
custom-class="issue-certificate__btn-submit"
|
||||
>
|
||||
<template #appendIcon>
|
||||
<SvgIcon name="arrow-left" :size="18" color="#fff" />
|
||||
</template>
|
||||
</BaseButton>
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
</BasicModal>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref } from 'vue'
|
||||
import { toast } from 'vue3-toastify'
|
||||
import useYup from '@/composables/useYup'
|
||||
import useDebounce from '@/composables/useDebounce'
|
||||
import { useQueryClient } from '@tanstack/vue-query'
|
||||
import BasicModal from '@/components/BasicModal.vue'
|
||||
import BaseButton from '@/components/BaseButton.vue'
|
||||
import SvgIcon from '@/components/icons/SvgIcon.vue'
|
||||
import SelectField from '@/components/form/SelectField.vue'
|
||||
import FileUploader from '@/components/form/FileUploader.vue'
|
||||
import { objectToFormData } from '@/utils/object-to-formdata'
|
||||
import { useUploadMediaMutation } from '@/services/query/auth'
|
||||
import DatePickerField from '@/components/form/DatePickerField.vue'
|
||||
import { useAdminUsersListQuery } from '@/services/query/admin-users'
|
||||
import { useAdminTermsListQuery } from '@/services/query/admin-terms'
|
||||
import { certificateSchema } from '@/features/admin/certificates/schema'
|
||||
import { useAdminCoursesListQuery } from '@/services/query/admin-courses'
|
||||
import {
|
||||
adminCertificatesKeys,
|
||||
useAddAdminCertificateMutation,
|
||||
} from '@/services/query/admin-certificates'
|
||||
|
||||
defineOptions({ name: 'IssueCertificateModal' })
|
||||
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
const form = ref({
|
||||
userId: '',
|
||||
termId: '',
|
||||
courseId: '',
|
||||
issuedAt: '',
|
||||
startedAt: '',
|
||||
endedAt: '',
|
||||
})
|
||||
|
||||
const { validate, errors, resetErrors } = useYup(certificateSchema)
|
||||
|
||||
const userSearch = ref('')
|
||||
const userFilters = computed(() => ({ search: userSearch.value, roles: 'student' }))
|
||||
const userPagination = ref({ page: 1, perPage: 10 })
|
||||
const { data: usersResponse } = useAdminUsersListQuery(userFilters, userPagination)
|
||||
const userOptions = computed(() => usersResponse.value?.data ?? [])
|
||||
const searchUsers = useDebounce((q) => {
|
||||
userSearch.value = q || ''
|
||||
}, 400)
|
||||
|
||||
const termSearch = ref('')
|
||||
const termFilters = computed(() => ({ title: termSearch.value }))
|
||||
const termPagination = ref({ page: 1, perPage: 10 })
|
||||
const { data: termsResponse } = useAdminTermsListQuery(termFilters, termPagination)
|
||||
const termOptions = computed(() => termsResponse.value?.data ?? [])
|
||||
const searchTerms = useDebounce((q) => {
|
||||
termSearch.value = q || ''
|
||||
}, 400)
|
||||
|
||||
const courseSearch = ref('')
|
||||
const courseFilters = computed(() => ({ title: courseSearch.value }))
|
||||
const coursePagination = ref({ page: 1, perPage: 10 })
|
||||
const { data: coursesResponse } = useAdminCoursesListQuery(courseFilters, coursePagination)
|
||||
const courseOptions = computed(() => coursesResponse.value?.data ?? [])
|
||||
const searchCourses = useDebounce((q) => {
|
||||
courseSearch.value = q || ''
|
||||
}, 400)
|
||||
|
||||
const imageFiles = ref([])
|
||||
const pdfFiles = ref([])
|
||||
const uploadMediaMutation = useUploadMediaMutation()
|
||||
|
||||
const onImageSelect = async (files) => {
|
||||
const file = files[0]
|
||||
if (!file) return
|
||||
try {
|
||||
const fd = objectToFormData({ file, purpose: 'certificate_image' })
|
||||
const response = await uploadMediaMutation.mutateAsync(fd)
|
||||
const payload = response?.data ?? response
|
||||
imageFiles.value = [{ id: payload?.id, name: file.name, size: file.size, url: payload?.url }]
|
||||
} catch {
|
||||
toast.error('بارگذاری تصویر گواهینامه با خطا مواجه شد.')
|
||||
}
|
||||
}
|
||||
|
||||
const onPdfSelect = async (files) => {
|
||||
const file = files[0]
|
||||
if (!file) return
|
||||
try {
|
||||
const fd = objectToFormData({ file, purpose: 'certificate_pdf' })
|
||||
const response = await uploadMediaMutation.mutateAsync(fd)
|
||||
const payload = response?.data ?? response
|
||||
pdfFiles.value = [{ id: payload?.id, name: file.name, size: file.size, url: payload?.url }]
|
||||
} catch {
|
||||
toast.error('بارگذاری فایل PDF گواهینامه با خطا مواجه شد.')
|
||||
}
|
||||
}
|
||||
|
||||
const onFileError = (msg) => toast.error(msg)
|
||||
|
||||
const addMutation = useAddAdminCertificateMutation()
|
||||
const submitting = computed(() => addMutation.isPending.value)
|
||||
|
||||
const onSubmit = async (close) => {
|
||||
const payload = {
|
||||
...form.value,
|
||||
imageMediaId: imageFiles.value[0]?.id ?? null,
|
||||
pdfMediaId: pdfFiles.value[0]?.id ?? null,
|
||||
}
|
||||
const { isValid } = await validate(payload)
|
||||
if (!isValid) return
|
||||
|
||||
await addMutation.mutateAsync(payload)
|
||||
await queryClient.invalidateQueries({ queryKey: adminCertificatesKeys.all })
|
||||
resetErrors()
|
||||
close()
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.issue-certificate {
|
||||
width: 100%;
|
||||
text-align: start;
|
||||
padding: 0.5rem 0;
|
||||
|
||||
&__grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: 0.75rem;
|
||||
margin-block: 0.75rem;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
|
||||
@media (min-width: 1280px) {
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
&__hint {
|
||||
color: var(--color-error);
|
||||
font-family: var(--font-family-fa);
|
||||
font-size: 0.75rem;
|
||||
margin: -0.25rem 0 0.5rem;
|
||||
}
|
||||
|
||||
&__files {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: 1rem;
|
||||
margin-top: 0.5rem;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
&__file-label {
|
||||
display: block;
|
||||
font-family: var(--font-family-fa);
|
||||
font-size: 0.8125rem;
|
||||
color: #4b5563;
|
||||
margin-bottom: 0.375rem;
|
||||
}
|
||||
|
||||
&__divider {
|
||||
border-block-end: 1px solid var(--color-thd-gray);
|
||||
margin-block: 1.5rem;
|
||||
}
|
||||
|
||||
&__actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
&__btn-cancel {
|
||||
min-width: 9rem;
|
||||
}
|
||||
|
||||
&__btn-submit {
|
||||
min-width: 12rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,129 @@
|
||||
<template>
|
||||
<div class="certificates-page">
|
||||
<BoxedIconTitleBlock
|
||||
class="certificates-page__heading"
|
||||
title="مدیریت گواهینامهها"
|
||||
desc="در این قسمت میتوانید برای طلبهها گواهینامه صادر کنید"
|
||||
>
|
||||
<template #icon>
|
||||
<SvgIcon name="certificate" :size="24" color="var(--color-primary)" />
|
||||
</template>
|
||||
</BoxedIconTitleBlock>
|
||||
|
||||
<div class="certificates-page__list-header">
|
||||
<SimpleTitleIconBlock
|
||||
title="لیست گواهینامههای صادرشده"
|
||||
class="certificates-page__list-title"
|
||||
>
|
||||
<template #header-icon>
|
||||
<SvgIcon name="list-bullets" :size="16" color="#bcbcbc" />
|
||||
</template>
|
||||
</SimpleTitleIconBlock>
|
||||
<BaseButton
|
||||
text="صدور گواهینامه جدید"
|
||||
custom-class="certificates-page__add-btn"
|
||||
@click="onAdd"
|
||||
>
|
||||
<template #appendIcon>
|
||||
<SvgIcon name="arrow-left" :size="18" color="#fff" />
|
||||
</template>
|
||||
</BaseButton>
|
||||
</div>
|
||||
|
||||
<SkeletonLoaderBlock v-if="isLoading" :rows="6" :cols-per-row="1" />
|
||||
<div v-else-if="certificates.length > 0">
|
||||
<CertificateItem
|
||||
v-for="certificate in certificates"
|
||||
:key="certificate.id"
|
||||
:certificate="certificate"
|
||||
@delete="onAskDelete"
|
||||
/>
|
||||
</div>
|
||||
<NoItems v-else title="متاسفیم" desc="گواهینامهای برای نمایش وجود ندارد." />
|
||||
|
||||
<PaginationBlock :pagination="paginationMeta" @update:page="setPage" />
|
||||
|
||||
<IssueCertificateModal v-if="isModal('IssueCertificateModal')" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref } from 'vue'
|
||||
import useModal from '@/composables/useModal'
|
||||
import { useQueryClient } from '@tanstack/vue-query'
|
||||
import BaseButton from '@/components/BaseButton.vue'
|
||||
import SvgIcon from '@/components/icons/SvgIcon.vue'
|
||||
import NoItems from '@/components/blocks/NoItems.vue'
|
||||
import { usePagination } from '@/composables/usePagination'
|
||||
import PaginationBlock from '@/components/blocks/PaginationBlock.vue'
|
||||
import BoxedIconTitleBlock from '@/components/blocks/BoxedIconTitleBlock.vue'
|
||||
import SkeletonLoaderBlock from '@/components/blocks/SkeletonLoaderBlock.vue'
|
||||
import SimpleTitleIconBlock from '@/components/blocks/SimpleTitleIconBlock.vue'
|
||||
import CertificateItem from '@/features/admin/certificates/components/CertificateItem.vue'
|
||||
import IssueCertificateModal from '@/features/admin/certificates/components/modals/IssueCertificateModal.vue'
|
||||
import {
|
||||
adminCertificatesKeys,
|
||||
useAdminCertificatesListQuery,
|
||||
useDeleteAdminCertificateMutation,
|
||||
} from '@/services/query/admin-certificates'
|
||||
|
||||
const queryClient = useQueryClient()
|
||||
const { openModal, isModal } = useModal()
|
||||
|
||||
const filters = ref({})
|
||||
const { pagination, setPage } = usePagination({ page: 1, perPage: 10 })
|
||||
|
||||
const { data, isLoading } = useAdminCertificatesListQuery(filters, pagination, {
|
||||
keepPreviousData: true,
|
||||
})
|
||||
|
||||
const certificates = computed(() => data.value?.data ?? [])
|
||||
const paginationMeta = computed(() => ({
|
||||
page: pagination.value.page,
|
||||
perPage: pagination.value.perPage,
|
||||
...data.value?.meta,
|
||||
}))
|
||||
|
||||
const onAdd = () => openModal('IssueCertificateModal')
|
||||
|
||||
const invalidate = () => queryClient.invalidateQueries({ queryKey: adminCertificatesKeys.all })
|
||||
const deleteMutation = useDeleteAdminCertificateMutation()
|
||||
|
||||
const onAskDelete = (certificate) => {
|
||||
openModal('ConfirmModal', {
|
||||
title: `حذف گواهینامه ${certificate.user?.name || ''}`,
|
||||
message:
|
||||
'بعد از حذف امکان بازگشت وجود ندارد، آیا مطمئن هستید که میخواهید این گواهینامه را حذف کنید؟',
|
||||
onConfirm: () => deleteMutation.mutate(certificate.id, { onSuccess: invalidate }),
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.certificates-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,24 @@
|
||||
import { mixed, number, object, string } from 'yup'
|
||||
|
||||
export const certificateSchema = object()
|
||||
.shape({
|
||||
userId: number().typeError('طلبه را انتخاب کنید').required('طلبه را انتخاب کنید'),
|
||||
termId: mixed().nullable().notRequired(),
|
||||
courseId: mixed().nullable().notRequired(),
|
||||
issuedAt: string().nullable().notRequired(),
|
||||
startedAt: string().nullable().notRequired(),
|
||||
endedAt: string().nullable().notRequired(),
|
||||
imageMediaId: number().nullable().notRequired(),
|
||||
pdfMediaId: number().nullable().notRequired(),
|
||||
})
|
||||
.test('term-or-course', function (value) {
|
||||
if (value?.termId || value?.courseId) return true
|
||||
return this.createError({ path: 'termId', message: 'یکی از ترم یا دوره را انتخاب کنید' })
|
||||
})
|
||||
.test('image-or-pdf', function (value) {
|
||||
if (value?.imageMediaId || value?.pdfMediaId) return true
|
||||
return this.createError({
|
||||
path: 'imageMediaId',
|
||||
message: 'حداقل یک فایل (تصویر یا PDF) بارگذاری کنید',
|
||||
})
|
||||
})
|
||||
@@ -283,8 +283,11 @@ const addExamMutation = useAddAdminExamMutation()
|
||||
const updateExamMutation = useUpdateAdminExamMutation()
|
||||
const addQuestionMutation = useAddAdminExamQuestionMutation()
|
||||
|
||||
const isSubmitting = ref(false)
|
||||
|
||||
const submitting = computed(
|
||||
() =>
|
||||
isSubmitting.value ||
|
||||
addExamMutation.isPending.value ||
|
||||
updateExamMutation.isPending.value ||
|
||||
addQuestionMutation.isPending.value
|
||||
@@ -298,23 +301,29 @@ const postQuestionsSequentially = async (id, list) => {
|
||||
}
|
||||
|
||||
const onSubmit = async () => {
|
||||
const { isValid } = await validate(form.value)
|
||||
const newQuestions = validateLocalQuestions()
|
||||
if (!isValid || !newQuestions) return
|
||||
if (isSubmitting.value) return
|
||||
isSubmitting.value = true
|
||||
try {
|
||||
const { isValid } = await validate(form.value)
|
||||
const newQuestions = validateLocalQuestions()
|
||||
if (!isValid || !newQuestions) return
|
||||
|
||||
const examPayload = buildExamPayload(form.value)
|
||||
let targetExamId = examId.value
|
||||
if (isEditMode.value) {
|
||||
await updateExamMutation.mutateAsync({ id: targetExamId, payload: examPayload })
|
||||
} else {
|
||||
const created = await addExamMutation.mutateAsync(examPayload)
|
||||
targetExamId = created?.data?.id ?? created?.id ?? targetExamId
|
||||
const examPayload = buildExamPayload(form.value)
|
||||
let targetExamId = examId.value
|
||||
if (isEditMode.value) {
|
||||
await updateExamMutation.mutateAsync({ id: targetExamId, payload: examPayload })
|
||||
} else {
|
||||
const created = await addExamMutation.mutateAsync(examPayload)
|
||||
targetExamId = created?.data?.id ?? created?.id ?? targetExamId
|
||||
}
|
||||
if (targetExamId && newQuestions.length > 0) {
|
||||
await postQuestionsSequentially(targetExamId, newQuestions)
|
||||
}
|
||||
await queryClient.invalidateQueries({ queryKey: adminExamsKeys.all, refetchType: 'all' })
|
||||
router.push({ name: 'admin-exams' })
|
||||
} finally {
|
||||
isSubmitting.value = false
|
||||
}
|
||||
if (targetExamId && newQuestions.length > 0) {
|
||||
await postQuestionsSequentially(targetExamId, newQuestions)
|
||||
}
|
||||
await queryClient.invalidateQueries({ queryKey: adminExamsKeys.all, refetchType: 'all' })
|
||||
router.push({ name: 'admin-exams' })
|
||||
}
|
||||
|
||||
const onCancel = () => router.push({ name: 'admin-exams' })
|
||||
|
||||
@@ -274,4 +274,15 @@ export default [
|
||||
subtitle: 'درخواستهای اعزام مبلغین را مشاهده و مدیریت نمایید.',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/certificates',
|
||||
name: 'admin-certificates',
|
||||
component: () => import('@/features/admin/certificates/pages/AdminCertificatesPage.vue'),
|
||||
meta: {
|
||||
layout: 'admin',
|
||||
role: 'admin',
|
||||
title: 'گواهینامهها',
|
||||
subtitle: 'گواهینامههای دورهها را صادر و مدیریت نمایید.',
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
@@ -17,14 +17,13 @@
|
||||
</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">
|
||||
<div v-if="!term.isActive" class="term-item__status">
|
||||
<span class="term-item__status-badge">
|
||||
<span class="term-item__status-dot" />
|
||||
غیرفعال
|
||||
</span>
|
||||
</div>
|
||||
<ToggleSwitch
|
||||
:model-value="!!term.isActive"
|
||||
@update:model-value="emit('change-status', { id: term.id, isActive: !term.isActive })"
|
||||
@@ -166,10 +165,6 @@ const createdDate = computed(() => formatJalaaliDate(props.term.createdAt) || ''
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
&__status {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
&__status-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
@@ -191,6 +186,7 @@ const createdDate = computed(() => formatJalaaliDate(props.term.createdAt) || ''
|
||||
|
||||
&__actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
|
||||
@@ -70,6 +70,18 @@
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="term-details__student-actions">
|
||||
<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="طلبهای برای نمایش وجود ندارد." />
|
||||
@@ -130,18 +142,24 @@ import BaseButton from '@/components/BaseButton.vue'
|
||||
import SvgIcon from '@/components/icons/SvgIcon.vue'
|
||||
import NoItems from '@/components/blocks/NoItems.vue'
|
||||
import { formatJalaaliDate } from '@/utils/date-utils'
|
||||
import CircleButton from '@/components/CircleButton.vue'
|
||||
import TabsBlock from '@/components/blocks/TabsBlock.vue'
|
||||
import { usePagination } from '@/composables/usePagination'
|
||||
import LineTitleBlock from '@/components/LineTitleBlock.vue'
|
||||
import LineInfoBlock from '@/components/blocks/LineInfoBlock.vue'
|
||||
import PaginationBlock from '@/components/blocks/PaginationBlock.vue'
|
||||
import SkeletonLoaderBlock from '@/components/blocks/SkeletonLoaderBlock.vue'
|
||||
import { useAdminTermEnrolleesQuery, useAdminTermQuery } from '@/services/query/admin-terms'
|
||||
import {
|
||||
adminCoursesKeys,
|
||||
useAdminCoursesListQuery,
|
||||
useUpdateAdminCourseMutation,
|
||||
} from '@/services/query/admin-courses'
|
||||
import {
|
||||
adminTermsKeys,
|
||||
useAdminTermEnrolleesQuery,
|
||||
useAdminTermQuery,
|
||||
useRemoveAdminTermStudentMutation,
|
||||
} from '@/services/query/admin-terms'
|
||||
|
||||
defineOptions({ name: 'TermDetailsModal' })
|
||||
|
||||
@@ -187,6 +205,24 @@ const studentPaginationMeta = computed(() => ({
|
||||
|
||||
const studentAvatar = (student) => student.avatarUrl || student.avatarDownloadUrl || ''
|
||||
|
||||
const invalidateStudents = () => queryClient.invalidateQueries({ queryKey: adminTermsKeys.all })
|
||||
|
||||
const removeStudentMutation = useRemoveAdminTermStudentMutation()
|
||||
|
||||
const onAskRemoveStudent = (student) => {
|
||||
openModal('ConfirmModal', {
|
||||
title: `حذف ${student?.user?.name || 'طلبه'}`,
|
||||
message: `بعد از حذف، دسترسی <strong>${
|
||||
student?.user?.name || 'این طلبه'
|
||||
}</strong> به این ترم و محتوای آن قطع میشود. آیا مطمئن هستید؟`,
|
||||
onConfirm: () =>
|
||||
removeStudentMutation.mutate(
|
||||
{ termId: termId.value, userId: student.user.id },
|
||||
{ onSuccess: invalidateStudents }
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
const courseFilters = computed(() => ({ termId: termId.value }))
|
||||
const { pagination: coursePagination, setPage: setCoursePage } = usePagination({
|
||||
page: 1,
|
||||
|
||||
@@ -25,12 +25,12 @@
|
||||
<button
|
||||
type="button"
|
||||
class="users-table__role-badge"
|
||||
:class="`users-table__role-badge--${roleName(user) || 'unknown'}`"
|
||||
:class="`users-table__role-badge--${roleNames(user)[0] || 'unknown'}`"
|
||||
:disabled="updateRoleMutation.isPending.value && activeUser?.id === user.id"
|
||||
@click="onRoleClick($event, user)"
|
||||
>
|
||||
<span class="users-table__role-dot" />
|
||||
<span>{{ roleLabel(user) || 'بدون نقش' }}</span>
|
||||
<span>{{ roleLabelsText(user) || 'بدون نقش' }}</span>
|
||||
<SvgIcon name="caret-down" :size="12" color="currentColor" />
|
||||
</button>
|
||||
<Badge v-if="user.status === 'blocked'" variant="danger" size="sm" dot>
|
||||
@@ -96,15 +96,13 @@ const queryClient = useQueryClient()
|
||||
|
||||
const emit = defineEmits(['edit', 'delete', 'block', 'unblock', 'show-details'])
|
||||
|
||||
const roleName = (user) => {
|
||||
const first = user.roles?.[0]
|
||||
return typeof first === 'string' ? first : first?.name
|
||||
}
|
||||
const roleNames = (user) =>
|
||||
(user.roles || []).map((r) => (typeof r === 'string' ? r : r?.name)).filter(Boolean)
|
||||
|
||||
const roleLabel = (user) => {
|
||||
const name = roleName(user)
|
||||
if (!name) return ''
|
||||
return ROLES.find((r) => r.value === name)?.label || name
|
||||
const roleLabelsText = (user) => {
|
||||
const names = roleNames(user)
|
||||
if (names.length === 0) return ''
|
||||
return names.map((name) => ROLES.find((r) => r.value === name)?.label || name).join('، ')
|
||||
}
|
||||
|
||||
const menuOpen = ref(false)
|
||||
@@ -140,23 +138,39 @@ const onRoleClick = (event, user) => {
|
||||
roleMenuOpen.value = true
|
||||
}
|
||||
|
||||
const onChangeRole = (targetRoleName) => {
|
||||
// Toggles one role's membership without touching the user's other roles —
|
||||
// access must stay additive, so this can never collapse into a single-role
|
||||
// replace the way the old "switch to X" action used to.
|
||||
const onToggleRole = (targetRoleName, isAssigned) => {
|
||||
const user = activeUser.value
|
||||
if (!user || !targetRoleName) return
|
||||
const current = roleNames(user)
|
||||
const nextRoles = isAssigned
|
||||
? current.filter((r) => r !== targetRoleName)
|
||||
: [...current, targetRoleName]
|
||||
if (nextRoles.length === 0) return
|
||||
updateRoleMutation.mutate(
|
||||
{ id: user.id, payload: { roles: [targetRoleName] } },
|
||||
{ id: user.id, payload: { roles: nextRoles } },
|
||||
{ onSuccess: invalidateUsers }
|
||||
)
|
||||
}
|
||||
|
||||
const roleMenuItems = computed(() => {
|
||||
const current = activeUser.value ? roleName(activeUser.value) : null
|
||||
return ROLES.filter((r) => r.changeable && r.value !== current).map((r) => ({
|
||||
key: `role-${r.value}`,
|
||||
label: `تغییر به ${r.label}`,
|
||||
icon: 'arrows-clockwise',
|
||||
onClick: () => onChangeRole(r.value),
|
||||
}))
|
||||
const user = activeUser.value
|
||||
if (!user) return []
|
||||
const current = roleNames(user)
|
||||
return ROLES.filter((r) => r.changeable).map((r) => {
|
||||
const isAssigned = current.includes(r.value)
|
||||
const isLastRole = isAssigned && current.length <= 1
|
||||
return {
|
||||
key: `role-${r.value}`,
|
||||
label: isAssigned ? `حذف نقش ${r.label}` : `افزودن نقش ${r.label}`,
|
||||
icon: isAssigned ? 'close' : 'check',
|
||||
danger: isAssigned,
|
||||
disabled: isLastRole,
|
||||
onClick: () => onToggleRole(r.value, isAssigned),
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
const menuItems = computed(() => {
|
||||
|
||||
@@ -19,14 +19,15 @@
|
||||
<div class="user-form__row">
|
||||
<div class="user-form__cell user-form__cell--third">
|
||||
<SelectField
|
||||
v-model="form.role"
|
||||
name="role"
|
||||
label="نقش"
|
||||
v-model="form.roles"
|
||||
name="roles"
|
||||
label="نقشها"
|
||||
:multiple="true"
|
||||
:options="ROLES"
|
||||
option-label="label"
|
||||
option-value="value"
|
||||
:error="errors.role"
|
||||
@change="validateAt('role', form.role)"
|
||||
:error="errors.roles"
|
||||
@change="validateAt('roles', form.roles)"
|
||||
/>
|
||||
</div>
|
||||
<div class="user-form__cell user-form__cell--third">
|
||||
@@ -265,7 +266,7 @@ const { data: cities = ref([]) } = useGetCitiesOfProvinceQuery(provinceIdRef, {
|
||||
const initialNationalCode = ref('')
|
||||
|
||||
const form = ref({
|
||||
role: '',
|
||||
roles: [],
|
||||
name: '',
|
||||
birthday: '',
|
||||
nationalCode: '',
|
||||
@@ -307,11 +308,12 @@ watch(
|
||||
existingUser,
|
||||
(user) => {
|
||||
if (!user) return
|
||||
const firstRole = Array.isArray(user.roles) ? user.roles[0] : null
|
||||
const roleValue = typeof firstRole === 'object' ? firstRole?.name : firstRole
|
||||
const roleValues = Array.isArray(user.roles)
|
||||
? user.roles.map((r) => (typeof r === 'object' ? r?.name : r)).filter(Boolean)
|
||||
: []
|
||||
form.value = {
|
||||
...form.value,
|
||||
role: roleValue || '',
|
||||
roles: roleValues,
|
||||
name: user.name || `${user.firstName || ''} ${user.lastName || ''}`.trim(),
|
||||
birthday: user.birthday || '',
|
||||
nationalCode: user.nationalCode || '',
|
||||
@@ -360,7 +362,7 @@ const submitting = computed(() => addMutation.isPending.value || updateMutation.
|
||||
const buildUpdatePayload = () => {
|
||||
return {
|
||||
name: form.value.name,
|
||||
roles: form.value.role ? [form.value.role] : [],
|
||||
roles: form.value.roles,
|
||||
provinceId: form.value.provinceId || null,
|
||||
cityId: form.value.cityId || null,
|
||||
marriageStatus: form.value.maritalStatus || null,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { number, object, string } from 'yup'
|
||||
import { array, number, object, string } from 'yup'
|
||||
import { passwordRule } from '@/constants/rules/passwordRule'
|
||||
import { phoneNumberRule } from '@/constants/rules/phoneNumberRule'
|
||||
import { nationalCodeRule } from '@/constants/rules/nationalCodeRule'
|
||||
@@ -9,7 +9,7 @@ export const rejectionReasonSchema = object().shape({
|
||||
})
|
||||
|
||||
const baseUserShape = {
|
||||
role: string().required(),
|
||||
roles: array().of(string().required()).min(1, 'حداقل یک نقش را انتخاب کنید').required(),
|
||||
name: string().required().min(3),
|
||||
phone: phoneNumberRule,
|
||||
nationalCode: nationalCodeRule,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="auth-copyright">
|
||||
<a href="https://mugweb.ir/" target="_blank" rel="noopener">
|
||||
<a href="https://madresebanoo.ir/" target="_blank" rel="noopener">
|
||||
<p class="auth-copyright__fa">تمام حقوق مادی و معنوی این وبسایت محفوظ هست</p>
|
||||
<p class="auth-copyright__en">All Rights Reserved. 2026</p>
|
||||
</a>
|
||||
|
||||
@@ -2,7 +2,8 @@ import { useAuthStore } from '@/store/auth'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { MAIN_SITE_URL, ROLE_HOME_ROUTES } from '@/enums'
|
||||
|
||||
const shouldLandOnMainSite = (auth) => auth.role !== 'admin' && auth.user?.status === 'approved'
|
||||
const shouldLandOnMainSite = (auth) =>
|
||||
!auth.roles.includes('admin') && auth.user?.status === 'approved'
|
||||
|
||||
export const useRedirectAfterLogin = () => {
|
||||
const router = useRouter()
|
||||
|
||||
@@ -18,6 +18,17 @@
|
||||
<p class="student-register__desc">{{ stepLabel.desc }}</p>
|
||||
</header>
|
||||
|
||||
<div
|
||||
v-if="auth.user?.status === 'blocked'"
|
||||
class="student-register__rejection"
|
||||
role="alert"
|
||||
>
|
||||
<p class="student-register__rejection-title">احراز هویت شما توسط ادمین رد شده است.</p>
|
||||
<p class="student-register__rejection-reason">
|
||||
{{ auth.user?.blockReason || 'دلیلی ثبت نشده است.' }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div v-if="isRegistrationDataPending" class="student-register__loading" aria-live="polite">
|
||||
در حال بازیابی اطلاعات ثبتنام…
|
||||
</div>
|
||||
@@ -30,6 +41,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { useAuthStore } from '@/store/auth'
|
||||
import useModal from '@/composables/useModal'
|
||||
import { computed, markRaw, watch } from 'vue'
|
||||
import { STUDENT_REGISTRATION } from '@/enums'
|
||||
@@ -49,6 +61,7 @@ import EducationalInformation from '@/features/auth/components/studentRegister/E
|
||||
import ProfessionalInformation from '@/features/auth/components/studentRegister/ProfessionalInformation.vue'
|
||||
|
||||
const store = useStudentRegistrationStore()
|
||||
const auth = useAuthStore()
|
||||
const { isModal, openModal } = useModal()
|
||||
|
||||
const { data: registerData, isPending: isRegistrationDataPending } = useGetRegisterDataQuery()
|
||||
@@ -273,6 +286,32 @@ watch(
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
&__rejection {
|
||||
background: #fdecec;
|
||||
border: 1px solid #f5b8b8;
|
||||
border-radius: 0.75rem;
|
||||
padding: 1rem 1.25rem;
|
||||
margin-bottom: 1.25rem;
|
||||
}
|
||||
|
||||
&__rejection-title {
|
||||
font-family: var(--font-family-fa);
|
||||
font-weight: 600;
|
||||
font-size: 0.9375rem;
|
||||
color: #c62828;
|
||||
margin: 0 0 0.375rem;
|
||||
}
|
||||
|
||||
&__rejection-reason {
|
||||
font-family: var(--font-family-fa);
|
||||
font-weight: 400;
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.8;
|
||||
color: #7a2f2f;
|
||||
margin: 0;
|
||||
text-align: justify;
|
||||
}
|
||||
|
||||
&__main :deep(.text-field__label),
|
||||
&__main :deep(.textarea-field__label),
|
||||
&__main :deep(.select-field__label),
|
||||
|
||||
@@ -173,6 +173,12 @@ const menuItems = computed(() => [
|
||||
to: { name: 'admin-missionary-requests' },
|
||||
active: route.name === 'admin-missionary-requests',
|
||||
},
|
||||
{
|
||||
title: 'گواهینامهها',
|
||||
icon: 'certificate',
|
||||
to: { name: 'admin-certificates' },
|
||||
active: route.name === 'admin-certificates',
|
||||
},
|
||||
])
|
||||
</script>
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ export const buildStudentMenuItems = (route) => [
|
||||
icon: 'monitor',
|
||||
to: { name: 'student-dashboard' },
|
||||
active: route.name === 'student-dashboard',
|
||||
dedupeKey: 'dashboard',
|
||||
},
|
||||
{
|
||||
title: 'آموزش',
|
||||
@@ -25,6 +26,7 @@ export const buildStudentMenuItems = (route) => [
|
||||
'student-courses',
|
||||
'student-course-details',
|
||||
].includes(route.name),
|
||||
dedupeKey: 'education',
|
||||
},
|
||||
{
|
||||
title: 'خدمات',
|
||||
@@ -55,6 +57,7 @@ export const buildStudentMenuItems = (route) => [
|
||||
icon: 'envelope-open',
|
||||
to: { name: 'student-tickets' },
|
||||
active: route.name === 'student-tickets',
|
||||
dedupeKey: 'ticket',
|
||||
},
|
||||
]
|
||||
|
||||
@@ -64,6 +67,7 @@ export const buildMissionaryMenuItems = (route) => [
|
||||
icon: 'menu',
|
||||
to: { name: 'missionary-dashboard' },
|
||||
active: route.name === 'missionary-dashboard',
|
||||
dedupeKey: 'dashboard',
|
||||
},
|
||||
{
|
||||
title: 'سامانه اعزام',
|
||||
@@ -76,12 +80,14 @@ export const buildMissionaryMenuItems = (route) => [
|
||||
icon: 'graduation-cap',
|
||||
to: { name: 'missionary-education' },
|
||||
active: route.name?.startsWith('missionary-education'),
|
||||
dedupeKey: 'education',
|
||||
},
|
||||
{
|
||||
title: 'تیکت',
|
||||
icon: 'envelope-open',
|
||||
to: { name: 'missionary-tickets' },
|
||||
active: route.name === 'missionary-tickets',
|
||||
dedupeKey: 'ticket',
|
||||
},
|
||||
]
|
||||
|
||||
@@ -91,12 +97,14 @@ export const buildCounselorMenuItems = (route) => [
|
||||
icon: 'menu',
|
||||
to: { name: 'counselor-dashboard' },
|
||||
active: route.name === 'counselor-dashboard',
|
||||
dedupeKey: 'dashboard',
|
||||
},
|
||||
{
|
||||
title: 'مشاوره',
|
||||
icon: 'chat',
|
||||
to: { name: 'counselor-consultations' },
|
||||
active: route.name === 'counselor-consultations',
|
||||
dedupeKey: 'consultation',
|
||||
},
|
||||
]
|
||||
|
||||
@@ -110,15 +118,22 @@ const MENU_BUILDERS = {
|
||||
* Union of every panel section unlocked by `roles`, in role order (roles
|
||||
* come back from the API ordered by role id, so a user's base role's
|
||||
* sections lead and each additional role's sections are appended after).
|
||||
* Items sharing a dedupeKey across roles are merged — only the first
|
||||
* occurrence is kept (the primary role's version wins).
|
||||
*/
|
||||
export const buildMergedMenuItems = (roles, route) => {
|
||||
const seen = new Set()
|
||||
const seenRoles = new Set()
|
||||
const seenKeys = new Set()
|
||||
const items = []
|
||||
for (const roleName of roles ?? []) {
|
||||
const builder = MENU_BUILDERS[roleName]
|
||||
if (!builder || seen.has(roleName)) continue
|
||||
seen.add(roleName)
|
||||
items.push(...builder(route))
|
||||
if (!builder || seenRoles.has(roleName)) continue
|
||||
seenRoles.add(roleName)
|
||||
for (const item of builder(route)) {
|
||||
if (item.dedupeKey && seenKeys.has(item.dedupeKey)) continue
|
||||
if (item.dedupeKey) seenKeys.add(item.dedupeKey)
|
||||
items.push(item)
|
||||
}
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { http } from '@/services/api/http'
|
||||
import { buildUrl, endpoints } from '@/services/api/endpoints'
|
||||
|
||||
export const apiGetAdminCertificates = (params) =>
|
||||
http.get(endpoints.getAdminCertificates, { params })
|
||||
|
||||
export const apiAddAdminCertificate = (payload) => http.post(endpoints.addAdminCertificate, payload)
|
||||
|
||||
export const apiDeleteAdminCertificate = (id) =>
|
||||
http.delete(buildUrl(endpoints.deleteAdminCertificate, { id }))
|
||||
@@ -196,6 +196,11 @@ export const endpoints = {
|
||||
listAdminMissionaryRequests: '/admin/missionary-requests',
|
||||
showAdminMissionaryRequest: '/admin/missionary-requests/:id',
|
||||
changeAdminMissionaryRequestStatus: '/admin/missionary-requests/:id/status',
|
||||
|
||||
// ─── Admin: certificates ───────────────────────────────────────────────────
|
||||
getAdminCertificates: '/admin/certificates',
|
||||
addAdminCertificate: '/admin/certificates',
|
||||
deleteAdminCertificate: '/admin/certificates/:id',
|
||||
}
|
||||
|
||||
export const buildUrl = (template, params = {}) =>
|
||||
|
||||
@@ -61,12 +61,25 @@ const addCamelizeInterceptor = (instance) => {
|
||||
)
|
||||
}
|
||||
|
||||
const _addUnauthorizeInterceptor = (instance) => {
|
||||
const addUnauthorizeInterceptor = (instance) => {
|
||||
instance.interceptors.response.use(
|
||||
(res) => res,
|
||||
async (e) => {
|
||||
if (e?.response?.status === 401) {
|
||||
tokenService.clearAll()
|
||||
// Login/OTP-verify endpoints also answer 401 for a plain wrong
|
||||
// password or code — that's a credential failure the login form
|
||||
// should handle itself, not a session expiring. Only treat this as
|
||||
// "the session died" when we actually had a token going in.
|
||||
if (e?.response?.status === 401 && tokenService.hasToken()) {
|
||||
// Route through the auth store, not tokenService directly, so the
|
||||
// reactive user state and the WordPress-facing mb_auth_status cookie
|
||||
// both get cleared along with the token — an expired/invalid session
|
||||
// must not leave WordPress showing a stale "logged in" state.
|
||||
try {
|
||||
const { useAuthStore } = await import('@/store/auth')
|
||||
useAuthStore().clearUser()
|
||||
} catch {
|
||||
tokenService.clearAll()
|
||||
}
|
||||
toast('نشست شما تایید نشد، لطفا مجدد وارد شوید')
|
||||
try {
|
||||
const { default: router } = await import('@/router')
|
||||
@@ -89,7 +102,7 @@ const createInstance = (baseUrl, { headers = {}, ...configs } = {}) => {
|
||||
addResponseUnwrapInterceptor(instance)
|
||||
addCamelizeInterceptor(instance)
|
||||
addSnakizeInterceptor(instance)
|
||||
// _addUnauthorizeInterceptor(instance)
|
||||
addUnauthorizeInterceptor(instance)
|
||||
return instance
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { cleanFilters } from '@/utils/clean-filters'
|
||||
import { useMutation, useQuery } from '@tanstack/vue-query'
|
||||
import {
|
||||
apiAddAdminCertificate,
|
||||
apiDeleteAdminCertificate,
|
||||
apiGetAdminCertificates,
|
||||
} from '@/services/api/admin-certificates'
|
||||
|
||||
export const adminCertificatesKeys = {
|
||||
all: ['admin', 'certificates'],
|
||||
list: (filters, pagination) => ['admin', 'certificates', 'list', filters, pagination],
|
||||
}
|
||||
|
||||
export const useAdminCertificatesListQuery = (filtersRef, paginationRef, options = {}) =>
|
||||
useQuery({
|
||||
queryKey: ['admin', 'certificates', 'list', filtersRef, paginationRef],
|
||||
queryFn: () =>
|
||||
apiGetAdminCertificates({ ...cleanFilters(filtersRef.value), ...paginationRef.value }),
|
||||
select: (response) => ({
|
||||
data: response?.data?.items ?? response?.data ?? [],
|
||||
meta: response?.data?.meta ?? response?.meta,
|
||||
}),
|
||||
...options,
|
||||
})
|
||||
|
||||
export const useAddAdminCertificateMutation = () =>
|
||||
useMutation({ mutationFn: (payload) => apiAddAdminCertificate(payload) })
|
||||
|
||||
export const useDeleteAdminCertificateMutation = () =>
|
||||
useMutation({ mutationFn: (id) => apiDeleteAdminCertificate(id) })
|
||||
@@ -18,6 +18,10 @@ export const useStudentCertificatesQuery = (filtersRef, paginationRef, options =
|
||||
...cleanFilters(filtersRef.value),
|
||||
...paginationRef.value,
|
||||
}),
|
||||
select: (response) => ({
|
||||
data: response?.data?.items ?? response?.data ?? [],
|
||||
meta: response?.data?.meta ?? response?.meta,
|
||||
}),
|
||||
...options,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user