From 2c106d1d3f6d59b10ad946e01e8bb3d0df587e40 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Sun, 14 Mar 2021 10:10:16 +0300
Subject: refactor: create Service abstraction

---
 src/containers/Service/ServiceList.tsx | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 src/containers/Service/ServiceList.tsx

(limited to 'src/containers/Service/ServiceList.tsx')

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;
-- 
cgit v1.2.3

