summaryrefslogtreecommitdiff
path: root/src/containers/Service/ServiceList.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/containers/Service/ServiceList.tsx')
-rw-r--r--src/containers/Service/ServiceList.tsx28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/containers/Service/ServiceList.tsx b/src/containers/Service/ServiceList.tsx
new file mode 100644
index 0000000..6af2d1b
--- /dev/null
+++ b/src/containers/Service/ServiceList.tsx
@@ -0,0 +1,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}/edit/${item?._id}`);
+ };
+
+ return (
+ <Page title={service.name} actions={actions}>
+ <ListTable items={data} fields={service.tableFields} handleRowClick={handleRowClick} />
+ </Page>
+ );
+};
+
+export default ServiceList;