blob: b7054eb955f2425085b9d94a4f51149d60e49617 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
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 = [{ name: 'Добавить', route: `/${service.route}/add` }];
const handleRowClick = (index: number) => {
const item = data && data[index];
history.push(`/${service.route}/${item?._id}`);
};
return (
<Page title={service.name} actions={actions}>
<ListTable items={data} fields={service.tableFields} handleRowClick={handleRowClick} />
</Page>
);
};
export default ServiceList;
|