This commit is contained in:
hamid zarghami
2025-10-12 14:45:30 +03:30
parent 33aa1f2a8b
commit 37ed9bc074
9 changed files with 587 additions and 3 deletions
+90
View File
@@ -0,0 +1,90 @@
import { type FC } from 'react'
import { useNavigate } from 'react-router-dom'
import { useGetLearning } from './hooks/useSellerData'
import type { Learning as LearningType } from './types/Types'
import PageLoading from '../../components/PageLoading'
import Error from '../../components/Error'
import Td from '../../components/Td'
import Button from '@/components/Button'
import LearningTableRow from './components/LearningTableRow'
import { Pages } from '@/config/Pages'
const Learning: FC = () => {
const navigate = useNavigate()
const { data: learningData, isLoading, error } = useGetLearning()
const handleEditLearning = (learning: LearningType) => {
navigate(`${Pages.sellers.learningUpdate}${learning._id}`)
}
const handleCreateLearning = () => {
navigate(Pages.sellers.learningCreate)
}
if (isLoading) {
return (
<div className="flex justify-center items-center min-h-[400px]">
<PageLoading />
</div>
)
}
if (error) {
return (
<div className="flex justify-center items-center min-h-[400px]">
<Error errorText="خطا در بارگذاری یادگیری‌ها" />
</div>
)
}
const learnings = learningData?.results?.learning || []
return (
<div>
<div className='flex justify-end mt-5'>
<Button
label="ایجاد یادگیری جدید"
onClick={handleCreateLearning}
className="w-auto"
/>
</div>
<div className='relative overflow-x-auto rounded-3xl mt-5 w-full'>
<table className='w-full text-sm'>
<thead className='thead'>
<tr>
<Td text={'کاور'} />
<Td text={'عنوان و توضیحات'} />
<Td text={'ویدیو'} />
<Td text={'دسته‌بندی'} />
<Td text={'وضعیت'} />
<Td text={'تاریخ ایجاد'} />
<Td text={'عملیات'} />
</tr>
</thead>
<tbody>
{learnings.length === 0 ? (
<tr className='tr'>
<td colSpan={7} className="text-center py-8 text-gray-500">
هیچ یادگیری یافت نشد
</td>
</tr>
) : (
learnings.map((learning: LearningType) => (
<LearningTableRow
key={learning._id}
learning={learning}
onEdit={handleEditLearning}
/>
))
)}
</tbody>
</table>
</div>
</div>
)
}
export default Learning