fix: ticket
This commit is contained in:
@@ -22,10 +22,14 @@
|
||||
import { computed } from 'vue'
|
||||
import Badge from '@/components/Badge.vue'
|
||||
|
||||
// Backend statuses are open/answered/closed. Legacy keys stay in place for any
|
||||
// pre-migration cached data.
|
||||
const TONE_MAP = {
|
||||
approved: 'success',
|
||||
rejected: 'danger',
|
||||
pending: 'neutral',
|
||||
open: 'neutral',
|
||||
answered: 'success',
|
||||
closed: 'info',
|
||||
}
|
||||
|
||||
|
||||
@@ -3,15 +3,12 @@
|
||||
<form class="rcf__form" @submit.prevent="onSubmit">
|
||||
<div class="rcf__row">
|
||||
<div class="rcf__cell">
|
||||
<SelectField
|
||||
v-model="form.title"
|
||||
name="title"
|
||||
<TextField
|
||||
v-model="form.subject"
|
||||
name="subject"
|
||||
label="عنوان مشاوره درخواستی"
|
||||
placeholder="انتخاب کنید"
|
||||
:options="titleOptions"
|
||||
option-label="label"
|
||||
option-value="value"
|
||||
:error="errors.title"
|
||||
placeholder="عنوان مشاوره را وارد کنید"
|
||||
:error="errors.subject"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -19,12 +16,12 @@
|
||||
<div class="rcf__row">
|
||||
<div class="rcf__cell rcf__cell--full">
|
||||
<TextareaField
|
||||
v-model="form.description"
|
||||
name="description"
|
||||
v-model="form.message"
|
||||
name="message"
|
||||
label="توضیحات خود را وارد نمایید"
|
||||
placeholder="لورم ایپسوم متن ساختگی با تولید سادگی نامفهوم از صنعت چاپ و با استفاده از طراحان گرافیک است."
|
||||
:row="5"
|
||||
:error="errors.description"
|
||||
:error="errors.message"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -48,14 +45,13 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import * as yup from 'yup'
|
||||
import { computed, ref } from 'vue'
|
||||
import useYup from '@/composables/useYup'
|
||||
import BaseButton from '@/components/BaseButton.vue'
|
||||
import SvgIcon from '@/components/icons/SvgIcon.vue'
|
||||
import SelectField from '@/components/form/SelectField.vue'
|
||||
import TextField from '@/components/form/TextField.vue'
|
||||
import TextareaField from '@/components/form/TextareaField.vue'
|
||||
import { useStudentConsultantTitlesQuery } from '@/services/query/student-consultants'
|
||||
|
||||
defineProps({
|
||||
submitting: { type: Boolean, default: false },
|
||||
@@ -64,13 +60,13 @@ defineProps({
|
||||
const emit = defineEmits(['submit'])
|
||||
|
||||
const form = ref({
|
||||
title: '',
|
||||
description: '',
|
||||
subject: '',
|
||||
message: '',
|
||||
})
|
||||
|
||||
const schema = yup.object({
|
||||
title: yup.string().required('عنوان مشاوره را انتخاب کنید'),
|
||||
description: yup
|
||||
subject: yup.string().trim().required('عنوان مشاوره را وارد کنید'),
|
||||
message: yup
|
||||
.string()
|
||||
.trim()
|
||||
.min(5, 'توضیحات حداقل ۵ کاراکتر باشد')
|
||||
@@ -79,13 +75,10 @@ const schema = yup.object({
|
||||
|
||||
const { validate, errors } = useYup(schema)
|
||||
|
||||
const { data: titles } = useStudentConsultantTitlesQuery()
|
||||
const titleOptions = computed(() => titles.value ?? [])
|
||||
|
||||
const onSubmit = async () => {
|
||||
const { isValid, payload } = await validate(form.value)
|
||||
if (!isValid) return
|
||||
emit('submit', { ...payload })
|
||||
emit('submit', { subject: payload.subject, message: payload.message })
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -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('ثبت درخواست با خطا مواجه شد.')
|
||||
|
||||
Reference in New Issue
Block a user