connected tickets table to api
This commit is contained in:
@@ -1,4 +1,10 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
// imports
|
||||||
|
|
||||||
|
import useGetAllTickets, {
|
||||||
|
type GetAllTicketsFilters,
|
||||||
|
} from "~/composables/api/tickets/useGetAllTickets";
|
||||||
|
|
||||||
// meta
|
// meta
|
||||||
|
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
@@ -8,10 +14,12 @@ definePageMeta({
|
|||||||
|
|
||||||
// state
|
// state
|
||||||
|
|
||||||
const filters = ref({
|
const params = useUrlSearchParams();
|
||||||
|
|
||||||
|
const filters = ref<GetAllTicketsFilters>({
|
||||||
sort: undefined,
|
sort: undefined,
|
||||||
status: undefined,
|
filter: undefined,
|
||||||
search: "",
|
page: params.page ?? 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
const tableHeads = ref([
|
const tableHeads = ref([
|
||||||
@@ -21,6 +29,22 @@ const tableHeads = ref([
|
|||||||
"وضعیت",
|
"وضعیت",
|
||||||
"عملیات",
|
"عملیات",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// queries
|
||||||
|
|
||||||
|
const { data, isLoading: ticketsIsLoading } = useGetAllTickets(filters);
|
||||||
|
|
||||||
|
// computed
|
||||||
|
|
||||||
|
const tickets = computed(() => {
|
||||||
|
return data.value?.results.flat();
|
||||||
|
});
|
||||||
|
|
||||||
|
const paginationData = computed(() => {
|
||||||
|
return tickets!.value?.results.map((_, i: number) => {
|
||||||
|
return { type: "page", value: i };
|
||||||
|
});
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -47,7 +71,7 @@ const tableHeads = ref([
|
|||||||
'در حال پردازش',
|
'در حال پردازش',
|
||||||
'لغو شده',
|
'لغو شده',
|
||||||
]"
|
]"
|
||||||
v-model="filters.status!"
|
v-model="filters.filter!"
|
||||||
triggerRootClass="!py-2.5"
|
triggerRootClass="!py-2.5"
|
||||||
class="w-[5rem]"
|
class="w-[5rem]"
|
||||||
/>
|
/>
|
||||||
@@ -63,7 +87,14 @@ const tableHeads = ref([
|
|||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Table>
|
<Placeholder
|
||||||
|
v-if="!tickets?.length && !ticketsIsLoading"
|
||||||
|
class="!w-full !py-[5rem]"
|
||||||
|
icon="bi:ticket"
|
||||||
|
title="تیکتی یافت نشد"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Table v-else>
|
||||||
<template #thead>
|
<template #thead>
|
||||||
<th
|
<th
|
||||||
v-for="(tableHead, index) in tableHeads"
|
v-for="(tableHead, index) in tableHeads"
|
||||||
@@ -82,9 +113,22 @@ const tableHeads = ref([
|
|||||||
</th>
|
</th>
|
||||||
</template>
|
</template>
|
||||||
<template #tbody>
|
<template #tbody>
|
||||||
<TicketsTableRow v-for="i in 4" />
|
<template v-if="ticketsIsLoading">
|
||||||
|
<TicketsTableRowLoading v-for="i in 5" />
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<TicketsTableRow
|
||||||
|
v-for="(ticket, index) in tickets"
|
||||||
|
:key="index"
|
||||||
|
:data="ticket"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
</template>
|
</template>
|
||||||
</Table>
|
</Table>
|
||||||
|
|
||||||
|
<div v-if="tickets?.length > 10" class="w-full flex-center py-10">
|
||||||
|
<Pagination :items="paginationData" :total="data?.count" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user