From 865b41114060765308d560181f4996c0aa7a3e74 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Fri, 26 Mar 2021 01:06:44 +0300
Subject: refactor: move Service to lib/

---
 src/lib/Service.tsx | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 src/lib/Service.tsx

(limited to 'src/lib/Service.tsx')

diff --git a/src/lib/Service.tsx b/src/lib/Service.tsx
new file mode 100644
index 0000000..b527531
--- /dev/null
+++ b/src/lib/Service.tsx
@@ -0,0 +1,25 @@
+import React, { useContext } from 'react';
+import { Route, Switch, useRouteMatch } from 'react-router-dom';
+import _ from 'lodash';
+import ServiceList from './ServiceList';
+import ServiceItem from './ServiceItem';
+import ServiceContext from './ServiceContext';
+
+
+const Service: React.FC = () => {
+  const { path } = useRouteMatch();
+  const service = useContext(ServiceContext);
+
+  return (
+    <Switch>
+      <Route exact path={path} component={ServiceList} />
+      <Route path={`${path}/add`} component={ServiceItem} />
+      {_.map(service.routes, (component, route) => (
+        <Route path={`${path}/${route}`} component={component} key={route} />
+      ))}
+      <Route path={`${path}/:id`} component={ServiceItem} />
+    </Switch>
+  );
+};
+
+export default Service;
-- 
cgit v1.2.3

