import { useCallback, useEffect, useState } from 'react' import { GridDto } from '@/proxy/form/models' import { useListFormCustomDataSource } from '@/shared/useListFormCustomDataSource' import { Pagination, Select } from '@/components/ui' import classNames from 'classnames' import { getList } from '@/services/form.service' import { FaInbox } from 'react-icons/fa' import FormView from '../form/FormView' interface CardProps { listFormCode: string searchParams?: URLSearchParams } type Option = { value: number label: string } const CardItem = ({ row, gridDto, listFormCode, }: { row: any gridDto: GridDto listFormCode: string }) => { const keyField = gridDto.gridOptions.keyFieldName const rowId = row[keyField!] return (
) } const Card = ({ listFormCode, searchParams }: CardProps) => { const { createSelectDataSource } = useListFormCustomDataSource({}) const [gridDto, setGridDto] = useState() const [data, setData] = useState([]) const [totalCount, setTotalCount] = useState(0) const [currentPage, setCurrentPage] = useState(1) const [pageSize, setPageSize] = useState(20) const [pageSizeOptions, setPageSizeOptions] = useState([]) const onPageSizeSelect = ({ value }: Option) => { setPageSize(value) setCurrentPage(1) } const onPageChange = (page: number) => { setCurrentPage(page) } const loadData = useCallback(() => { if (!gridDto) return const store = createSelectDataSource(gridDto.gridOptions, listFormCode, searchParams) const loadOptions = { skip: (currentPage - 1) * pageSize, take: pageSize, requireTotalCount: true, } store.load(loadOptions).then((res: any) => { setData(res.data) setTotalCount(res.totalCount || 0) }) }, [gridDto, listFormCode, searchParams, currentPage, pageSize]) useEffect(() => { getList({ listFormCode }).then((res: any) => setGridDto(res.data)) }, [listFormCode]) useEffect(() => { if (!gridDto) return const pagerOptions = gridDto.gridOptions.pagerOptionDto const allowedSizes = pagerOptions?.allowedPageSizes ?.split(',') .map((s) => Number(s.trim())) .filter((n) => !isNaN(n) && n > 0) || [20, 50, 100] setPageSizeOptions(allowedSizes.map((size) => ({ value: size, label: `${size} page` }))) }, [gridDto, listFormCode, searchParams]) useEffect(() => { loadData() }, [loadData]) if (!gridDto) return null return ( <> {data.length === 0 && (

Kayıt Bulunamadı

Görüntülenecek herhangi bir veri yok.

)}
{data.map((row, idx) => { const keyField = gridDto.gridOptions.keyFieldName const rowId = row[keyField!] return })}
{gridDto.gridOptions.pagerOptionDto?.visible && totalCount > pageSize && (
Toplam {totalCount} kayıt