fix: ticket

This commit is contained in:
sajjadtalkhabi
2026-06-05 18:43:02 +03:30
parent 1c665830b0
commit ea562aeefa
53 changed files with 2475 additions and 859 deletions
@@ -35,9 +35,11 @@
<script setup>
import { computed, ref } from 'vue'
import { toast } from 'vue3-toastify'
import { TICKET_STATUS } from '@/enums'
import { useQueryClient } from '@tanstack/vue-query'
import SvgIcon from '@/components/icons/SvgIcon.vue'
import NoItems from '@/components/blocks/NoItems.vue'
import { formatJalaaliDate } from '@/utils/date-utils'
import TabsBlock from '@/components/blocks/TabsBlock.vue'
import { usePagination } from '@/composables/usePagination'
import PaginationBlock from '@/components/blocks/PaginationBlock.vue'
@@ -46,10 +48,10 @@ import SkeletonLoaderBlock from '@/components/blocks/SkeletonLoaderBlock.vue'
import ConsultantItem from '@/features/student/consultants/components/ConsultantItem.vue'
import RequestConsultantForm from '@/features/student/consultants/components/RequestConsultantForm.vue'
import {
studentConsultantsKeys,
useCreateStudentConsultantMutation,
useStudentConsultantsQuery,
} from '@/services/query/student-consultants'
studentTicketsKeys,
useCreateStudentTicketMutation,
useStudentTicketsQuery,
} from '@/services/query/student-tickets'
const queryClient = useQueryClient()
@@ -59,13 +61,13 @@ const tabs = [
]
const activeTab = ref('create')
const historyFilters = ref({})
const historyFilters = ref({ type: 'advise' })
const { pagination: historyPagination, setPage: setHistoryPage } = usePagination({
page: 1,
perPage: 10,
})
const { data: historyData, isLoading: historyLoading } = useStudentConsultantsQuery(
const { data: historyData, isLoading: historyLoading } = useStudentTicketsQuery(
historyFilters,
historyPagination,
{
@@ -74,20 +76,42 @@ const { data: historyData, isLoading: historyLoading } = useStudentConsultantsQu
}
)
const consultants = computed(() => historyData.value?.data ?? [])
const formatTime = (iso) => {
if (!iso) return ''
const d = new Date(iso)
if (Number.isNaN(d.getTime())) return ''
return d.toLocaleTimeString('fa-IR', { hour: '2-digit', minute: '2-digit' })
}
// ConsultantItem expects title/requestNumber/dateLabel/timeLabel/statusLabel.
// Bridge the new backend payload without touching the item template.
const consultants = computed(() =>
(historyData.value?.data?.items ?? []).map((t) => ({
...t,
title: t.subject ?? '',
requestNumber: t.id,
dateLabel: formatJalaaliDate(t.createdAt) || '',
timeLabel: formatTime(t.createdAt),
statusLabel: TICKET_STATUS[t.status] ?? '',
}))
)
const historyMeta = computed(() => ({
page: historyPagination.value.page,
perPage: historyPagination.value.perPage,
...historyData.value?.meta,
}))
const createMutation = useCreateStudentConsultantMutation()
const createMutation = useCreateStudentTicketMutation()
const onSubmit = async (payload) => {
const onSubmit = async (formPayload) => {
try {
await createMutation.mutateAsync(payload)
await createMutation.mutateAsync({
type: 'advise',
subject: formPayload.subject,
message: formPayload.message,
})
toast.success('درخواست مشاوره با موفقیت ثبت شد.')
await queryClient.invalidateQueries({ queryKey: studentConsultantsKeys.all })
await queryClient.invalidateQueries({ queryKey: studentTicketsKeys.all })
activeTab.value = 'history'
} catch {
toast.error('ثبت درخواست با خطا مواجه شد.')