Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 55ed80e652 | |||
| bdb77786f2 | |||
| d227b1c8f4 | |||
| fdc52381db | |||
| c0fe9e9918 | |||
| 8743d37a7d | |||
| fc1c249033 | |||
| 9f86acacb0 |
@@ -1,8 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="course-item">
|
<div class="course-item">
|
||||||
<div class="course-item__main">
|
<div class="course-item__main">
|
||||||
<div v-if="course.image" class="course-item__image">
|
<div v-if="course.coverUrl" class="course-item__image">
|
||||||
<img :src="course.image" :alt="course.title" />
|
<img :src="course.coverUrl" :alt="course.title" />
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="course-item__image course-item__image--placeholder">
|
<div v-else class="course-item__image course-item__image--placeholder">
|
||||||
<SvgIcon name="book" :size="22" color="#bcbcbc" />
|
<SvgIcon name="book" :size="22" color="#bcbcbc" />
|
||||||
@@ -30,14 +30,13 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="course-item__actions">
|
||||||
<div v-if="!isActive" class="course-item__status">
|
<div v-if="!isActive" class="course-item__status">
|
||||||
<span class="course-item__status-badge">
|
<span class="course-item__status-badge">
|
||||||
<span class="course-item__status-dot" />
|
<span class="course-item__status-dot" />
|
||||||
غیرفعال
|
غیرفعال
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="course-item__actions">
|
|
||||||
<ToggleSwitch
|
<ToggleSwitch
|
||||||
:model-value="!!isActive"
|
:model-value="!!isActive"
|
||||||
@update:model-value="emit('change-status', { id: course.id, isActive: !isActive })"
|
@update:model-value="emit('change-status', { id: course.id, isActive: !isActive })"
|
||||||
@@ -192,10 +191,6 @@ const isActive = computed(() => props.course.isActive ?? false)
|
|||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
}
|
}
|
||||||
|
|
||||||
&__status {
|
|
||||||
flex: 0 0 auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
&__status-badge {
|
&__status-badge {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -217,6 +212,7 @@ const isActive = computed(() => props.course.isActive ?? false)
|
|||||||
|
|
||||||
&__actions {
|
&__actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 0.375rem;
|
gap: 0.375rem;
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ const form = ref({
|
|||||||
templateId: '',
|
templateId: '',
|
||||||
title: '',
|
title: '',
|
||||||
capacity: '',
|
capacity: '',
|
||||||
imageId: null,
|
coverMediaId: null,
|
||||||
isActive: false,
|
isActive: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -212,10 +212,10 @@ watch(existingCourse, (course) => {
|
|||||||
templateId: '',
|
templateId: '',
|
||||||
title: course.title || '',
|
title: course.title || '',
|
||||||
capacity: course.capacity ?? '',
|
capacity: course.capacity ?? '',
|
||||||
imageId: course.imageId || null,
|
coverMediaId: course.coverMediaId || null,
|
||||||
isActive: course.isActive ?? false,
|
isActive: course.isActive ?? false,
|
||||||
}
|
}
|
||||||
if (course.image) image.value = { url: course.image }
|
if (course.coverUrl) image.value = { url: course.coverUrl }
|
||||||
})
|
})
|
||||||
|
|
||||||
const uploadMutation = useUploadMediaMutation()
|
const uploadMutation = useUploadMediaMutation()
|
||||||
@@ -225,8 +225,8 @@ const onImageCropped = async (file) => {
|
|||||||
const formData = objectToFormData({ file, purpose: 'cover', context: 'course' })
|
const formData = objectToFormData({ file, purpose: 'cover', context: 'course' })
|
||||||
const response = await uploadMutation.mutateAsync(formData)
|
const response = await uploadMutation.mutateAsync(formData)
|
||||||
const payload = response?.data ?? response
|
const payload = response?.data ?? response
|
||||||
image.value = { url: payload?.url, uploadId: payload?.uploadId, ...payload }
|
image.value = { url: payload?.url, ...payload }
|
||||||
form.value.imageId = payload?.uploadId || payload?.id
|
form.value.coverMediaId = payload?.id
|
||||||
} catch {
|
} catch {
|
||||||
/* handled globally */
|
/* handled globally */
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<template v-else-if="course">
|
<template v-else-if="course">
|
||||||
<div class="course-details__hero">
|
<div class="course-details__hero">
|
||||||
<div class="course-details__image">
|
<div class="course-details__image">
|
||||||
<img v-if="course.image" :src="course.image" :alt="course.title" />
|
<img v-if="course.coverUrl" :src="course.coverUrl" :alt="course.title" />
|
||||||
<SvgIcon v-else name="book" :size="32" color="#bcbcbc" />
|
<SvgIcon v-else name="book" :size="32" color="#bcbcbc" />
|
||||||
</div>
|
</div>
|
||||||
<div class="course-details__grid">
|
<div class="course-details__grid">
|
||||||
|
|||||||
@@ -24,6 +24,6 @@ export const offeredCourseSchema = object().shape({
|
|||||||
.required()
|
.required()
|
||||||
.integer('ظرفیت باید عدد صحیح باشد')
|
.integer('ظرفیت باید عدد صحیح باشد')
|
||||||
.min(1, 'ظرفیت باید حداقل ۱ نفر باشد'),
|
.min(1, 'ظرفیت باید حداقل ۱ نفر باشد'),
|
||||||
imageId: string().nullable().notRequired(),
|
coverMediaId: number().typeError('شناسه تصویر دوره باید عدد باشد').nullable().notRequired(),
|
||||||
isActive: boolean().nullable().notRequired(),
|
isActive: boolean().nullable().notRequired(),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -241,6 +241,17 @@ export default [
|
|||||||
subtitle: 'لیست خدمات را مشاهده و مدیریت نمایید.',
|
subtitle: 'لیست خدمات را مشاهده و مدیریت نمایید.',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/service-types',
|
||||||
|
name: 'admin-service-types',
|
||||||
|
component: () => import('@/features/admin/services/pages/ServiceTypesPage.vue'),
|
||||||
|
meta: {
|
||||||
|
layout: 'admin',
|
||||||
|
role: 'admin',
|
||||||
|
title: 'مرکز خدمات',
|
||||||
|
subtitle: 'انواع خدمات قابل درخواست توسط کاربران را مدیریت کنید.',
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/consultations',
|
path: '/consultations',
|
||||||
name: 'admin-consultations',
|
name: 'admin-consultations',
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
<template>
|
||||||
|
<div class="service-type-item">
|
||||||
|
<div class="service-type-item__main">
|
||||||
|
<p class="service-type-item__title">{{ serviceType.title }}</p>
|
||||||
|
<p class="service-type-item__desc">{{ serviceType.description || '—' }}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="service-type-item__actions">
|
||||||
|
<CircleButton
|
||||||
|
tooltip="ویرایش"
|
||||||
|
bg-color="rgba(104, 104, 104, 0.05)"
|
||||||
|
size="2.5rem"
|
||||||
|
@click="emit('edit', serviceType)"
|
||||||
|
>
|
||||||
|
<template #icon>
|
||||||
|
<SvgIcon name="pencil" :size="18" color="var(--color-primary)" />
|
||||||
|
</template>
|
||||||
|
</CircleButton>
|
||||||
|
<CircleButton
|
||||||
|
tooltip="حذف"
|
||||||
|
bg-color="rgba(104, 104, 104, 0.05)"
|
||||||
|
size="2.5rem"
|
||||||
|
@click="emit('delete', serviceType)"
|
||||||
|
>
|
||||||
|
<template #icon>
|
||||||
|
<SvgIcon name="trash" :size="18" color="var(--color-error)" />
|
||||||
|
</template>
|
||||||
|
</CircleButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import SvgIcon from '@/components/icons/SvgIcon.vue'
|
||||||
|
import CircleButton from '@/components/CircleButton.vue'
|
||||||
|
|
||||||
|
defineProps({
|
||||||
|
serviceType: { type: Object, required: true },
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits(['edit', 'delete'])
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.service-type-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.75rem;
|
||||||
|
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;
|
||||||
|
|
||||||
|
&__main {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__title {
|
||||||
|
font-family: var(--font-family-fa);
|
||||||
|
font-size: 1rem;
|
||||||
|
color: #4b4b4b;
|
||||||
|
margin: 0 0 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__desc {
|
||||||
|
font-family: var(--font-family-fa);
|
||||||
|
font-size: 0.8125rem;
|
||||||
|
color: #848484;
|
||||||
|
margin: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
display: -webkit-box;
|
||||||
|
-webkit-line-clamp: 2;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.375rem;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
<template>
|
||||||
|
<BasicModal
|
||||||
|
:title="isEditMode ? 'ویرایش نوع خدمت' : 'افزودن نوع خدمت'"
|
||||||
|
title-en="Service Type"
|
||||||
|
width="95%"
|
||||||
|
max-width="40rem"
|
||||||
|
min-width="auto"
|
||||||
|
:show-close-button="true"
|
||||||
|
>
|
||||||
|
<template #default="{ close }">
|
||||||
|
<form class="service-type-form" @submit.prevent="onSubmit(close)">
|
||||||
|
<TextField
|
||||||
|
v-model="form.title"
|
||||||
|
name="title"
|
||||||
|
label="عنوان نوع خدمت"
|
||||||
|
placeholder="مثال: خدمات رفاهی"
|
||||||
|
:error="errors.title"
|
||||||
|
@blur="validateAt('title', form.title)"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TextareaField
|
||||||
|
v-model="form.description"
|
||||||
|
name="description"
|
||||||
|
label="توضیحات"
|
||||||
|
placeholder="توضیح کوتاهی درباره این نوع خدمت بنویسید"
|
||||||
|
:row="4"
|
||||||
|
:error="errors.description"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div class="service-type-form__divider" />
|
||||||
|
|
||||||
|
<div class="service-type-form__actions">
|
||||||
|
<BaseButton
|
||||||
|
variant="transparent"
|
||||||
|
text="منصرف شدم"
|
||||||
|
custom-class="service-type-form__btn-cancel"
|
||||||
|
@click="close"
|
||||||
|
>
|
||||||
|
<template #prependIcon>
|
||||||
|
<SvgIcon name="caret-right" :size="14" color="var(--color-sec-gray)" />
|
||||||
|
</template>
|
||||||
|
</BaseButton>
|
||||||
|
<BaseButton
|
||||||
|
type="submit"
|
||||||
|
:text="isEditMode ? 'ذخیره تغییرات' : 'افزودن'"
|
||||||
|
:loading="submitting"
|
||||||
|
custom-class="service-type-form__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 useYup from '@/composables/useYup'
|
||||||
|
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 BasicModal from '@/components/BasicModal.vue'
|
||||||
|
import TextField from '@/components/form/TextField.vue'
|
||||||
|
import TextareaField from '@/components/form/TextareaField.vue'
|
||||||
|
import { serviceTypeSchema } from '@/features/admin/services/schema/service-type'
|
||||||
|
import {
|
||||||
|
serviceTypesKeys,
|
||||||
|
useAddServiceTypeMutation,
|
||||||
|
useUpdateServiceTypeMutation,
|
||||||
|
} from '@/services/query/service-types'
|
||||||
|
|
||||||
|
defineOptions({ name: 'ServiceTypeFormModal' })
|
||||||
|
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
const { getModal } = useModal()
|
||||||
|
|
||||||
|
const modalData = computed(() => getModal('ServiceTypeFormModal')?.data ?? {})
|
||||||
|
const editingServiceType = computed(() => modalData.value.serviceType ?? null)
|
||||||
|
const isEditMode = computed(() => !!editingServiceType.value)
|
||||||
|
|
||||||
|
const form = ref({
|
||||||
|
title: editingServiceType.value?.title ?? '',
|
||||||
|
description: editingServiceType.value?.description ?? '',
|
||||||
|
})
|
||||||
|
|
||||||
|
const { validate, validateAt, errors } = useYup(serviceTypeSchema)
|
||||||
|
|
||||||
|
const addMutation = useAddServiceTypeMutation()
|
||||||
|
const updateMutation = useUpdateServiceTypeMutation()
|
||||||
|
const submitting = computed(() => addMutation.isPending.value || updateMutation.isPending.value)
|
||||||
|
|
||||||
|
const onSubmit = async (close) => {
|
||||||
|
const { isValid, payload } = await validate(form.value)
|
||||||
|
if (!isValid) return
|
||||||
|
|
||||||
|
if (isEditMode.value) {
|
||||||
|
await updateMutation.mutateAsync({ id: editingServiceType.value.id, payload })
|
||||||
|
} else {
|
||||||
|
await addMutation.mutateAsync(payload)
|
||||||
|
}
|
||||||
|
await queryClient.invalidateQueries({ queryKey: serviceTypesKeys.all })
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.service-type-form {
|
||||||
|
width: 100%;
|
||||||
|
text-align: start;
|
||||||
|
padding: 0.5rem 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.75rem;
|
||||||
|
|
||||||
|
&__divider {
|
||||||
|
border-block-end: 1px solid var(--color-thd-gray);
|
||||||
|
margin-block: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__btn-cancel {
|
||||||
|
min-width: 9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__btn-submit {
|
||||||
|
min-width: 10rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
export { default as SendMessageModal } from './components/modals/SendMessageModal.vue'
|
export { default as SendMessageModal } from './components/modals/SendMessageModal.vue'
|
||||||
export { default as ServiceDetailsModal } from './components/modals/ServiceDetailsModal.vue'
|
export { default as ServiceDetailsModal } from './components/modals/ServiceDetailsModal.vue'
|
||||||
|
export { default as ServiceTypeFormModal } from './components/modals/ServiceTypeFormModal.vue'
|
||||||
export { default as ServiceItem } from './components/ServiceItem.vue'
|
export { default as ServiceItem } from './components/ServiceItem.vue'
|
||||||
|
export { default as ServiceTypeItem } from './components/ServiceTypeItem.vue'
|
||||||
export { default as ServicesFilters } from './components/ServicesFilters.vue'
|
export { default as ServicesFilters } from './components/ServicesFilters.vue'
|
||||||
|
|||||||
@@ -0,0 +1,109 @@
|
|||||||
|
<template>
|
||||||
|
<div class="service-types-page">
|
||||||
|
<BoxedIconTitleBlock
|
||||||
|
class="service-types-page__heading"
|
||||||
|
title="انواع خدمات"
|
||||||
|
desc="در این قسمت میتوانید نوعهای خدمت قابل درخواست توسط کاربران را تعریف کنید."
|
||||||
|
>
|
||||||
|
<template #icon>
|
||||||
|
<SvgIcon name="users-three" :size="24" color="var(--color-primary)" />
|
||||||
|
</template>
|
||||||
|
</BoxedIconTitleBlock>
|
||||||
|
|
||||||
|
<div class="service-types-page__list-header">
|
||||||
|
<SimpleTitleIconBlock title="لیست انواع خدمات" class="service-types-page__list-title">
|
||||||
|
<template #header-icon>
|
||||||
|
<SvgIcon name="list-bullets" :size="16" color="#bcbcbc" />
|
||||||
|
</template>
|
||||||
|
</SimpleTitleIconBlock>
|
||||||
|
<BaseButton text="افزودن نوع خدمت" custom-class="service-types-page__add-btn" @click="onAdd">
|
||||||
|
<template #appendIcon>
|
||||||
|
<SvgIcon name="plus" :size="18" color="#fff" />
|
||||||
|
</template>
|
||||||
|
</BaseButton>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<SkeletonLoaderBlock v-if="isLoading" :rows="4" :cols-per-row="1" />
|
||||||
|
<div v-else-if="serviceTypes.length > 0">
|
||||||
|
<ServiceTypeItem
|
||||||
|
v-for="serviceType in serviceTypes"
|
||||||
|
:key="serviceType.id"
|
||||||
|
:service-type="serviceType"
|
||||||
|
@edit="onEdit"
|
||||||
|
@delete="onAskDelete"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<NoItems v-else title="موردی نیست" desc="هنوز هیچ نوع خدمتی تعریف نشده است." />
|
||||||
|
|
||||||
|
<ServiceTypeFormModal v-if="isModal('ServiceTypeFormModal')" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed } 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 BoxedIconTitleBlock from '@/components/blocks/BoxedIconTitleBlock.vue'
|
||||||
|
import SkeletonLoaderBlock from '@/components/blocks/SkeletonLoaderBlock.vue'
|
||||||
|
import SimpleTitleIconBlock from '@/components/blocks/SimpleTitleIconBlock.vue'
|
||||||
|
import ServiceTypeItem from '@/features/admin/services/components/ServiceTypeItem.vue'
|
||||||
|
import ServiceTypeFormModal from '@/features/admin/services/components/modals/ServiceTypeFormModal.vue'
|
||||||
|
import {
|
||||||
|
serviceTypesKeys,
|
||||||
|
useServiceTypesListQuery,
|
||||||
|
useDeleteServiceTypeMutation,
|
||||||
|
} from '@/services/query/service-types'
|
||||||
|
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
const { openModal, isModal } = useModal()
|
||||||
|
|
||||||
|
const { data, isLoading } = useServiceTypesListQuery()
|
||||||
|
const serviceTypes = computed(() => data.value ?? [])
|
||||||
|
|
||||||
|
const onAdd = () => openModal('ServiceTypeFormModal')
|
||||||
|
const onEdit = (serviceType) => openModal('ServiceTypeFormModal', { serviceType })
|
||||||
|
|
||||||
|
const invalidate = () => queryClient.invalidateQueries({ queryKey: serviceTypesKeys.all })
|
||||||
|
const deleteMutation = useDeleteServiceTypeMutation()
|
||||||
|
|
||||||
|
const onAskDelete = (serviceType) => {
|
||||||
|
openModal('ConfirmModal', {
|
||||||
|
title: `حذف نوع خدمت «${serviceType.title}»`,
|
||||||
|
message:
|
||||||
|
'بعد از حذف امکان بازگشت وجود ندارد، آیا مطمئن هستید که میخواهید این نوع خدمت را حذف کنید؟',
|
||||||
|
onConfirm: () => deleteMutation.mutate(serviceType.id, { onSuccess: invalidate }),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.service-types-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,6 @@
|
|||||||
|
import { object, string } from 'yup'
|
||||||
|
|
||||||
|
export const serviceTypeSchema = object().shape({
|
||||||
|
title: string().trim().required('عنوان نوع خدمت را وارد کنید').max(255, 'عنوان طولانی است'),
|
||||||
|
description: string().trim().nullable().notRequired().max(2000, 'توضیحات طولانی است'),
|
||||||
|
})
|
||||||
@@ -77,6 +77,19 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- row 3b — embed code (online sessions only) -->
|
||||||
|
<div class="session-form__row" v-if="form.type === 'online'">
|
||||||
|
<TextareaField
|
||||||
|
v-model="form.embedCode"
|
||||||
|
name="embedCode"
|
||||||
|
label="کد امبد (Embed Code)"
|
||||||
|
placeholder="در صورت وجود، کد iframe/embed جلسه (مثلاً از آپارات یا سرویس ویدئوکنفرانس) را اینجا وارد کنید تا بهجای لینک، بهصورت مستقیم در صفحه نمایش داده شود."
|
||||||
|
:row="3"
|
||||||
|
:error="errors.embedCode"
|
||||||
|
@blur="validateAt('embedCode', form.embedCode)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- row 4 — description -->
|
<!-- row 4 — description -->
|
||||||
<div class="session-form__row">
|
<div class="session-form__row">
|
||||||
<TextareaField
|
<TextareaField
|
||||||
@@ -101,6 +114,17 @@
|
|||||||
@remove="onContentRemove"
|
@remove="onContentRemove"
|
||||||
@error="onContentError"
|
@error="onContentError"
|
||||||
/>
|
/>
|
||||||
|
<div v-if="contentUploadMutation.isPending.value" class="session-form__upload-progress">
|
||||||
|
<div class="session-form__upload-progress-track">
|
||||||
|
<div
|
||||||
|
class="session-form__upload-progress-bar"
|
||||||
|
:style="{ width: contentUploadProgress + '%' }"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<span class="session-form__upload-progress-text">
|
||||||
|
{{ contentUploadProgress }}% بارگذاری شده
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -200,6 +224,7 @@ const form = ref({
|
|||||||
contentType: '',
|
contentType: '',
|
||||||
type: '',
|
type: '',
|
||||||
link: '',
|
link: '',
|
||||||
|
embedCode: '',
|
||||||
description: '',
|
description: '',
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -207,6 +232,7 @@ const image = ref(null)
|
|||||||
const contentFiles = ref([])
|
const contentFiles = ref([])
|
||||||
const coverMediaId = ref(null)
|
const coverMediaId = ref(null)
|
||||||
const contentMediaId = ref(null)
|
const contentMediaId = ref(null)
|
||||||
|
const contentUploadProgress = ref(0)
|
||||||
|
|
||||||
const contentAccept = computed(() => COURSE_CONTENT_TYPE_ACCEPT[form.value.contentType] || '*')
|
const contentAccept = computed(() => COURSE_CONTENT_TYPE_ACCEPT[form.value.contentType] || '*')
|
||||||
const contentMaxSize = computed(
|
const contentMaxSize = computed(
|
||||||
@@ -238,7 +264,10 @@ const onContentTypeChange = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onSessionTypeChange = () => {
|
const onSessionTypeChange = () => {
|
||||||
if (form.value.type !== 'online') form.value.link = ''
|
if (form.value.type !== 'online') {
|
||||||
|
form.value.link = ''
|
||||||
|
form.value.embedCode = ''
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data: existingSession } = useAdminSessionQuery(sessionId, {
|
const { data: existingSession } = useAdminSessionQuery(sessionId, {
|
||||||
@@ -267,6 +296,7 @@ watch(
|
|||||||
contentType,
|
contentType,
|
||||||
type: session.type ?? '',
|
type: session.type ?? '',
|
||||||
link: session.link ?? '',
|
link: session.link ?? '',
|
||||||
|
embedCode: session.embedCode ?? '',
|
||||||
description: session.description ?? '',
|
description: session.description ?? '',
|
||||||
}
|
}
|
||||||
coverMediaId.value = coverMedia?.id ?? null
|
coverMediaId.value = coverMedia?.id ?? null
|
||||||
@@ -298,13 +328,20 @@ const purposeForContentType = (contentType) => {
|
|||||||
const onContentSelect = async (files) => {
|
const onContentSelect = async (files) => {
|
||||||
const file = files?.[0]
|
const file = files?.[0]
|
||||||
if (!file) return
|
if (!file) return
|
||||||
|
contentUploadProgress.value = 0
|
||||||
try {
|
try {
|
||||||
const formData = objectToFormData({
|
const formData = objectToFormData({
|
||||||
file,
|
file,
|
||||||
purpose: purposeForContentType(form.value.contentType),
|
purpose: purposeForContentType(form.value.contentType),
|
||||||
context: 'session',
|
context: 'session',
|
||||||
})
|
})
|
||||||
const response = await contentUploadMutation.mutateAsync(formData)
|
const response = await contentUploadMutation.mutateAsync({
|
||||||
|
formData,
|
||||||
|
onUploadProgress: (event) => {
|
||||||
|
if (!event.total) return
|
||||||
|
contentUploadProgress.value = Math.round((event.loaded / event.total) * 100)
|
||||||
|
},
|
||||||
|
})
|
||||||
const payload = response?.data ?? response
|
const payload = response?.data ?? response
|
||||||
const id = payload?.id ?? payload?.uploadId
|
const id = payload?.id ?? payload?.uploadId
|
||||||
contentFiles.value = [{ id, name: file.name, size: file.size, url: payload?.url }]
|
contentFiles.value = [{ id, name: file.name, size: file.size, url: payload?.url }]
|
||||||
@@ -342,6 +379,7 @@ const buildPayload = (values) => {
|
|||||||
courseId: values.courseId,
|
courseId: values.courseId,
|
||||||
type: values.type,
|
type: values.type,
|
||||||
link: values.type === 'online' ? values.link : undefined,
|
link: values.type === 'online' ? values.link : undefined,
|
||||||
|
embedCode: values.type === 'online' ? values.embedCode : undefined,
|
||||||
description: values.description,
|
description: values.description,
|
||||||
mediaIds,
|
mediaIds,
|
||||||
}
|
}
|
||||||
@@ -477,6 +515,38 @@ const onCancel = () => router.push({ name: 'admin-sessions' })
|
|||||||
color: var(--color-prim-gray);
|
color: var(--color-prim-gray);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&__upload-progress {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.75rem;
|
||||||
|
margin-top: -0.25rem;
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__upload-progress-track {
|
||||||
|
flex: 1;
|
||||||
|
height: 0.5rem;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: var(--color-thd-gray);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__upload-progress-bar {
|
||||||
|
height: 100%;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: var(--color-primary);
|
||||||
|
transition: width 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__upload-progress-text {
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-family: var(--font-family-en);
|
||||||
|
font-size: 0.75rem;
|
||||||
|
color: var(--color-sec-gray);
|
||||||
|
min-width: 3.5rem;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
&__preview {
|
&__preview {
|
||||||
place-items: center center;
|
place-items: center center;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,5 +9,6 @@ export const sessionSchema = object().shape({
|
|||||||
then: (schema) => schema.required(),
|
then: (schema) => schema.required(),
|
||||||
otherwise: (schema) => schema.nullable().notRequired(),
|
otherwise: (schema) => schema.nullable().notRequired(),
|
||||||
}),
|
}),
|
||||||
|
embedCode: string().nullable().notRequired(),
|
||||||
description: string().nullable().notRequired(),
|
description: string().nullable().notRequired(),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="course-item">
|
<div class="course-item">
|
||||||
<div class="course-item__main">
|
<div class="course-item__main">
|
||||||
<div v-if="course.image" class="course-item__image">
|
<div v-if="course.coverUrl" class="course-item__image">
|
||||||
<img :src="course.image" :alt="course.title" />
|
<img :src="course.coverUrl" :alt="course.title" />
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="course-item__image course-item__image--placeholder">
|
<div v-else class="course-item__image course-item__image--placeholder">
|
||||||
<SvgIcon name="book" :size="22" color="#bcbcbc" />
|
<SvgIcon name="book" :size="22" color="#bcbcbc" />
|
||||||
|
|||||||
@@ -0,0 +1,392 @@
|
|||||||
|
<template>
|
||||||
|
<div class="user-evaluation">
|
||||||
|
<div class="user-evaluation__header">
|
||||||
|
<LineTitleBlock
|
||||||
|
class="user-evaluation__title"
|
||||||
|
title="سیستم ارزیابی کاربر"
|
||||||
|
title-en="User Evaluation System"
|
||||||
|
/>
|
||||||
|
<BaseButton
|
||||||
|
text="دانلود PDF"
|
||||||
|
:loading="pdfLoading"
|
||||||
|
:disabled="isLoading || !evaluation"
|
||||||
|
custom-class="user-evaluation__pdf-btn"
|
||||||
|
data-pdf-ignore
|
||||||
|
@click="onSaveAsPdf"
|
||||||
|
>
|
||||||
|
<template #appendIcon>
|
||||||
|
<SvgIcon name="arrow-left" :size="16" color="#fff" />
|
||||||
|
</template>
|
||||||
|
</BaseButton>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<SkeletonLoaderBlock v-if="isLoading" :rows="2" :cols-per-row="3" />
|
||||||
|
|
||||||
|
<div v-else-if="evaluation" ref="pdfContent" class="user-evaluation__content">
|
||||||
|
<header class="user-evaluation__pdf-header">
|
||||||
|
<h1>سیستم ارزیابی کاربر</h1>
|
||||||
|
<p>{{ fullName }}</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<section class="user-evaluation__section">
|
||||||
|
<p class="user-evaluation__section-title">مشخصات هویتی</p>
|
||||||
|
<div class="user-evaluation__identity-grid">
|
||||||
|
<LineInfoBlock title="نام و نام خانوادگی" :numeric-desc="fullName" />
|
||||||
|
<LineInfoBlock title="شماره تماس" :numeric-desc="user?.phone || '—'" />
|
||||||
|
<LineInfoBlock title="کد ملی" :numeric-desc="user?.nationalCode || '—'" />
|
||||||
|
<LineInfoBlock title="نقش" :desc="roleText" />
|
||||||
|
<LineInfoBlock title="تاریخ عضویت" :numeric-desc="joinDateLabel" />
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="user-evaluation__section">
|
||||||
|
<p class="user-evaluation__section-title">خلاصه عملکرد</p>
|
||||||
|
<div class="user-evaluation__stats">
|
||||||
|
<div v-for="(stat, i) in stats" :key="i" class="user-evaluation__stat-card">
|
||||||
|
<div class="user-evaluation__stat-icon">
|
||||||
|
<SvgIcon :name="stat.icon" :size="20" color="var(--color-primary)" />
|
||||||
|
</div>
|
||||||
|
<div class="user-evaluation__stat-text">
|
||||||
|
<p class="user-evaluation__stat-label">{{ stat.label }}</p>
|
||||||
|
<p class="user-evaluation__stat-value">
|
||||||
|
{{ stat.value }}
|
||||||
|
<span v-if="stat.unit" class="user-evaluation__stat-unit">{{ stat.unit }}</span>
|
||||||
|
</p>
|
||||||
|
<p v-if="stat.subtitle" class="user-evaluation__stat-subtitle">
|
||||||
|
{{ stat.subtitle }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<NoItems v-else title="موردی نیست" desc="اطلاعات ارزیابی این کاربر در دسترس نیست." />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
import { toast } from 'vue3-toastify'
|
||||||
|
import { ROLE_LABELS } from '@/enums'
|
||||||
|
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 LineTitleBlock from '@/components/LineTitleBlock.vue'
|
||||||
|
import LineInfoBlock from '@/components/blocks/LineInfoBlock.vue'
|
||||||
|
import { useAdminUserEvaluationQuery } from '@/services/query/admin-users'
|
||||||
|
import SkeletonLoaderBlock from '@/components/blocks/SkeletonLoaderBlock.vue'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
userId: { type: [Number, String], required: true },
|
||||||
|
user: { type: Object, default: null },
|
||||||
|
})
|
||||||
|
|
||||||
|
const userIdRef = computed(() => props.userId)
|
||||||
|
const { data: evaluation, isLoading } = useAdminUserEvaluationQuery(userIdRef, {
|
||||||
|
enabled: () => !!userIdRef.value,
|
||||||
|
})
|
||||||
|
|
||||||
|
const fullName = computed(() => props.user?.name || '—')
|
||||||
|
|
||||||
|
const roleText = computed(() => {
|
||||||
|
const names = (props.user?.roles || [])
|
||||||
|
.map((r) => (typeof r === 'string' ? r : r?.name))
|
||||||
|
.filter(Boolean)
|
||||||
|
if (names.length === 0) return 'بدون نقش'
|
||||||
|
return names.map((name) => ROLE_LABELS[name] || name).join('، ')
|
||||||
|
})
|
||||||
|
|
||||||
|
const joinDateLabel = computed(() => formatJalaaliDate(props.user?.createdAt) || '—')
|
||||||
|
|
||||||
|
const formatMembershipDuration = (days) => {
|
||||||
|
if (days == null) return '—'
|
||||||
|
if (days < 1) return 'کمتر از یک روز'
|
||||||
|
const years = Math.floor(days / 365)
|
||||||
|
const months = Math.floor((days % 365) / 30)
|
||||||
|
const remDays = Math.floor(days % 30)
|
||||||
|
const parts = []
|
||||||
|
if (years) parts.push(`${years} سال`)
|
||||||
|
if (months) parts.push(`${months} ماه`)
|
||||||
|
if (!years && !months) parts.push(`${remDays} روز`)
|
||||||
|
return parts.join(' و ')
|
||||||
|
}
|
||||||
|
|
||||||
|
const stats = computed(() => {
|
||||||
|
const e = evaluation.value || {}
|
||||||
|
const exams = e.exams || {}
|
||||||
|
const assignments = e.assignments || {}
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
icon: 'video',
|
||||||
|
label: 'جلسات مشاهدهشده',
|
||||||
|
value: e.sessions_viewed ?? 0,
|
||||||
|
unit: 'جلسه',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: 'check-square',
|
||||||
|
label: 'آزمونهای شرکتکرده',
|
||||||
|
value: exams.taken ?? 0,
|
||||||
|
unit: 'آزمون',
|
||||||
|
subtitle: `قبولشده: ${exams.passed ?? 0}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: 'certificate',
|
||||||
|
label: 'میانگین امتیاز',
|
||||||
|
value: exams.average_score_percent ?? '—',
|
||||||
|
unit: exams.average_score_percent == null ? '' : '%',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: 'file',
|
||||||
|
label: 'تکالیف انجامشده',
|
||||||
|
value: assignments.completed ?? 0,
|
||||||
|
unit: 'تکلیف',
|
||||||
|
subtitle: `تاییدشده: ${assignments.accepted ?? 0}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: 'book',
|
||||||
|
label: 'ترم فعلی',
|
||||||
|
value: e.current_term?.title || 'بدون ترم',
|
||||||
|
unit: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: 'clock',
|
||||||
|
label: 'مدت عضویت',
|
||||||
|
value: formatMembershipDuration(e.member_since?.days),
|
||||||
|
unit: '',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
const pdfContent = ref(null)
|
||||||
|
const pdfLoading = ref(false)
|
||||||
|
|
||||||
|
const onSaveAsPdf = async () => {
|
||||||
|
if (!pdfContent.value || isLoading.value || pdfLoading.value) return
|
||||||
|
|
||||||
|
pdfLoading.value = true
|
||||||
|
try {
|
||||||
|
await document.fonts?.ready
|
||||||
|
|
||||||
|
const pdfSource = pdfContent.value.cloneNode(true)
|
||||||
|
pdfSource.classList.add('user-evaluation__content--pdf')
|
||||||
|
pdfSource.querySelectorAll('[data-pdf-ignore]').forEach((element) => element.remove())
|
||||||
|
|
||||||
|
const html2pdfModule = await import('html2pdf.js')
|
||||||
|
const html2pdf = html2pdfModule.default || html2pdfModule
|
||||||
|
|
||||||
|
await html2pdf()
|
||||||
|
.set({
|
||||||
|
margin: [8, 8, 8, 8],
|
||||||
|
filename: `user-evaluation-${props.userId}.pdf`,
|
||||||
|
image: { type: 'jpeg', quality: 0.98 },
|
||||||
|
html2canvas: {
|
||||||
|
scale: 2,
|
||||||
|
useCORS: true,
|
||||||
|
backgroundColor: '#ffffff',
|
||||||
|
logging: false,
|
||||||
|
},
|
||||||
|
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' },
|
||||||
|
pagebreak: {
|
||||||
|
mode: ['css', 'legacy'],
|
||||||
|
avoid: ['.user-evaluation__section', '.user-evaluation__stat-card'],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.from(pdfSource)
|
||||||
|
.save()
|
||||||
|
} catch {
|
||||||
|
toast.error('ساخت فایل PDF با خطا مواجه شد.')
|
||||||
|
} finally {
|
||||||
|
pdfLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.user-evaluation {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
text-align: start;
|
||||||
|
|
||||||
|
&__header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.625rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__title {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 12rem;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__pdf-btn {
|
||||||
|
min-width: 9rem;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__pdf-header {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__section {
|
||||||
|
margin-bottom: 1.25rem;
|
||||||
|
|
||||||
|
&:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__section-title {
|
||||||
|
font-family: var(--font-family-fa);
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 0.8125rem;
|
||||||
|
color: #8a8a8a;
|
||||||
|
margin: 0 0 0.625rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__identity-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
gap: 0.25rem;
|
||||||
|
|
||||||
|
@media (min-width: 640px) {
|
||||||
|
grid-template-columns: repeat(2, 1fr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 1024px) {
|
||||||
|
grid-template-columns: repeat(3, 1fr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__stats {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
gap: 0.75rem;
|
||||||
|
|
||||||
|
@media (min-width: 640px) {
|
||||||
|
grid-template-columns: repeat(2, 1fr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 1024px) {
|
||||||
|
grid-template-columns: repeat(3, 1fr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__stat-card {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 0.625rem;
|
||||||
|
padding: 0.875rem;
|
||||||
|
background: rgba(255, 255, 255, 55%);
|
||||||
|
box-shadow: 0 4px 10px -6px rgba(0, 0, 0, 8%);
|
||||||
|
border-radius: 0.875rem;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__stat-icon {
|
||||||
|
flex-shrink: 0;
|
||||||
|
width: 2.5rem;
|
||||||
|
height: 2.5rem;
|
||||||
|
border-radius: 0.625rem;
|
||||||
|
background: rgba(243, 102, 117, 8%);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__stat-text {
|
||||||
|
min-width: 0;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__stat-label {
|
||||||
|
margin: 0 0 0.25rem;
|
||||||
|
font-family: var(--font-family-fa);
|
||||||
|
font-weight: 400;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
line-height: 1.3;
|
||||||
|
color: #9a9a9a;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__stat-value {
|
||||||
|
margin: 0;
|
||||||
|
font-family: var(--font-family-fa);
|
||||||
|
font-weight: 700;
|
||||||
|
font-size: 1.0625rem;
|
||||||
|
line-height: 1.4;
|
||||||
|
color: #4b4b4b;
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__stat-unit {
|
||||||
|
font-family: var(--font-family-fa);
|
||||||
|
font-weight: 400;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
color: #8a8a8a;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__stat-subtitle {
|
||||||
|
margin: 0.25rem 0 0;
|
||||||
|
font-family: var(--font-family-fa);
|
||||||
|
font-size: 0.6875rem;
|
||||||
|
color: #9a9a9a;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__content--pdf {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.25rem;
|
||||||
|
background: #fff;
|
||||||
|
box-sizing: border-box;
|
||||||
|
direction: rtl;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__content--pdf &__pdf-header {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
padding-bottom: 0.75rem;
|
||||||
|
border-bottom: 1px solid #eee;
|
||||||
|
text-align: right;
|
||||||
|
break-after: avoid;
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
margin: 0;
|
||||||
|
font-family: var(--font-family-fa);
|
||||||
|
font-size: 1.25rem;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #4b4b4b;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin: 0.25rem 0 0;
|
||||||
|
font-family: var(--font-family-fa);
|
||||||
|
font-size: 0.875rem;
|
||||||
|
color: #808080;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__content--pdf &__section {
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
break-inside: avoid;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__content--pdf &__identity-grid {
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
}
|
||||||
|
|
||||||
|
&__content--pdf &__stats {
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
}
|
||||||
|
|
||||||
|
&__content--pdf &__stat-card {
|
||||||
|
break-inside: avoid;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -76,6 +76,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<LineInfoBlock title="گرایش/رشته تحصیلی" :desc="user.fieldOfStudy || '—'" />
|
<LineInfoBlock title="گرایش/رشته تحصیلی" :desc="user.fieldOfStudy || '—'" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="user-details__section">
|
||||||
|
<UserEvaluationPanel :user-id="userId" :user="user" />
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<NoItems v-else title="یافت نشد" desc="اطلاعات این کاربر در دسترس نیست." />
|
<NoItems v-else title="یافت نشد" desc="اطلاعات این کاربر در دسترس نیست." />
|
||||||
@@ -106,6 +110,7 @@ import LineTitleBlock from '@/components/LineTitleBlock.vue'
|
|||||||
import { useAdminUserQuery } from '@/services/query/admin-users'
|
import { useAdminUserQuery } from '@/services/query/admin-users'
|
||||||
import LineInfoBlock from '@/components/blocks/LineInfoBlock.vue'
|
import LineInfoBlock from '@/components/blocks/LineInfoBlock.vue'
|
||||||
import SkeletonLoaderBlock from '@/components/blocks/SkeletonLoaderBlock.vue'
|
import SkeletonLoaderBlock from '@/components/blocks/SkeletonLoaderBlock.vue'
|
||||||
|
import UserEvaluationPanel from '@/features/admin/users/components/UserEvaluationPanel.vue'
|
||||||
import {
|
import {
|
||||||
EDUCATION_STATUS,
|
EDUCATION_STATUS,
|
||||||
GENDER,
|
GENDER,
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ const downloadItems = computed(() => [
|
|||||||
|
|
||||||
@media (min-width: 1024px) {
|
@media (min-width: 1024px) {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
order: 3;
|
order: 1;
|
||||||
min-width: 12rem;
|
min-width: 12rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,8 +146,8 @@ const downloadItems = computed(() => [
|
|||||||
&__course-info {
|
&__course-info {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: flex-start;
|
align-items: flex-end;
|
||||||
text-align: end;
|
text-align: right;
|
||||||
gap: 0.25rem;
|
gap: 0.25rem;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
}
|
}
|
||||||
@@ -186,6 +186,7 @@ const downloadItems = computed(() => [
|
|||||||
background: rgba(107, 107, 107, 4%);
|
background: rgba(107, 107, 107, 4%);
|
||||||
font-family: var(--font-family-fa);
|
font-family: var(--font-family-fa);
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
align-self: center;
|
||||||
|
|
||||||
@media (min-width: 1024px) {
|
@media (min-width: 1024px) {
|
||||||
order: 2;
|
order: 2;
|
||||||
@@ -222,15 +223,20 @@ const downloadItems = computed(() => [
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|
||||||
@media (min-width: 1024px) {
|
@media (min-width: 1024px) {
|
||||||
order: 1;
|
order: 3;
|
||||||
justify-content: flex-start;
|
justify-content: flex-end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&__download-btn {
|
&__download-btn {
|
||||||
min-width: 9rem;
|
width: 100%;
|
||||||
height: 2rem;
|
height: 2rem;
|
||||||
padding: 0 1.25rem;
|
padding: 0 1.25rem;
|
||||||
|
|
||||||
|
@media (min-width: 1024px) {
|
||||||
|
width: auto;
|
||||||
|
min-width: 9rem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import { computed, ref } from 'vue'
|
|||||||
import { toast } from 'vue3-toastify'
|
import { toast } from 'vue3-toastify'
|
||||||
import SvgIcon from '@/components/icons/SvgIcon.vue'
|
import SvgIcon from '@/components/icons/SvgIcon.vue'
|
||||||
import NoItems from '@/components/blocks/NoItems.vue'
|
import NoItems from '@/components/blocks/NoItems.vue'
|
||||||
|
import { formatJalaaliDate } from '@/utils/date-utils'
|
||||||
import { usePagination } from '@/composables/usePagination'
|
import { usePagination } from '@/composables/usePagination'
|
||||||
import PaginationBlock from '@/components/blocks/PaginationBlock.vue'
|
import PaginationBlock from '@/components/blocks/PaginationBlock.vue'
|
||||||
import BoxedIconTitleBlock from '@/components/blocks/BoxedIconTitleBlock.vue'
|
import BoxedIconTitleBlock from '@/components/blocks/BoxedIconTitleBlock.vue'
|
||||||
@@ -53,7 +54,17 @@ const { data, isLoading } = useStudentCertificatesQuery(filters, pagination, {
|
|||||||
keepPreviousData: true,
|
keepPreviousData: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
const certificates = computed(() => data.value?.data ?? [])
|
// Bridge the backend payload (title/teacherName/startedAt/endedAt) into the
|
||||||
|
// display shape CertificateItem expects, without touching its template.
|
||||||
|
const certificates = computed(() =>
|
||||||
|
(data.value?.data ?? []).map((c) => ({
|
||||||
|
...c,
|
||||||
|
courseTitle: c.title ?? '',
|
||||||
|
teacherName: c.teacherName ?? '',
|
||||||
|
startDate: formatJalaaliDate(c.startedAt) || '',
|
||||||
|
endDate: formatJalaaliDate(c.endedAt) || '',
|
||||||
|
}))
|
||||||
|
)
|
||||||
const meta = computed(() => ({
|
const meta = computed(() => ({
|
||||||
page: pagination.value.page,
|
page: pagination.value.page,
|
||||||
perPage: pagination.value.perPage,
|
perPage: pagination.value.perPage,
|
||||||
|
|||||||
@@ -67,8 +67,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from 'vue'
|
|
||||||
import * as yup from 'yup'
|
import * as yup from 'yup'
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
import { toast } from 'vue3-toastify'
|
import { toast } from 'vue3-toastify'
|
||||||
import useYup from '@/composables/useYup'
|
import useYup from '@/composables/useYup'
|
||||||
import BaseButton from '@/components/BaseButton.vue'
|
import BaseButton from '@/components/BaseButton.vue'
|
||||||
@@ -79,6 +79,7 @@ import FileUploader from '@/components/form/FileUploader.vue'
|
|||||||
import { objectToFormData } from '@/utils/object-to-formdata'
|
import { objectToFormData } from '@/utils/object-to-formdata'
|
||||||
import { useUploadMediaMutation } from '@/services/query/auth'
|
import { useUploadMediaMutation } from '@/services/query/auth'
|
||||||
import TextareaField from '@/components/form/TextareaField.vue'
|
import TextareaField from '@/components/form/TextareaField.vue'
|
||||||
|
import { useServiceTypesListQuery } from '@/services/query/service-types'
|
||||||
|
|
||||||
defineProps({
|
defineProps({
|
||||||
submitting: { type: Boolean, default: false },
|
submitting: { type: Boolean, default: false },
|
||||||
@@ -86,10 +87,10 @@ defineProps({
|
|||||||
|
|
||||||
const emit = defineEmits(['submit', 'file-error'])
|
const emit = defineEmits(['submit', 'file-error'])
|
||||||
|
|
||||||
const serviceTypeOptions = [
|
const { data: serviceTypes } = useServiceTypesListQuery()
|
||||||
{ value: 'خدمات رفاهی', label: 'خدمات رفاهی' },
|
const serviceTypeOptions = computed(() =>
|
||||||
{ value: 'خدمات آموزشی', label: 'خدمات آموزشی' },
|
(serviceTypes.value ?? []).map((st) => ({ value: st.title, label: st.title }))
|
||||||
]
|
)
|
||||||
|
|
||||||
const form = ref({
|
const form = ref({
|
||||||
category: '',
|
category: '',
|
||||||
|
|||||||
@@ -37,12 +37,23 @@
|
|||||||
<SvgIcon name="warning" :size="22" color="#b8b8b8" class="ssd__text-icon" />
|
<SvgIcon name="warning" :size="22" color="#b8b8b8" class="ssd__text-icon" />
|
||||||
<p class="ssd__text-body">{{ session.text }}</p>
|
<p class="ssd__text-body">{{ session.text }}</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-else-if="contentKind === 'embed'" class="ssd__embed">
|
||||||
|
<iframe
|
||||||
|
class="ssd__embed-frame"
|
||||||
|
:srcdoc="session.embedCode"
|
||||||
|
sandbox="allow-scripts allow-popups allow-forms allow-presentation"
|
||||||
|
allow="autoplay; fullscreen; picture-in-picture"
|
||||||
|
allowfullscreen
|
||||||
|
loading="lazy"
|
||||||
|
referrerpolicy="no-referrer"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div v-else-if="contentKind === 'link'" class="ssd__link">
|
<div v-else-if="contentKind === 'link'" class="ssd__link">
|
||||||
<div class="ssd__link__box">
|
<div class="ssd__link__box">
|
||||||
<span>https://link</span>
|
<span>{{ session?.link || 'لینکی ثبت نشده است' }}</span>
|
||||||
<SvgIcon name="link" :size="22" class="ssd__link-icon" />
|
<SvgIcon name="link" :size="22" class="ssd__link-icon" />
|
||||||
</div>
|
</div>
|
||||||
<BaseButton text="ورود به جلسه " custom-class="ssd__link-btn">
|
<BaseButton text="ورود به جلسه " custom-class="ssd__link-btn" @click="openSessionLink">
|
||||||
<template #appendIcon>
|
<template #appendIcon>
|
||||||
<SvgIcon name="arrow-left" :size="18" color="#fff" />
|
<SvgIcon name="arrow-left" :size="18" color="#fff" />
|
||||||
</template>
|
</template>
|
||||||
@@ -129,13 +140,17 @@ const homework = computed(() => (homeworksData.value?.data ?? [])[0] ?? null)
|
|||||||
const contentKind = computed(() => {
|
const contentKind = computed(() => {
|
||||||
const s = session.value
|
const s = session.value
|
||||||
if (!s) return ''
|
if (!s) return ''
|
||||||
if (s.type === 'online') return 'link'
|
if (s.type === 'online') return s.embedCode?.trim() ? 'embed' : 'link'
|
||||||
if (s.videoUrl) return 'link'
|
if (s.videoUrl) return 'video'
|
||||||
if (s.audioUrl) return 'audio'
|
if (s.audioUrl) return 'audio'
|
||||||
if (s.text) return 'text'
|
if (s.text) return 'text'
|
||||||
return ''
|
return ''
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const openSessionLink = () => {
|
||||||
|
if (session.value?.link) window.open(session.value.link, '_blank', 'noopener,noreferrer')
|
||||||
|
}
|
||||||
|
|
||||||
const homeworkAudio = ref(null)
|
const homeworkAudio = ref(null)
|
||||||
const homeworkImage = ref(null)
|
const homeworkImage = ref(null)
|
||||||
const errors = reactive({ audio: '', image: '' })
|
const errors = reactive({ audio: '', image: '' })
|
||||||
@@ -260,6 +275,18 @@ const onSubmit = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&__embed {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__embed-frame {
|
||||||
|
width: 100%;
|
||||||
|
aspect-ratio: 16 / 9;
|
||||||
|
border: 0;
|
||||||
|
border-radius: 1rem;
|
||||||
|
background: #000;
|
||||||
|
}
|
||||||
|
|
||||||
&__link {
|
&__link {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
@@ -147,9 +147,20 @@ const menuItems = computed(() => [
|
|||||||
{
|
{
|
||||||
title: 'مدیریت خدمات',
|
title: 'مدیریت خدمات',
|
||||||
icon: 'users-three',
|
icon: 'users-three',
|
||||||
|
active: ['admin-services', 'admin-service-types'].includes(route.name),
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
title: 'درخواستهای خدمت',
|
||||||
to: { name: 'admin-services' },
|
to: { name: 'admin-services' },
|
||||||
active: route.name === 'admin-services',
|
active: route.name === 'admin-services',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: 'انواع خدمات',
|
||||||
|
to: { name: 'admin-service-types' },
|
||||||
|
active: route.name === 'admin-service-types',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: 'مدیریت مشاوره',
|
title: 'مدیریت مشاوره',
|
||||||
icon: 'chat',
|
icon: 'chat',
|
||||||
|
|||||||
@@ -40,13 +40,16 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { useUIStore } from '@/store/ui'
|
import { useUIStore } from '@/store/ui'
|
||||||
|
import { useAuthStore } from '@/store/auth'
|
||||||
import { RouterView, useRoute } from 'vue-router'
|
import { RouterView, useRoute } from 'vue-router'
|
||||||
import Copyright from '@/components/Copyright.vue'
|
import Copyright from '@/components/Copyright.vue'
|
||||||
import HeaderBlock from '@/components/HeaderBlock.vue'
|
import HeaderBlock from '@/components/HeaderBlock.vue'
|
||||||
|
import { buildMergedMenuItems } from '@/layouts/roleMenuItems'
|
||||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||||
import CounselorSidebar from '@/layouts/sidebars/CounselorSidebar.vue'
|
import CounselorSidebar from '@/layouts/sidebars/CounselorSidebar.vue'
|
||||||
|
|
||||||
const ui = useUIStore()
|
const ui = useUIStore()
|
||||||
|
const auth = useAuthStore()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
|
||||||
const isMobile = ref(window.innerWidth < 1024)
|
const isMobile = ref(window.innerWidth < 1024)
|
||||||
@@ -59,20 +62,7 @@ onBeforeUnmount(() => window.removeEventListener('resize', onResize))
|
|||||||
const pageTitle = computed(() => route.meta?.title || 'مشاوره')
|
const pageTitle = computed(() => route.meta?.title || 'مشاوره')
|
||||||
const pageSubtitle = computed(() => route.meta?.subtitle || '')
|
const pageSubtitle = computed(() => route.meta?.subtitle || '')
|
||||||
|
|
||||||
const menuItems = computed(() => [
|
const menuItems = computed(() => buildMergedMenuItems(auth.roles, route))
|
||||||
{
|
|
||||||
title: 'پیشخوان',
|
|
||||||
icon: 'menu',
|
|
||||||
to: { name: 'counselor-dashboard' },
|
|
||||||
active: route.name === 'counselor-dashboard',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'مشاوره',
|
|
||||||
icon: 'chat',
|
|
||||||
to: { name: 'counselor-consultations' },
|
|
||||||
active: route.name === 'counselor-consultations',
|
|
||||||
},
|
|
||||||
])
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
@@ -38,13 +38,16 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { useUIStore } from '@/store/ui'
|
import { useUIStore } from '@/store/ui'
|
||||||
|
import { useAuthStore } from '@/store/auth'
|
||||||
import { RouterView, useRoute } from 'vue-router'
|
import { RouterView, useRoute } from 'vue-router'
|
||||||
import Copyright from '@/components/Copyright.vue'
|
import Copyright from '@/components/Copyright.vue'
|
||||||
import HeaderBlock from '@/components/HeaderBlock.vue'
|
import HeaderBlock from '@/components/HeaderBlock.vue'
|
||||||
|
import { buildMergedMenuItems } from '@/layouts/roleMenuItems'
|
||||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||||
import StudentSidebar from '@/layouts/sidebars/StudentSidebar.vue'
|
import StudentSidebar from '@/layouts/sidebars/StudentSidebar.vue'
|
||||||
|
|
||||||
const ui = useUIStore()
|
const ui = useUIStore()
|
||||||
|
const auth = useAuthStore()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
|
||||||
const isMobile = ref(window.innerWidth < 1024)
|
const isMobile = ref(window.innerWidth < 1024)
|
||||||
@@ -57,32 +60,7 @@ onBeforeUnmount(() => window.removeEventListener('resize', onResize))
|
|||||||
const pageTitle = computed(() => route.meta?.title || 'سیستم مدیریت اعزام')
|
const pageTitle = computed(() => route.meta?.title || 'سیستم مدیریت اعزام')
|
||||||
const pageSubtitle = computed(() => route.meta?.subtitle || '')
|
const pageSubtitle = computed(() => route.meta?.subtitle || '')
|
||||||
|
|
||||||
const menuItems = computed(() => [
|
const menuItems = computed(() => buildMergedMenuItems(auth.roles, route))
|
||||||
{
|
|
||||||
title: 'پیشخوان',
|
|
||||||
icon: 'menu',
|
|
||||||
to: { name: 'missionary-dashboard' },
|
|
||||||
active: route.name === 'missionary-dashboard',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'سامانه اعزام',
|
|
||||||
icon: 'user-sound',
|
|
||||||
to: { name: 'missionary-requests' },
|
|
||||||
active: route.name === 'missionary-requests',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'آموزش من',
|
|
||||||
icon: 'graduation-cap',
|
|
||||||
to: { name: 'missionary-education' },
|
|
||||||
active: route.name?.startsWith('missionary-education'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'تیکت',
|
|
||||||
icon: 'envelope-open',
|
|
||||||
to: { name: 'missionary-tickets' },
|
|
||||||
active: route.name === 'missionary-tickets',
|
|
||||||
},
|
|
||||||
])
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
@@ -38,13 +38,16 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { useUIStore } from '@/store/ui'
|
import { useUIStore } from '@/store/ui'
|
||||||
|
import { useAuthStore } from '@/store/auth'
|
||||||
import { RouterView, useRoute } from 'vue-router'
|
import { RouterView, useRoute } from 'vue-router'
|
||||||
import Copyright from '@/components/Copyright.vue'
|
import Copyright from '@/components/Copyright.vue'
|
||||||
import HeaderBlock from '@/components/HeaderBlock.vue'
|
import HeaderBlock from '@/components/HeaderBlock.vue'
|
||||||
|
import { buildMergedMenuItems } from '@/layouts/roleMenuItems'
|
||||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||||
import StudentSidebar from '@/layouts/sidebars/StudentSidebar.vue'
|
import StudentSidebar from '@/layouts/sidebars/StudentSidebar.vue'
|
||||||
|
|
||||||
const ui = useUIStore()
|
const ui = useUIStore()
|
||||||
|
const auth = useAuthStore()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
|
||||||
const isMobile = ref(window.innerWidth < 1024)
|
const isMobile = ref(window.innerWidth < 1024)
|
||||||
@@ -57,52 +60,7 @@ onBeforeUnmount(() => window.removeEventListener('resize', onResize))
|
|||||||
const pageTitle = computed(() => route.meta?.title || 'پیشخوان')
|
const pageTitle = computed(() => route.meta?.title || 'پیشخوان')
|
||||||
const pageSubtitle = computed(() => route.meta?.subtitle || '')
|
const pageSubtitle = computed(() => route.meta?.subtitle || '')
|
||||||
|
|
||||||
const menuItems = computed(() => [
|
const menuItems = computed(() => buildMergedMenuItems(auth.roles, route))
|
||||||
{
|
|
||||||
title: 'داشبورد',
|
|
||||||
icon: 'monitor',
|
|
||||||
to: { name: 'student-dashboard' },
|
|
||||||
active: route.name === 'student-dashboard',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'آموزش',
|
|
||||||
icon: 'graduation-cap',
|
|
||||||
to: { name: 'student-terms' },
|
|
||||||
active: [
|
|
||||||
'student-terms',
|
|
||||||
'student-term-details',
|
|
||||||
'student-lesson-details',
|
|
||||||
'student-session-details',
|
|
||||||
'student-exam',
|
|
||||||
'student-courses',
|
|
||||||
'student-course-details',
|
|
||||||
].includes(route.name),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'خدمات',
|
|
||||||
icon: 'folder-simple-star',
|
|
||||||
to: { name: 'student-services' },
|
|
||||||
active: route.name === 'student-services',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'گواهینامه',
|
|
||||||
icon: 'certificate',
|
|
||||||
to: { name: 'student-certificates' },
|
|
||||||
active: route.name === 'student-certificates',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'ویرایش پروفایل',
|
|
||||||
icon: 'user-circle-check',
|
|
||||||
to: { name: 'student-profile' },
|
|
||||||
active: route.name === 'student-profile',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'تیکت',
|
|
||||||
icon: 'envelope-open',
|
|
||||||
to: { name: 'student-tickets' },
|
|
||||||
active: route.name === 'student-tickets',
|
|
||||||
},
|
|
||||||
])
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
@@ -0,0 +1,124 @@
|
|||||||
|
// Per-role sidebar sections, kept as plain builder functions so any layout
|
||||||
|
// can request the union of sections for every role a user holds — additive
|
||||||
|
// multi-role access without each layout hardcoding its own single-role list.
|
||||||
|
// Only roles with a registered builder participate in the merge; a role
|
||||||
|
// without one (e.g. admin) contributes nothing and keeps its own standalone
|
||||||
|
// menu untouched.
|
||||||
|
|
||||||
|
export const buildStudentMenuItems = (route) => [
|
||||||
|
{
|
||||||
|
title: 'داشبورد',
|
||||||
|
icon: 'monitor',
|
||||||
|
to: { name: 'student-dashboard' },
|
||||||
|
active: route.name === 'student-dashboard',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'آموزش',
|
||||||
|
icon: 'graduation-cap',
|
||||||
|
to: { name: 'student-terms' },
|
||||||
|
active: [
|
||||||
|
'student-terms',
|
||||||
|
'student-term-details',
|
||||||
|
'student-lesson-details',
|
||||||
|
'student-session-details',
|
||||||
|
'student-exam',
|
||||||
|
'student-courses',
|
||||||
|
'student-course-details',
|
||||||
|
].includes(route.name),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'خدمات',
|
||||||
|
icon: 'folder-simple-star',
|
||||||
|
to: { name: 'student-services' },
|
||||||
|
active: route.name === 'student-services',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'مشاوره',
|
||||||
|
icon: 'chat-teardrop-text',
|
||||||
|
to: { name: 'student-consultants' },
|
||||||
|
active: route.name === 'student-consultants',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'گواهینامه',
|
||||||
|
icon: 'certificate',
|
||||||
|
to: { name: 'student-certificates' },
|
||||||
|
active: route.name === 'student-certificates',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'ویرایش پروفایل',
|
||||||
|
icon: 'user-circle-check',
|
||||||
|
to: { name: 'student-profile' },
|
||||||
|
active: route.name === 'student-profile',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'تیکت',
|
||||||
|
icon: 'envelope-open',
|
||||||
|
to: { name: 'student-tickets' },
|
||||||
|
active: route.name === 'student-tickets',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
export const buildMissionaryMenuItems = (route) => [
|
||||||
|
{
|
||||||
|
title: 'پیشخوان',
|
||||||
|
icon: 'menu',
|
||||||
|
to: { name: 'missionary-dashboard' },
|
||||||
|
active: route.name === 'missionary-dashboard',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'سامانه اعزام',
|
||||||
|
icon: 'user-sound',
|
||||||
|
to: { name: 'missionary-requests' },
|
||||||
|
active: route.name === 'missionary-requests',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'آموزش من',
|
||||||
|
icon: 'graduation-cap',
|
||||||
|
to: { name: 'missionary-education' },
|
||||||
|
active: route.name?.startsWith('missionary-education'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'تیکت',
|
||||||
|
icon: 'envelope-open',
|
||||||
|
to: { name: 'missionary-tickets' },
|
||||||
|
active: route.name === 'missionary-tickets',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
export const buildCounselorMenuItems = (route) => [
|
||||||
|
{
|
||||||
|
title: 'پیشخوان',
|
||||||
|
icon: 'menu',
|
||||||
|
to: { name: 'counselor-dashboard' },
|
||||||
|
active: route.name === 'counselor-dashboard',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'مشاوره',
|
||||||
|
icon: 'chat',
|
||||||
|
to: { name: 'counselor-consultations' },
|
||||||
|
active: route.name === 'counselor-consultations',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
const MENU_BUILDERS = {
|
||||||
|
student: buildStudentMenuItems,
|
||||||
|
missionary: buildMissionaryMenuItems,
|
||||||
|
counselor: buildCounselorMenuItems,
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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).
|
||||||
|
*/
|
||||||
|
export const buildMergedMenuItems = (roles, route) => {
|
||||||
|
const seen = 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))
|
||||||
|
}
|
||||||
|
return items
|
||||||
|
}
|
||||||
@@ -33,7 +33,7 @@ export const statusGuard = (to) => {
|
|||||||
if (!tokenService.hasToken()) return
|
if (!tokenService.hasToken()) return
|
||||||
const auth = useAuthStore()
|
const auth = useAuthStore()
|
||||||
if (!auth.user) return
|
if (!auth.user) return
|
||||||
if (auth.role && auth.role !== 'student') return
|
if (!auth.roles.includes('student')) return
|
||||||
if (auth.user.status === 'approved') return
|
if (auth.user.status === 'approved') return
|
||||||
return { name: 'student-register' }
|
return { name: 'student-register' }
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,7 @@ export const statusGuard = (to) => {
|
|||||||
export const roleGuard = (to) => {
|
export const roleGuard = (to) => {
|
||||||
if (!to.meta?.role) return
|
if (!to.meta?.role) return
|
||||||
const auth = useAuthStore()
|
const auth = useAuthStore()
|
||||||
if (auth.role !== to.meta.role) {
|
if (!auth.roles.includes(to.meta.role)) {
|
||||||
return { name: 'home' }
|
return { name: 'home' }
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ export const apiShowAdminUser = (id) => http.get(buildUrl(endpoints.showUserDeta
|
|||||||
export const apiGetAdminUserRegisterData = (id) =>
|
export const apiGetAdminUserRegisterData = (id) =>
|
||||||
http.get(buildUrl(endpoints.getUserRegisterData, { id }))
|
http.get(buildUrl(endpoints.getUserRegisterData, { id }))
|
||||||
|
|
||||||
|
export const apiGetAdminUserEvaluation = (id) =>
|
||||||
|
http.get(buildUrl(endpoints.getUserEvaluation, { id }))
|
||||||
|
|
||||||
export const apiAddAdminUser = (payload) => http.post(endpoints.addNewUser, payload)
|
export const apiAddAdminUser = (payload) => http.post(endpoints.addNewUser, payload)
|
||||||
|
|
||||||
export const apiUpdateAdminUser = (id, payload) =>
|
export const apiUpdateAdminUser = (id, payload) =>
|
||||||
|
|||||||
@@ -46,5 +46,10 @@ export const apiGetRegistrationQuestionVideo = () =>
|
|||||||
// Media uploads (especially course videos) can legitimately take several
|
// Media uploads (especially course videos) can legitimately take several
|
||||||
// minutes on slower connections. Keep the normal API timeout short, but give
|
// minutes on slower connections. Keep the normal API timeout short, but give
|
||||||
// this endpoint enough time to complete the backend's 300 MB upload contract.
|
// this endpoint enough time to complete the backend's 300 MB upload contract.
|
||||||
export const apiUploadMedia = (formData) =>
|
// `onUploadProgress` is optional and forwarded straight to axios so callers
|
||||||
http.post(endpoints.uploadMedia, formData, { timeout: 10 * 60 * 1000 })
|
// can render an upload progress bar (e.g. XHR progress events).
|
||||||
|
export const apiUploadMedia = (formData, onUploadProgress) =>
|
||||||
|
http.post(endpoints.uploadMedia, formData, {
|
||||||
|
timeout: 10 * 60 * 1000,
|
||||||
|
...(onUploadProgress ? { onUploadProgress } : {}),
|
||||||
|
})
|
||||||
|
|||||||
@@ -55,6 +55,14 @@ export const endpoints = {
|
|||||||
getStudentCertificates: '/student/certificates',
|
getStudentCertificates: '/student/certificates',
|
||||||
downloadStudentCertificate: '/student/certificates/:id/download',
|
downloadStudentCertificate: '/student/certificates/:id/download',
|
||||||
|
|
||||||
|
// ─── Backend-aligned: Service types (settings) ────────────────────────────
|
||||||
|
// Read is open to any authenticated role (populates the student "request
|
||||||
|
// service" category select); create/update/delete are admin-only.
|
||||||
|
getServiceTypesList: '/service-types',
|
||||||
|
addServiceType: '/service-types',
|
||||||
|
updateServiceType: '/service-types/:id',
|
||||||
|
deleteServiceType: '/service-types/:id',
|
||||||
|
|
||||||
// ─── Per-role aggregated dashboards ────────────────────────────────────────
|
// ─── Per-role aggregated dashboards ────────────────────────────────────────
|
||||||
// Each requires the matching role's token; backend scopes the payload.
|
// Each requires the matching role's token; backend scopes the payload.
|
||||||
getAdminDashboard: '/admin/dashboard',
|
getAdminDashboard: '/admin/dashboard',
|
||||||
@@ -74,6 +82,7 @@ export const endpoints = {
|
|||||||
changeUserStatus: '/admin/users/:id/status',
|
changeUserStatus: '/admin/users/:id/status',
|
||||||
deleteUser: '/admin/users/:id',
|
deleteUser: '/admin/users/:id',
|
||||||
getUserRegisterData: '/admin/users/:id/register-data',
|
getUserRegisterData: '/admin/users/:id/register-data',
|
||||||
|
getUserEvaluation: '/admin/users/:id/evaluation',
|
||||||
|
|
||||||
// ─── Backend-aligned: Terms ────────────────────────────────────────────────
|
// ─── Backend-aligned: Terms ────────────────────────────────────────────────
|
||||||
getTermsList: '/terms',
|
getTermsList: '/terms',
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { http } from '@/services/api/http'
|
||||||
|
import { buildUrl, endpoints } from '@/services/api/endpoints'
|
||||||
|
|
||||||
|
export const apiGetServiceTypes = () => http.get(endpoints.getServiceTypesList)
|
||||||
|
|
||||||
|
export const apiAddServiceType = (payload) => http.post(endpoints.addServiceType, payload)
|
||||||
|
|
||||||
|
export const apiUpdateServiceType = (id, payload) =>
|
||||||
|
http.patch(buildUrl(endpoints.updateServiceType, { id }), payload)
|
||||||
|
|
||||||
|
export const apiDeleteServiceType = (id) =>
|
||||||
|
http.delete(buildUrl(endpoints.deleteServiceType, { id }))
|
||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
apiAddAdminUser,
|
apiAddAdminUser,
|
||||||
apiChangeAdminUserStatus,
|
apiChangeAdminUserStatus,
|
||||||
apiDeleteAdminUser,
|
apiDeleteAdminUser,
|
||||||
|
apiGetAdminUserEvaluation,
|
||||||
apiGetAdminUserRegisterData,
|
apiGetAdminUserRegisterData,
|
||||||
apiGetAdminUsers,
|
apiGetAdminUsers,
|
||||||
apiShowAdminUser,
|
apiShowAdminUser,
|
||||||
@@ -16,6 +17,7 @@ export const adminUsersKeys = {
|
|||||||
list: (filters, pagination) => ['admin', 'users', 'list', filters, pagination],
|
list: (filters, pagination) => ['admin', 'users', 'list', filters, pagination],
|
||||||
detail: (id) => ['admin', 'users', 'detail', id],
|
detail: (id) => ['admin', 'users', 'detail', id],
|
||||||
registerData: (id) => ['admin', 'users', 'register-data', id],
|
registerData: (id) => ['admin', 'users', 'register-data', id],
|
||||||
|
evaluation: (id) => ['admin', 'users', 'evaluation', id],
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useAdminUsersListQuery = (filtersRef, paginationRef, options = {}) =>
|
export const useAdminUsersListQuery = (filtersRef, paginationRef, options = {}) =>
|
||||||
@@ -59,6 +61,14 @@ export const useAdminUserRegisterDataQuery = (idRef, options = {}) =>
|
|||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const useAdminUserEvaluationQuery = (idRef, options = {}) =>
|
||||||
|
useQuery({
|
||||||
|
queryKey: ['admin', 'users', 'evaluation', idRef],
|
||||||
|
queryFn: () => apiGetAdminUserEvaluation(idRef.value),
|
||||||
|
select: (response) => response?.data ?? response,
|
||||||
|
...options,
|
||||||
|
})
|
||||||
|
|
||||||
export const useAddAdminUserMutation = () =>
|
export const useAddAdminUserMutation = () =>
|
||||||
useMutation({ mutationFn: (payload) => apiAddAdminUser(payload) })
|
useMutation({ mutationFn: (payload) => apiAddAdminUser(payload) })
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,16 @@ export const useGetRegistrationVideoQuery = (options = {}) =>
|
|||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
|
|
||||||
export const useUploadMediaMutation = () => useMutation({ mutationFn: apiUploadMedia })
|
// `mutateAsync` accepts either a raw FormData (existing call sites, no
|
||||||
|
// progress tracking) or `{ formData, onUploadProgress }` for callers that
|
||||||
|
// want to render upload progress (e.g. a video upload progress bar).
|
||||||
|
const uploadMediaMutationFn = (variables) => {
|
||||||
|
if (variables instanceof FormData) return apiUploadMedia(variables)
|
||||||
|
const { formData, onUploadProgress } = variables
|
||||||
|
return apiUploadMedia(formData, onUploadProgress)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useUploadMediaMutation = () => useMutation({ mutationFn: uploadMediaMutationFn })
|
||||||
|
|
||||||
// Register-data is a flat `{ field: value }` object; legacy responses were a
|
// Register-data is a flat `{ field: value }` object; legacy responses were a
|
||||||
// `[{ key, value }]` list. Normalize both into the object shape.
|
// `[{ key, value }]` list. Normalize both into the object shape.
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import { useMutation, useQuery } from '@tanstack/vue-query'
|
||||||
|
import {
|
||||||
|
apiAddServiceType,
|
||||||
|
apiDeleteServiceType,
|
||||||
|
apiGetServiceTypes,
|
||||||
|
apiUpdateServiceType,
|
||||||
|
} from '@/services/api/service-types'
|
||||||
|
|
||||||
|
export const serviceTypesKeys = {
|
||||||
|
all: ['service-types'],
|
||||||
|
list: () => ['service-types', 'list'],
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useServiceTypesListQuery = (options = {}) =>
|
||||||
|
useQuery({
|
||||||
|
queryKey: serviceTypesKeys.list(),
|
||||||
|
queryFn: () => apiGetServiceTypes(),
|
||||||
|
select: (response) => response?.data ?? response ?? [],
|
||||||
|
...options,
|
||||||
|
})
|
||||||
|
|
||||||
|
export const useAddServiceTypeMutation = () =>
|
||||||
|
useMutation({ mutationFn: (payload) => apiAddServiceType(payload) })
|
||||||
|
|
||||||
|
export const useUpdateServiceTypeMutation = () =>
|
||||||
|
useMutation({ mutationFn: ({ id, payload }) => apiUpdateServiceType(id, payload) })
|
||||||
|
|
||||||
|
export const useDeleteServiceTypeMutation = () =>
|
||||||
|
useMutation({ mutationFn: (id) => apiDeleteServiceType(id) })
|
||||||
@@ -8,15 +8,22 @@ export const studentCoursesKeys = {
|
|||||||
detail: (id) => ['student', 'courses', 'detail', id],
|
detail: (id) => ['student', 'courses', 'detail', id],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const withCoverImage = (course) => ({
|
||||||
|
...course,
|
||||||
|
image: course.image ?? course.coverUrl ?? null,
|
||||||
|
})
|
||||||
|
|
||||||
const adaptCourseResponse = (response) => {
|
const adaptCourseResponse = (response) => {
|
||||||
const course = response?.data ?? response
|
const course = response?.data ?? response
|
||||||
if (!course) return course
|
if (!course) return course
|
||||||
return {
|
return withCoverImage(course)
|
||||||
...course,
|
|
||||||
image: course.image ?? course.coverUrl ?? null,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const adaptCourseListResponse = (response) => ({
|
||||||
|
data: (response?.data?.items ?? response?.data ?? []).map((course) => withCoverImage(course)),
|
||||||
|
meta: response?.data?.meta ?? response?.meta,
|
||||||
|
})
|
||||||
|
|
||||||
export const useStudentCoursesListQuery = (filtersRef, paginationRef, options = {}) =>
|
export const useStudentCoursesListQuery = (filtersRef, paginationRef, options = {}) =>
|
||||||
useQuery({
|
useQuery({
|
||||||
queryKey: ['student', 'courses', 'list', filtersRef, paginationRef],
|
queryKey: ['student', 'courses', 'list', filtersRef, paginationRef],
|
||||||
@@ -25,6 +32,7 @@ export const useStudentCoursesListQuery = (filtersRef, paginationRef, options =
|
|||||||
...cleanFilters(filtersRef.value),
|
...cleanFilters(filtersRef.value),
|
||||||
...paginationRef.value,
|
...paginationRef.value,
|
||||||
}),
|
}),
|
||||||
|
select: adaptCourseListResponse,
|
||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import { ROLE_HOME_ROUTES } from '@/enums'
|
||||||
|
|
||||||
|
// Read by the WordPress site (madresebanoo.ir) to show/hide its "account"
|
||||||
|
// button and link it to the right dashboard, without ever seeing a real
|
||||||
|
// auth token. Must stay in sync with whatever the WP/Elementor side expects
|
||||||
|
// — see the implementation report for the exact contract.
|
||||||
|
const COOKIE_NAME = 'mb_auth_status'
|
||||||
|
const ROOT_DOMAIN = 'madresebanoo.ir'
|
||||||
|
|
||||||
|
const isOnRootDomain = () => {
|
||||||
|
const host = window.location.hostname
|
||||||
|
return host === ROOT_DOMAIN || host.endsWith(`.${ROOT_DOMAIN}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const cookieAttributes = () => {
|
||||||
|
const attrs = ['Path=/', 'SameSite=Lax']
|
||||||
|
// A Domain=.madresebanoo.ir cookie is only accepted by the browser when the
|
||||||
|
// current page is actually on that domain (prod). On local dev
|
||||||
|
// (127.0.0.1/localhost) we fall back to a host-only cookie so the sync
|
||||||
|
// logic is still exercised, instead of silently failing to set anything.
|
||||||
|
if (isOnRootDomain()) attrs.push(`Domain=.${ROOT_DOMAIN}`)
|
||||||
|
// Secure cookies are dropped by the browser on plain http, which local dev
|
||||||
|
// serves over. Only require it where it can actually work (prod, https).
|
||||||
|
if (window.location.protocol === 'https:') attrs.push('Secure')
|
||||||
|
return attrs
|
||||||
|
}
|
||||||
|
|
||||||
|
const writeCookie = (value, { expire = false } = {}) => {
|
||||||
|
const attrs = cookieAttributes()
|
||||||
|
attrs.push(expire ? 'Max-Age=0' : '') // no Max-Age on set = session cookie
|
||||||
|
// This cookie must be readable by a separate WordPress site with plain JS
|
||||||
|
// (no httpOnly), and needs Domain/SameSite attributes the CookieStore API
|
||||||
|
// doesn't uniformly support yet — document.cookie is the correct tool here.
|
||||||
|
// eslint-disable-next-line unicorn/no-document-cookie
|
||||||
|
document.cookie = [`${COOKIE_NAME}=${value}`, ...attrs].filter(Boolean).join('; ')
|
||||||
|
}
|
||||||
|
|
||||||
|
const dashboardPathFor = async (role) => {
|
||||||
|
try {
|
||||||
|
const { default: router } = await import('@/router')
|
||||||
|
const routeName = ROLE_HOME_ROUTES[role] || 'student-dashboard'
|
||||||
|
return router.resolve({ name: routeName }).path
|
||||||
|
} catch {
|
||||||
|
return '/dashboard'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets mb_auth_status to a non-sensitive JSON blob describing display state
|
||||||
|
* only: `{ loggedIn: true, dashboardPath }`. Never put the access token,
|
||||||
|
* password, or any credential in this cookie.
|
||||||
|
*/
|
||||||
|
export const syncAuthStatusCookie = async (role) => {
|
||||||
|
const dashboardPath = await dashboardPathFor(role)
|
||||||
|
const value = encodeURIComponent(JSON.stringify({ loggedIn: true, dashboardPath }))
|
||||||
|
writeCookie(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const clearAuthStatusCookie = () => {
|
||||||
|
writeCookie('', { expire: true })
|
||||||
|
}
|
||||||
+22
-4
@@ -2,31 +2,49 @@ import { computed, ref } from 'vue'
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
|
|
||||||
import { tokenService } from '@/services/api/token-service'
|
import { tokenService } from '@/services/api/token-service'
|
||||||
|
import { syncAuthStatusCookie, clearAuthStatusCookie } from '@/services/wp-sync/auth-status-cookie'
|
||||||
|
|
||||||
export const useAuthStore = defineStore('auth', () => {
|
export const useAuthStore = defineStore('auth', () => {
|
||||||
const user = ref(tokenService.getUserInfo())
|
const user = ref(tokenService.getUserInfo())
|
||||||
|
|
||||||
const isAuthenticated = computed(() => !!tokenService.getToken() && !!user.value)
|
const isAuthenticated = computed(() => !!tokenService.getToken() && !!user.value)
|
||||||
const role = computed(() => {
|
// Full set of roles this user holds — access should be additive across all
|
||||||
|
// of them, never just their first/"primary" one.
|
||||||
|
const roles = computed(() => {
|
||||||
const u = user.value
|
const u = user.value
|
||||||
if (!u) return null
|
if (!u) return []
|
||||||
if (Array.isArray(u.roles) && u.roles.length > 0) return u.roles[0]
|
if (Array.isArray(u.roles) && u.roles.length > 0) return u.roles
|
||||||
return u.role || u.roleName || null
|
if (u.role) return [u.role]
|
||||||
|
if (u.roleName) return [u.roleName]
|
||||||
|
return []
|
||||||
})
|
})
|
||||||
|
// Primary role, used only where a single default is needed (e.g. the
|
||||||
|
// landing route right after login) — never for access control.
|
||||||
|
const role = computed(() => roles.value[0] || null)
|
||||||
|
|
||||||
const setUser = (userData) => {
|
const setUser = (userData) => {
|
||||||
user.value = userData
|
user.value = userData
|
||||||
tokenService.saveUserInfo(userData)
|
tokenService.saveUserInfo(userData)
|
||||||
|
// Only a real, token-backed session should tell WordPress "logged in" —
|
||||||
|
// setUser is also used to stash a phone number mid-signup, before any
|
||||||
|
// token exists, so gate the display-state cookie on the actual token.
|
||||||
|
if (tokenService.hasToken()) {
|
||||||
|
syncAuthStatusCookie(role.value)
|
||||||
|
} else {
|
||||||
|
clearAuthStatusCookie()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const clearUser = () => {
|
const clearUser = () => {
|
||||||
user.value = null
|
user.value = null
|
||||||
tokenService.clearAll()
|
tokenService.clearAll()
|
||||||
|
clearAuthStatusCookie()
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
user,
|
user,
|
||||||
role,
|
role,
|
||||||
|
roles,
|
||||||
isAuthenticated,
|
isAuthenticated,
|
||||||
setUser,
|
setUser,
|
||||||
clearUser,
|
clearUser,
|
||||||
|
|||||||
Reference in New Issue
Block a user