From 443709b406cc0ce0c3bef1213cbe4c6703d9121b Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Sat, 4 Oct 2025 11:43:35 +0330 Subject: [PATCH] report category list --- src/config/Pages.ts | 3 + src/pages/contactUs/List.tsx | 77 +++++++++++++++++++ src/pages/contactUs/hooks/useContactUsData.ts | 9 +++ src/pages/contactUs/service/ContactService.ts | 12 +++ src/pages/contactUs/types/index.ts | 16 ++++ src/pages/report/Category.tsx | 65 +++++++++++++++- src/pages/report/hooks/useReportData.ts | 7 ++ src/pages/report/service/ReportService.ts | 10 ++- src/pages/report/types/Types.ts | 8 ++ src/router/Main.tsx | 3 + src/shared/SideBar.tsx | 8 +- src/shared/types/SharedTypes.ts | 9 +++ 12 files changed, 219 insertions(+), 8 deletions(-) create mode 100644 src/pages/contactUs/List.tsx create mode 100644 src/pages/contactUs/hooks/useContactUsData.ts create mode 100644 src/pages/contactUs/service/ContactService.ts create mode 100644 src/pages/contactUs/types/index.ts diff --git a/src/config/Pages.ts b/src/config/Pages.ts index cfab75f..6da8c8d 100644 --- a/src/config/Pages.ts +++ b/src/config/Pages.ts @@ -191,4 +191,7 @@ export const Pages = { list: "/jobs/list", resumes: "/jobs/resumes", }, + contactUs: { + list: "/contact-us/list", + }, }; diff --git a/src/pages/contactUs/List.tsx b/src/pages/contactUs/List.tsx new file mode 100644 index 0000000..8cfcecb --- /dev/null +++ b/src/pages/contactUs/List.tsx @@ -0,0 +1,77 @@ +import { type FC, useState } from 'react' +import { useGetContactUs } from './hooks/useContactUsData'; +import { type ContactUsItem } from './types'; +import PageLoading from '../../components/PageLoading'; +import Error from '../../components/Error'; +import PaginationUi from '../../components/PaginationUi'; +import Td from '../../components/Td'; + +const ContactUsList: FC = () => { + const [currentPage, setCurrentPage] = useState(1); + const { data: contactUsData, isLoading, error } = useGetContactUs(currentPage); + + if (isLoading) { + return ( +
+ +
+ ); + } + + if (error) { + return ( +
+ +
+ ); + } + + const contactUs = contactUsData?.results?.contactUs || []; + const pager = contactUsData?.results?.pager; + + const truncateText = (text: string, maxLength: number = 100) => { + return text.length > maxLength ? text.substring(0, maxLength) + '...' : text; + }; + + return ( +
+
+ + + + + + + {contactUs.length === 0 ? ( + + + + ) : ( + contactUs.map((contact: ContactUsItem, index: number) => ( + + + )) + )} + +
+ + +
+ هیچ پیامی یافت نشد +
+ + +
+
+ + { + setCurrentPage(page); + }} + /> +
+ ) +} + +export default ContactUsList \ No newline at end of file diff --git a/src/pages/contactUs/hooks/useContactUsData.ts b/src/pages/contactUs/hooks/useContactUsData.ts new file mode 100644 index 0000000..d85bdac --- /dev/null +++ b/src/pages/contactUs/hooks/useContactUsData.ts @@ -0,0 +1,9 @@ +import { useQuery } from "@tanstack/react-query"; +import * as api from "../service/ContactService"; + +export const useGetContactUs = (page: number = 1, limit: number = 10) => { + return useQuery({ + queryKey: ["contactUs", page, limit], + queryFn: () => api.getContactUs(page, limit), + }); +}; diff --git a/src/pages/contactUs/service/ContactService.ts b/src/pages/contactUs/service/ContactService.ts new file mode 100644 index 0000000..92ca9d2 --- /dev/null +++ b/src/pages/contactUs/service/ContactService.ts @@ -0,0 +1,12 @@ +import axios from "@/config/axios"; +import type { ContactUsResponse } from "../types"; + +export const getContactUs = async ( + page: number = 1, + limit: number = 10 +): Promise => { + const { data } = await axios.get( + `/admin/settings/contact-us?page=${page}&limit=${limit}` + ); + return data; +}; diff --git a/src/pages/contactUs/types/index.ts b/src/pages/contactUs/types/index.ts new file mode 100644 index 0000000..ca8f6e0 --- /dev/null +++ b/src/pages/contactUs/types/index.ts @@ -0,0 +1,16 @@ +import { type PagerType } from '../../../shared/types/SharedTypes'; + +export interface ContactUsItem { + fullName: string; + email_phone: string; + message: string; +} + +export interface ContactUsResponse { + status: number; + success: boolean; + results: { + pager: PagerType; + contactUs: ContactUsItem[]; + }; +} diff --git a/src/pages/report/Category.tsx b/src/pages/report/Category.tsx index f2b8571..c653752 100644 --- a/src/pages/report/Category.tsx +++ b/src/pages/report/Category.tsx @@ -1,10 +1,44 @@ import { type FC, useState } from 'react' import Button from '@/components/Button'; import CreateReportCategoryModal from './components/CreateReportCategoryModal.tsx'; +import { useGetReportCategories } from './hooks/useReportData.ts'; +import { type Reason } from './types/Types'; +import PageLoading from '../../components/PageLoading'; +import Error from '../../components/Error'; +import Td from '../../components/Td'; +import { useQueryClient } from '@tanstack/react-query'; const CategoryReport: FC = () => { + + const queryClient = useQueryClient(); + const { data: reportCategoriesResponse, isLoading, error } = useGetReportCategories(); const [isModalOpen, setIsModalOpen] = useState(false); + const handleCloseModal = () => { + setIsModalOpen(false); + queryClient.invalidateQueries({ queryKey: ['reportCategories'] }); + }; + + if (isLoading) { + return ( +
+ +
+ ); + } + + if (error) { + return ( +
+ +
+ ); + } + + const reportCategories = Array.isArray(reportCategoriesResponse?.results?.questions) + ? reportCategoriesResponse.results.questions + : []; + return (
@@ -14,11 +48,38 @@ const CategoryReport: FC = () => { className='w-fit' />
-
+
+ + + + + + + {reportCategories.length === 0 ? ( + + + + ) : ( + reportCategories.map((category: Reason) => ( + + + )) + )} + +
+ + +
+ هیچ دسته‌بندی یافت نشد +
+ + +
+
setIsModalOpen(false)} + onClose={handleCloseModal} />
) diff --git a/src/pages/report/hooks/useReportData.ts b/src/pages/report/hooks/useReportData.ts index 45ad602..1d9ee6f 100644 --- a/src/pages/report/hooks/useReportData.ts +++ b/src/pages/report/hooks/useReportData.ts @@ -13,3 +13,10 @@ export const useCreateReportCategory = () => { mutationFn: api.createReportCategory, }); }; + +export const useGetReportCategories = () => { + return useQuery({ + queryKey: ["reportCategories"], + queryFn: api.getReportCategories, + }); +}; diff --git a/src/pages/report/service/ReportService.ts b/src/pages/report/service/ReportService.ts index bd16c76..61d27cf 100644 --- a/src/pages/report/service/ReportService.ts +++ b/src/pages/report/service/ReportService.ts @@ -1,5 +1,9 @@ import axios from "../../../config/axios"; -import type { CreateReportCategoryType, ReportResponse } from "../types/Types"; +import type { + CreateReportCategoryType, + ReportResponse, + ReportCategoriesResponse, +} from "../types/Types"; export const getProductReport = async (): Promise => { const { data } = await axios.get("/admin/products/user-reports"); @@ -13,7 +17,9 @@ export const createReportCategory = async ( return data; }; -export const getReportQuestions = async () => { +export const getReportCategories = async (): Promise< + ReportCategoriesResponse +> => { const { data } = await axios.get("/admin/products/report-questions"); return data; }; diff --git a/src/pages/report/types/Types.ts b/src/pages/report/types/Types.ts index bac9584..e18b270 100644 --- a/src/pages/report/types/Types.ts +++ b/src/pages/report/types/Types.ts @@ -85,3 +85,11 @@ export interface ReportResponse { export interface CreateReportCategoryType { title: string; } + +export interface ReportCategoriesResponse { + status: number; + success: boolean; + results: { + questions: Reason[]; + }; +} diff --git a/src/router/Main.tsx b/src/router/Main.tsx index 28d160f..f60972f 100644 --- a/src/router/Main.tsx +++ b/src/router/Main.tsx @@ -60,6 +60,7 @@ import Banners from '@/pages/setting/Banners' import SiteSetting from '@/pages/setting/SiteSetting' import JobsList from '@/pages/jobs/List' import Resumes from '@/pages/jobs/Resume' +import ContactUsList from '@/pages/contactUs/List' const MainRouter: FC = () => { @@ -146,6 +147,8 @@ const MainRouter: FC = () => { } /> } /> + + } /> diff --git a/src/shared/SideBar.tsx b/src/shared/SideBar.tsx index 2bff307..a0cfc9e 100644 --- a/src/shared/SideBar.tsx +++ b/src/shared/SideBar.tsx @@ -212,7 +212,7 @@ const SideBar: FC = () => { icon={} title="ارتباط با ما" isActive={isActive('contact')} - link="/contact" + link={Pages.contactUs.list} activeName='contact' /> @@ -276,7 +276,7 @@ const SideBar: FC = () => { : subMenuName === 'tickets' ? : subMenuName === 'reports' ? : subMenuName === 'chat' ? - : subMenuName === 'contact' ? + : subMenuName === 'contact-us' ? : subMenuName === 'settings' ? : subMenuName === 'pages' ? : subMenuName === 'jobs' ? @@ -732,8 +732,8 @@ const ContactSubMenu: FC = () => {
diff --git a/src/shared/types/SharedTypes.ts b/src/shared/types/SharedTypes.ts index 1b7e445..ee50cd0 100644 --- a/src/shared/types/SharedTypes.ts +++ b/src/shared/types/SharedTypes.ts @@ -6,3 +6,12 @@ export type SharedStoreType = { subMenuName: string; setSubMenuName: (value: string) => void; }; + +export type PagerType = { + page: number; + limit: number; + totalItems: number; + totalPages: number; + prevPage: boolean | null; + nextPage: string | null; +};