import React, { useContext } from 'react'; import { useHistory } from 'react-router-dom'; import Page from '../Page'; import ListTable from '../../components/ListTable'; import hooks from '../../hooks/useAPIClient'; import ServiceContext from './ServiceContext'; const ServiceList: React.FC = () => { const service = useContext(ServiceContext); const history = useHistory(); const { data } = hooks[service.route].useList(); const actions = [ ...( service.actions?.map(action => ({ ...action, route: `/${service.route}/${action.route}`, })) || [] ), { name: 'Добавить', route: `/${service.route}/add` }, ]; const handleRowClick = (index: number) => { const item = data && data[index]; history.push(`/${service.route}/${item?._id}`); }; return ( ); }; export default ServiceList;