summaryrefslogtreecommitdiff
path: root/src/lib/ServiceList.tsx
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2021-03-26 01:06:44 +0300
committereug-vs <eug-vs@keemail.me>2021-03-26 01:06:44 +0300
commit865b41114060765308d560181f4996c0aa7a3e74 (patch)
tree578d3089e05131445b0a8b6d5e69a3a76aaf7e73 /src/lib/ServiceList.tsx
parent91e1a3b4ccaa822097e4adfea5f51056b010fdd6 (diff)
downloadcommercel-ui-865b41114060765308d560181f4996c0aa7a3e74.tar.gz
refactor: move Service to lib/
Diffstat (limited to 'src/lib/ServiceList.tsx')
-rw-r--r--src/lib/ServiceList.tsx35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/lib/ServiceList.tsx b/src/lib/ServiceList.tsx
new file mode 100644
index 0000000..74ad10b
--- /dev/null
+++ b/src/lib/ServiceList.tsx
@@ -0,0 +1,35 @@
+import React, { useContext } from 'react';
+import { useHistory, useLocation } from 'react-router-dom';
+import Page from '../containers/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 location = useLocation();
+ const { data } = hooks[service.route].useList(location.search);
+
+ const actions = service.actions || [{
+ name: 'Добавить',
+ route: `/${service.route}/add${location.search}`,
+ }];
+
+ const handleRowClick = (index: number) => {
+ const item = data && data[index];
+ const route = service.rowLink
+ ? service.rowLink(item)
+ : `/${service.route}/${item?._id}`;
+
+ history.push(route);
+ };
+
+ return (
+ <Page title={service.name} actions={actions}>
+ <ListTable items={data} fields={service.tableFields} handleRowClick={handleRowClick} />
+ </Page>
+ );
+};
+
+export default ServiceList;