This commit is contained in:
hamid zarghami
2025-03-03 15:29:50 +03:30
parent 37081ae981
commit dcf786330c
8 changed files with 53 additions and 15 deletions
+13 -3
View File
@@ -1,9 +1,9 @@
import { FC, useState } from 'react'
import { FC, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { Eye, MessageRemove, MessageTick, MessageTime } from 'iconsax-react'
import Tabs from '../../components/Tabs'
import Td from '../../components/Td'
import { Link } from 'react-router-dom'
import { Link, useSearchParams } from 'react-router-dom'
import { Pages } from '../../config/Pages'
import { useGetTickets } from './hooks/useTicketData'
import moment from 'moment-jalaali'
@@ -12,8 +12,18 @@ import { TicketItemType } from './types/TicketTypes'
const TicketList: FC = () => {
const { t } = useTranslation('global')
const [searchParams] = useSearchParams()
const [customerId, setCustomerId] = useState<string>('')
const [activeTab, setActiveTab] = useState<'ANSWERED' | 'PENDING' | 'CLOSED'>('PENDING')
const getTicket = useGetTickets(activeTab)
const getTicket = useGetTickets(activeTab, customerId)
useEffect(() => {
const urlCustomerId = searchParams.get('user')
if (urlCustomerId) {
setCustomerId(urlCustomerId)
}
}, [searchParams])
return (
<div className='mt-4'>
+3 -3
View File
@@ -2,10 +2,10 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import * as api from "../service/TicketServiec";
import { AddMessageTicketType, CreateCategoryType } from "../types/TicketTypes";
export const useGetTickets = (status: string) => {
export const useGetTickets = (status: string, customerId?: string) => {
return useQuery({
queryKey: ["tickets", status],
queryFn: () => api.getTickets(status),
queryKey: ["tickets", status, customerId],
queryFn: () => api.getTickets(status, customerId),
});
};
+6 -2
View File
@@ -1,8 +1,12 @@
import axios from "../../../config/axios";
import { AddMessageTicketType, CreateCategoryType } from "../types/TicketTypes";
export const getTickets = async (status: string) => {
const { data } = await axios.get(`/tickets/admin?status=${status}`);
export const getTickets = async (status: string, customerId?: string) => {
let query = `/tickets/admin?status=${status}`;
if (customerId) {
query += `&userId=${customerId}`;
}
const { data } = await axios.get(query);
return data;
};