diff options
Diffstat (limited to 'src/containers/Service')
-rw-r--r-- | src/containers/Service/Service.tsx | 8 | ||||
-rw-r--r-- | src/containers/Service/ServiceContext.tsx | 3 | ||||
-rw-r--r-- | src/containers/Service/ServiceList.tsx | 10 |
3 files changed, 19 insertions, 2 deletions
diff --git a/src/containers/Service/Service.tsx b/src/containers/Service/Service.tsx index 162fce0..b527531 100644 --- a/src/containers/Service/Service.tsx +++ b/src/containers/Service/Service.tsx @@ -1,16 +1,22 @@ -import React from 'react'; +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> ); diff --git a/src/containers/Service/ServiceContext.tsx b/src/containers/Service/ServiceContext.tsx index f9e1605..68ff907 100644 --- a/src/containers/Service/ServiceContext.tsx +++ b/src/containers/Service/ServiceContext.tsx @@ -6,12 +6,15 @@ export interface PanelProps { mutate: (item: any) => void; } +type Route = Record<string, React.FC>; + export interface ServiceParams { route: string; name: string; nameSingular: string; tableFields: any[]; default: Record<string, any>; + routes?: Route[]; Form?: React.FC<FormikProps>; Panel?: React.FC<PanelProps>; } diff --git a/src/containers/Service/ServiceList.tsx b/src/containers/Service/ServiceList.tsx index b7054eb..7d30c14 100644 --- a/src/containers/Service/ServiceList.tsx +++ b/src/containers/Service/ServiceList.tsx @@ -11,7 +11,15 @@ const ServiceList: React.FC = () => { const history = useHistory(); const { data } = hooks[service.route].useList(); - const actions = [{ name: 'Добавить', route: `/${service.route}/add` }]; + const actions = [ + ...( + service.actions?.map(action => ({ + ...action, + route: `/${service.route}/${action.route}`, + })) || [] + ), + { name: 'Добавить', route: `/${service.route}/add` }, + ]; const handleRowClick = (index: number) => { const item = data && data[index]; |