import { type FC } from 'react' import { useDeleteAboutUs, useGetAboutUs } from './hooks/useSettingData' import { type AboutUsItem } from './types/Types' import PageLoading from '../../components/PageLoading' import Error from '../../components/Error' import Td from '../../components/Td' import { Calendar, DocumentText, Add } from 'iconsax-react' import Button from '../../components/Button' import { useNavigate } from 'react-router-dom' import { Pages } from '@/config/Pages' import TrashWithConfrim from '@/components/TrashWithConfrim' import { useQueryClient } from '@tanstack/react-query' const AboutUsList: FC = () => { const navigate = useNavigate(); const queryClient = useQueryClient(); const deleteAboutUs = useDeleteAboutUs(); const { data, isLoading, error } = useGetAboutUs(); if (isLoading) { return (
); } if (error) { return (
); } const aboutUsItems = data?.results?.aboutUs || []; const formatDate = (dateString: string) => { if (!dateString) return '-'; return new Date(dateString).toLocaleDateString('fa-IR'); }; const truncateText = (text: string, maxLength: number = 50) => { if (text.length <= maxLength) return text; return text.substring(0, maxLength) + '...'; }; return (
{aboutUsItems.length === 0 ? ( ) : ( aboutUsItems.map((item: AboutUsItem) => ( )) )}
هیچ اطلاعاتی یافت نشد
{item.title}
{item.title}
{truncateText(item.description)}
{formatDate(item.createdAt)}
{ deleteAboutUs.mutate(item._id, { onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['aboutUs'] }) } }) }} />
) } export default AboutUsList