summaryrefslogtreecommitdiff
path: root/src/containers/Service/Service.tsx
blob: b527531b7b4e11a203d9458ff5e342dbc780baf2 (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
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;