6 Commits

Author SHA1 Message Date
Saghar Mohammadi 9f86acacb0 feat(batch-1): multi-role sidebar, video display, certificate layout, upload progress, counselor access
- roleMenuItems.js: merged menu builder that unions items from all user roles
  (student + missionary, student + counselor, etc.) additively
- auth store: expose `roles` array in addition to singular `role`; wire in
  WordPress auth-status cookie sync so the public site can show/hide the
  account button
- router guards: use roles.includes() instead of role === for multi-role access
- layouts (Student/Counselor/Missionary): delegate menuItems to
  buildMergedMenuItems so dual-role users see sections from both roles
- StudentSessionDetailsPage: contentKind now returns 'video' (not 'link')
  when session.videoUrl is set; adds embed iframe branch for online sessions
- CertificateItem.vue: fix CSS order/alignment for desktop + mobile layout
- StudentCertificatesPage.vue: map backend payload fields to component props
  with Jalaali date formatting
- SessionFormPage: upload progress bar (%) during video uploads; embed_code
  textarea for online sessions (frontend-only; dormant until batch-2 backend
  migration is deployed)
- wp-sync/auth-status-cookie.js: cookie helper for WordPress login-state sync

[batch-1-low-risk]
2026-09-02 11:17:20 +04:30
sajjadtalkhabi 81332abdb0 fix: bugs
Deploy banu-front / deploy (push) Successful in 1m47s
2026-08-18 09:08:45 +03:30
sajjadtalkhabi e4a0eb463b Merge branch 'master' of ssh://git.madresebanoo.ir:2222/front-end/banu-front
Deploy banu-front / deploy (push) Successful in 2m0s
2026-08-17 16:59:27 +03:30
sajjadtalkhabi 20551fee63 fix: bugs 2026-08-17 16:59:24 +03:30
Server Migration 612a6e3dfe Merge remote-tracking branch 'origin/master'
Deploy banu-front / deploy (push) Successful in 2m42s
2026-08-16 17:07:32 +03:30
Server Migration 861773b05b fix: make admin media uploads reliable 2026-08-16 17:03:36 +03:30
25 changed files with 501 additions and 138 deletions
+8
View File
@@ -7,7 +7,9 @@
</button> </button>
</div> </div>
<div class="header-block__logo"> <div class="header-block__logo">
<a :href="MAIN_SITE_URL">
<img :src="logo" alt="logo" /> <img :src="logo" alt="logo" />
</a>
</div> </div>
<div class="header-block__title"> <div class="header-block__title">
<slot> <slot>
@@ -52,6 +54,7 @@
import { computed, ref } from 'vue' import { computed, ref } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import { useUIStore } from '@/store/ui' import { useUIStore } from '@/store/ui'
import { MAIN_SITE_URL } from '@/enums'
import { gallery } from '@/utils/gallery' import { gallery } from '@/utils/gallery'
import useAuth from '@/composables/useAuth' import useAuth from '@/composables/useAuth'
import SvgIcon from '@/components/icons/SvgIcon.vue' import SvgIcon from '@/components/icons/SvgIcon.vue'
@@ -149,7 +152,12 @@ const iconList = [
display: none; display: none;
} }
a {
display: block;
}
img { img {
display: block;
margin: 0 auto; margin: 0 auto;
height: 3.5rem; height: 3.5rem;
object-fit: contain; object-fit: contain;
+18 -2
View File
@@ -3,9 +3,12 @@
<label class="file-uploader__dropzone-wrap"> <label class="file-uploader__dropzone-wrap">
<div <div
class="file-uploader__dropzone" class="file-uploader__dropzone"
:class="{ 'file-uploader__dropzone--active': isDragging }" :class="{
'file-uploader__dropzone--active': isDragging,
'file-uploader__dropzone--disabled': disabled,
}"
@dragover.prevent @dragover.prevent
@dragenter="isDragging = true" @dragenter="onDragEnter"
@dragleave="isDragging = false" @dragleave="isDragging = false"
@drop="handleDrop" @drop="handleDrop"
> >
@@ -19,6 +22,7 @@
class="file-uploader__input" class="file-uploader__input"
:accept="accept" :accept="accept"
:multiple="multiple" :multiple="multiple"
:disabled="disabled"
@change="handleFileSelect" @change="handleFileSelect"
/> />
</div> </div>
@@ -75,6 +79,7 @@ const props = defineProps({
multiple: { type: Boolean, default: true }, multiple: { type: Boolean, default: true },
maxFiles: { type: Number, default: 10 }, maxFiles: { type: Number, default: 10 },
maxSize: { type: Number, default: 0 }, maxSize: { type: Number, default: 0 },
disabled: { type: Boolean, default: false },
}) })
const emit = defineEmits(['update:modelValue', 'select', 'remove', 'error']) const emit = defineEmits(['update:modelValue', 'select', 'remove', 'error'])
@@ -82,6 +87,7 @@ const emit = defineEmits(['update:modelValue', 'select', 'remove', 'error'])
const isDragging = ref(false) const isDragging = ref(false)
const handleFileSelect = (event) => { const handleFileSelect = (event) => {
if (props.disabled) return
const files = [...event.target.files] const files = [...event.target.files]
emitFiles(files) emitFiles(files)
event.target.value = '' event.target.value = ''
@@ -90,10 +96,15 @@ const handleFileSelect = (event) => {
const handleDrop = (event) => { const handleDrop = (event) => {
event.preventDefault() event.preventDefault()
isDragging.value = false isDragging.value = false
if (props.disabled) return
const files = [...event.dataTransfer.files] const files = [...event.dataTransfer.files]
emitFiles(files) emitFiles(files)
} }
const onDragEnter = () => {
if (!props.disabled) isDragging.value = true
}
const emitFiles = (files) => { const emitFiles = (files) => {
if (props.modelValue.length + files.length > props.maxFiles) { if (props.modelValue.length + files.length > props.maxFiles) {
emit('error', `حداکثر تعداد فایل مجاز ${props.maxFiles} عدد است.`) emit('error', `حداکثر تعداد فایل مجاز ${props.maxFiles} عدد است.`)
@@ -155,6 +166,11 @@ const formatFileSize = (bytes) => {
&--active { &--active {
border-color: var(--color-primary); border-color: var(--color-primary);
} }
&--disabled {
cursor: not-allowed;
opacity: 0.55;
}
} }
&__upload-icon { &__upload-icon {
+15 -4
View File
@@ -53,6 +53,8 @@ export const USER_STATUS = Object.freeze({
export const MARITAL_STATUS = Object.freeze({ export const MARITAL_STATUS = Object.freeze({
single: 'مجرد', single: 'مجرد',
married: 'متاهل', married: 'متاهل',
divorced: 'مطلقه',
widowed: 'بیوه',
}) })
export const GENDER = Object.freeze({ export const GENDER = Object.freeze({
@@ -138,9 +140,15 @@ export const COURSE_CONTENT_TYPE = Object.freeze({
}) })
export const COURSE_CONTENT_TYPE_ACCEPT = Object.freeze({ export const COURSE_CONTENT_TYPE_ACCEPT = Object.freeze({
video: 'video/*', video: '.mp4,.webm,video/mp4,video/webm',
voice: 'audio/*', voice: '.mp3,.wav,.m4a,.webm,audio/mpeg,audio/wav,audio/mp4,audio/webm',
text: '.pdf,.doc,.docx,.txt', text: '.pdf,application/pdf',
})
export const COURSE_CONTENT_TYPE_MAX_SIZE = Object.freeze({
video: 300 * 1024 * 1024,
voice: 50 * 1024 * 1024,
text: 50 * 1024 * 1024,
}) })
export const SESSION_TYPE = Object.freeze({ export const SESSION_TYPE = Object.freeze({
@@ -212,8 +220,11 @@ export const MISSIONARY_REQUEST_STATUS = Object.freeze({
rejected: 'رد شده', rejected: 'رد شده',
}) })
export const MAIN_SITE_URL = 'https://madresebanoo.ir/'
// Landing route per role after login / when a logged-in user hits a guest // Landing route per role after login / when a logged-in user hits a guest
// page. Roles not listed here fall back to the student dashboard. // page. Roles not listed here fall back to the student dashboard. Approved
// users of every role except admin bypass this and land on MAIN_SITE_URL.
export const ROLE_HOME_ROUTES = Object.freeze({ export const ROLE_HOME_ROUTES = Object.freeze({
admin: 'admin-dashboard', admin: 'admin-dashboard',
counselor: 'counselor-dashboard', counselor: 'counselor-dashboard',
@@ -33,7 +33,7 @@
<SelectField <SelectField
v-model="form.teacherId" v-model="form.teacherId"
name="teacherId" name="teacherId"
label="استاد" label="استاد (اختیاری)"
:options="teacherOptions" :options="teacherOptions"
option-label="name" option-label="name"
option-value="id" option-value="id"
@@ -251,12 +251,12 @@ watch(
{ immediate: true } { immediate: true }
) )
const uploadMutation = useUploadMediaMutation() const coverUploadMutation = useUploadMediaMutation()
const onImageCropped = async (file) => { const onImageCropped = async (file) => {
try { try {
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 coverUploadMutation.mutateAsync(formData)
const payload = response?.data ?? response const payload = response?.data ?? response
image.value = { url: payload?.url, ...payload } image.value = { url: payload?.url, ...payload }
form.value.coverMediaId = payload?.id form.value.coverMediaId = payload?.id
@@ -270,16 +270,29 @@ const onImageError = (msg) => toast.error(msg)
const addMutation = useAddAdminCourseMutation() const addMutation = useAddAdminCourseMutation()
const updateMutation = useUpdateAdminCourseMutation() const updateMutation = useUpdateAdminCourseMutation()
const submitting = computed(() => addMutation.isPending.value || updateMutation.isPending.value) const submitting = computed(
() =>
coverUploadMutation.isPending.value ||
addMutation.isPending.value ||
updateMutation.isPending.value
)
const onSubmit = async () => { const onSubmit = async () => {
if (coverUploadMutation.isPending.value) {
toast.info('لطفاً تا پایان بارگذاری تصویر دوره منتظر بمانید.')
return
}
const { isValid, payload } = await validate(form.value) const { isValid, payload } = await validate(form.value)
if (!isValid) return if (!isValid) return
try {
if (isEditMode.value) { if (isEditMode.value) {
await updateMutation.mutateAsync({ id: courseId.value, payload }) await updateMutation.mutateAsync({ id: courseId.value, payload })
} else { } else {
await addMutation.mutateAsync(payload) await addMutation.mutateAsync(payload)
} }
} catch {
return
}
await queryClient.invalidateQueries({ queryKey: adminCoursesKeys.all }) await queryClient.invalidateQueries({ queryKey: adminCoursesKeys.all })
router.push({ name: 'admin-courses' }) router.push({ name: 'admin-courses' })
} }
@@ -69,7 +69,12 @@ const courseIcon = gallery.courseIcon
const routeTermId = computed(() => (route.params.termId ? Number(route.params.termId) : null)) const routeTermId = computed(() => (route.params.termId ? Number(route.params.termId) : null))
const onAdd = () => { const onAdd = () => {
router.push({ name: 'admin-add-course' }).catch(() => {}) router
.push({
name: 'admin-add-course',
query: routeTermId.value ? { termId: routeTermId.value } : undefined,
})
.catch(() => {})
} }
const tabs = [ const tabs = [
+2 -1
View File
@@ -2,7 +2,8 @@ import { array, boolean, mixed, number, object, string } from 'yup'
export const courseSchema = object().shape({ export const courseSchema = object().shape({
title: string().required().min(3).max(255), title: string().required().min(3).max(255),
teacherId: mixed().required(), // The backend intentionally allows courses without an assigned teacher.
teacherId: mixed().nullable().notRequired(),
capacity: number() capacity: number()
.typeError('ظرفیت باید به‌صورت عدد وارد شود') .typeError('ظرفیت باید به‌صورت عدد وارد شود')
.required() .required()
@@ -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
@@ -95,11 +108,23 @@
:accept="contentAccept" :accept="contentAccept"
:multiple="false" :multiple="false"
:max-files="1" :max-files="1"
:disabled="!form.contentType" :max-size="contentMaxSize"
:disabled="!form.contentType || contentUploadMutation.isPending.value"
@select="onContentSelect" @select="onContentSelect"
@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>
@@ -162,7 +187,12 @@ import TextareaField from '@/components/form/TextareaField.vue'
import { sessionSchema } from '@/features/admin/sessions/schema' import { sessionSchema } from '@/features/admin/sessions/schema'
import { useAdminCoursesListQuery } from '@/services/query/admin-courses' import { useAdminCoursesListQuery } from '@/services/query/admin-courses'
import BoxedIconTitleBlock from '@/components/blocks/BoxedIconTitleBlock.vue' import BoxedIconTitleBlock from '@/components/blocks/BoxedIconTitleBlock.vue'
import { COURSE_CONTENT_TYPE, COURSE_CONTENT_TYPE_ACCEPT, SESSION_TYPE } from '@/enums' import {
COURSE_CONTENT_TYPE,
COURSE_CONTENT_TYPE_ACCEPT,
COURSE_CONTENT_TYPE_MAX_SIZE,
SESSION_TYPE,
} from '@/enums'
import { import {
adminSessionsKeys, adminSessionsKeys,
useAddAdminSessionMutation, useAddAdminSessionMutation,
@@ -175,6 +205,7 @@ const router = useRouter()
const queryClient = useQueryClient() const queryClient = useQueryClient()
const sessionId = computed(() => (route.params.id ? Number(route.params.id) : null)) const sessionId = computed(() => (route.params.id ? Number(route.params.id) : null))
const presetCourseId = computed(() => (route.query.courseId ? Number(route.query.courseId) : null))
const isEditMode = computed(() => !!sessionId.value) const isEditMode = computed(() => !!sessionId.value)
const sessionTypeOptions = [ const sessionTypeOptions = [
@@ -189,10 +220,11 @@ const contentTypeOptions = Object.entries(COURSE_CONTENT_TYPE).map(([value, labe
const form = ref({ const form = ref({
title: '', title: '',
courseId: '', courseId: presetCourseId.value ?? '',
contentType: '', contentType: '',
type: '', type: '',
link: '', link: '',
embedCode: '',
description: '', description: '',
}) })
@@ -200,8 +232,12 @@ 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(
() => COURSE_CONTENT_TYPE_MAX_SIZE[form.value.contentType] || 50 * 1024 * 1024
)
const { validate, validateAt, errors } = useYup(sessionSchema) const { validate, validateAt, errors } = useYup(sessionSchema)
@@ -228,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, {
@@ -257,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
@@ -276,7 +316,8 @@ watch(
{ immediate: true } { immediate: true }
) )
const uploadMutation = useUploadMediaMutation() const contentUploadMutation = useUploadMediaMutation()
const coverUploadMutation = useUploadMediaMutation()
const purposeForContentType = (contentType) => { const purposeForContentType = (contentType) => {
if (contentType === 'video') return 'video' if (contentType === 'video') return 'video'
@@ -287,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 uploadMutation.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 }]
@@ -313,7 +361,7 @@ const onContentError = (msg) => toast.error(msg)
const onImageCropped = async (file) => { const onImageCropped = async (file) => {
try { try {
const formData = objectToFormData({ file, purpose: 'cover', context: 'session' }) const formData = objectToFormData({ file, purpose: 'cover', context: 'session' })
const response = await uploadMutation.mutateAsync(formData) const response = await coverUploadMutation.mutateAsync(formData)
const payload = response?.data ?? response const payload = response?.data ?? response
image.value = { url: payload?.url, ...payload } image.value = { url: payload?.url, ...payload }
coverMediaId.value = payload?.id ?? null coverMediaId.value = payload?.id ?? null
@@ -331,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,
} }
@@ -346,17 +395,35 @@ const buildPayload = (values) => {
const addMutation = useAddAdminSessionMutation() const addMutation = useAddAdminSessionMutation()
const updateMutation = useUpdateAdminSessionMutation() const updateMutation = useUpdateAdminSessionMutation()
const submitting = computed(() => addMutation.isPending.value || updateMutation.isPending.value) const submitting = computed(
() =>
contentUploadMutation.isPending.value ||
coverUploadMutation.isPending.value ||
addMutation.isPending.value ||
updateMutation.isPending.value
)
const onSubmit = async () => { const onSubmit = async () => {
if (contentUploadMutation.isPending.value || coverUploadMutation.isPending.value) {
toast.info('لطفاً تا پایان بارگذاری محتوای جلسه منتظر بمانید.')
return
}
const { isValid } = await validate(form.value) const { isValid } = await validate(form.value)
if (!isValid) return if (!isValid) return
if (form.value.contentType && contentMediaId.value == null) {
toast.error('برای نوع محتوای انتخاب‌شده، فایل جلسه را بارگذاری کنید.')
return
}
const payload = buildPayload(form.value) const payload = buildPayload(form.value)
try {
if (isEditMode.value) { if (isEditMode.value) {
await updateMutation.mutateAsync({ id: sessionId.value, payload }) await updateMutation.mutateAsync({ id: sessionId.value, payload })
} else { } else {
await addMutation.mutateAsync(payload) await addMutation.mutateAsync(payload)
} }
} catch {
return
}
// The list query is inactive while we're on the form page, and the global // The list query is inactive while we're on the form page, and the global
// `refetchOnMount: false` means navigating back won't refetch a merely-stale // `refetchOnMount: false` means navigating back won't refetch a merely-stale
// query — so force a refetch of all matching queries, active or not. // query — so force a refetch of all matching queries, active or not.
@@ -448,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;
} }
@@ -109,7 +109,12 @@ const onFilterApply = () => resetPagination()
const onFilterReset = () => resetPagination() const onFilterReset = () => resetPagination()
const onAdd = () => { const onAdd = () => {
router.push({ name: 'admin-add-session' }).catch(() => {}) router
.push({
name: 'admin-add-session',
query: routeCourseId.value ? { courseId: routeCourseId.value } : undefined,
})
.catch(() => {})
} }
const onEdit = (session) => { const onEdit = (session) => {
@@ -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,6 +1,8 @@
import { ROLE_HOME_ROUTES } from '@/enums'
import { useAuthStore } from '@/store/auth' import { useAuthStore } from '@/store/auth'
import { useRoute, useRouter } from 'vue-router' 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'
export const useRedirectAfterLogin = () => { export const useRedirectAfterLogin = () => {
const router = useRouter() const router = useRouter()
@@ -13,6 +15,10 @@ export const useRedirectAfterLogin = () => {
router.push(redirect).catch(() => router.push('/')) router.push(redirect).catch(() => router.push('/'))
return return
} }
if (shouldLandOnMainSite(auth)) {
window.location.href = MAIN_SITE_URL
return
}
const target = { name: ROLE_HOME_ROUTES[auth.role] || 'student-dashboard' } const target = { name: ROLE_HOME_ROUTES[auth.role] || 'student-dashboard' }
router.push(target).catch(() => router.push('/')) router.push(target).catch(() => router.push('/'))
} }
@@ -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,
@@ -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;
+4 -14
View File
@@ -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>
+4 -26
View File
@@ -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>
+4 -46
View File
@@ -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>
+124
View File
@@ -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
}
+3
View File
@@ -1,7 +1,9 @@
<template> <template>
<aside class="admin-sidebar"> <aside class="admin-sidebar">
<div class="admin-sidebar__logo"> <div class="admin-sidebar__logo">
<a :href="MAIN_SITE_URL">
<img :src="logo" alt="مدرسه بانو" /> <img :src="logo" alt="مدرسه بانو" />
</a>
</div> </div>
<nav class="admin-sidebar__nav"> <nav class="admin-sidebar__nav">
<ul> <ul>
@@ -56,6 +58,7 @@
<script setup> <script setup>
import { ref, watch } from 'vue' import { ref, watch } from 'vue'
import { RouterLink } from 'vue-router' import { RouterLink } from 'vue-router'
import { MAIN_SITE_URL } from '@/enums'
import { gallery } from '@/utils/gallery' import { gallery } from '@/utils/gallery'
import SvgIcon from '@/components/icons/SvgIcon.vue' import SvgIcon from '@/components/icons/SvgIcon.vue'
import SidebarLogout from '@/layouts/sidebars/SidebarLogout.vue' import SidebarLogout from '@/layouts/sidebars/SidebarLogout.vue'
@@ -1,7 +1,9 @@
<template> <template>
<aside class="counselor-sidebar"> <aside class="counselor-sidebar">
<div class="counselor-sidebar__logo"> <div class="counselor-sidebar__logo">
<a :href="MAIN_SITE_URL">
<img :src="logo" alt="مدرسه بانو" /> <img :src="logo" alt="مدرسه بانو" />
</a>
</div> </div>
<nav class="counselor-sidebar__nav"> <nav class="counselor-sidebar__nav">
<ul> <ul>
@@ -23,6 +25,7 @@
</template> </template>
<script setup> <script setup>
import { MAIN_SITE_URL } from '@/enums'
import { gallery } from '@/utils/gallery' import { gallery } from '@/utils/gallery'
import SvgIcon from '@/components/icons/SvgIcon.vue' import SvgIcon from '@/components/icons/SvgIcon.vue'
import SidebarLogout from '@/layouts/sidebars/SidebarLogout.vue' import SidebarLogout from '@/layouts/sidebars/SidebarLogout.vue'
+3
View File
@@ -1,7 +1,9 @@
<template> <template>
<aside class="student-sidebar" :style="{ backgroundImage: `url(${bgPattern})` }"> <aside class="student-sidebar" :style="{ backgroundImage: `url(${bgPattern})` }">
<div class="student-sidebar__logo"> <div class="student-sidebar__logo">
<a :href="MAIN_SITE_URL">
<img :src="logo" alt="مدرسه بانو" /> <img :src="logo" alt="مدرسه بانو" />
</a>
</div> </div>
<nav class="student-sidebar__nav"> <nav class="student-sidebar__nav">
<ul> <ul>
@@ -23,6 +25,7 @@
</template> </template>
<script setup> <script setup>
import { MAIN_SITE_URL } from '@/enums'
import { gallery } from '@/utils/gallery' import { gallery } from '@/utils/gallery'
import SvgIcon from '@/components/icons/SvgIcon.vue' import SvgIcon from '@/components/icons/SvgIcon.vue'
import SidebarLogout from '@/layouts/sidebars/SidebarLogout.vue' import SidebarLogout from '@/layouts/sidebars/SidebarLogout.vue'
+2 -2
View File
@@ -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
+5 -1
View File
@@ -43,4 +43,8 @@ export const apiSaveRegisterData = (data) => http.post(endpoints.registerData, {
export const apiGetRegistrationQuestionVideo = () => export const apiGetRegistrationQuestionVideo = () =>
http.get(endpoints.getRegistrationQuestionVideo) http.get(endpoints.getRegistrationQuestionVideo)
export const apiUploadMedia = (formData) => http.post(endpoints.uploadMedia, formData) // Media uploads (especially course videos) can legitimately take several
// 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.
export const apiUploadMedia = (formData) =>
http.post(endpoints.uploadMedia, formData, { timeout: 10 * 60 * 1000 })
@@ -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
View File
@@ -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,
+12
View File
@@ -24,6 +24,18 @@ export function handleApiError(error_) {
const data = error_?.response?.data const data = error_?.response?.data
const status = error_?.response?.status const status = error_?.response?.status
if (error_?.code === 'ECONNABORTED') {
toast.error(
'زمان بارگذاری فایل به پایان رسید. لطفاً اتصال اینترنت را بررسی و دوباره تلاش کنید.'
)
return
}
if (status === 413) {
toast.error('حجم فایل از حداکثر مجاز بیشتر است.')
return
}
if (status === 422 && data?.errors) { if (status === 422 && data?.errors) {
Object.values(data.errors).forEach((messages) => { Object.values(data.errors).forEach((messages) => {
const list = Array.isArray(messages) ? messages : [messages] const list = Array.isArray(messages) ? messages : [messages]