summaryrefslogtreecommitdiff
path: root/src/containers/Service
diff options
context:
space:
mode:
Diffstat (limited to 'src/containers/Service')
-rw-r--r--src/containers/Service/Service.tsx6
-rw-r--r--src/containers/Service/ServiceContext.tsx5
-rw-r--r--src/containers/Service/ServiceItem.tsx (renamed from src/containers/Service/ServiceForm.tsx)25
-rw-r--r--src/containers/Service/ServiceList.tsx2
4 files changed, 25 insertions, 13 deletions
diff --git a/src/containers/Service/Service.tsx b/src/containers/Service/Service.tsx
index 3a7cbee..162fce0 100644
--- a/src/containers/Service/Service.tsx
+++ b/src/containers/Service/Service.tsx
@@ -1,7 +1,7 @@
import React from 'react';
import { Route, Switch, useRouteMatch } from 'react-router-dom';
import ServiceList from './ServiceList';
-import ServiceForm from './ServiceForm';
+import ServiceItem from './ServiceItem';
const Service: React.FC = () => {
@@ -10,8 +10,8 @@ const Service: React.FC = () => {
return (
<Switch>
<Route exact path={path} component={ServiceList} />
- <Route path={`${path}/add`} component={ServiceForm} />
- <Route path={`${path}/edit/:id`} component={ServiceForm} />
+ <Route path={`${path}/add`} component={ServiceItem} />
+ <Route path={`${path}/:id`} component={ServiceItem} />
</Switch>
);
};
diff --git a/src/containers/Service/ServiceContext.tsx b/src/containers/Service/ServiceContext.tsx
index c035417..b4200a0 100644
--- a/src/containers/Service/ServiceContext.tsx
+++ b/src/containers/Service/ServiceContext.tsx
@@ -1,6 +1,10 @@
import React from 'react';
import { FormikProps } from 'formik';
+export interface PanelProps {
+ item: any;
+}
+
export interface ServiceParams {
route: string;
name: string;
@@ -8,6 +12,7 @@ export interface ServiceParams {
tableFields: any[];
default: Record<string, any>;
Form?: React.FC<FormikProps>;
+ Panel?: React.FC<PanelProps>;
}
const ServiceContext = React.createContext<ServiceParams>({
diff --git a/src/containers/Service/ServiceForm.tsx b/src/containers/Service/ServiceItem.tsx
index 0c02cbd..bd449f9 100644
--- a/src/containers/Service/ServiceForm.tsx
+++ b/src/containers/Service/ServiceItem.tsx
@@ -11,7 +11,7 @@ interface Params {
id: string;
}
-const ServiceForm: React.FC = () => {
+const ServiceItem: React.FC = () => {
const service = useContext(ServiceContext);
const history = useHistory();
const { id } = useParams<Params>();
@@ -31,22 +31,29 @@ const ServiceForm: React.FC = () => {
};
const actions: Action[] = [
- { name: 'Назад', variant: 'outlined', route: '..' },
+ { name: 'Назад', variant: 'outlined', onClick: history.goBack },
{ name: 'Удалить', variant: 'outlined', onClick: handleDelete },
{ name: 'Сохранить', type: 'submit', form: 'form' },
];
return (
- <Page title={id ? item?.name : `Новый ${service.nameSingular}`} actions={actions}>
+ <Page
+ title={id ? item?.name : `Новый ${service.nameSingular}`}
+ actions={actions}
+ className="flex"
+ >
{(!id || item) && (
- <Formik
- initialValues={_.defaults(item, service.default)}
- onSubmit={onSubmit}
- children={service.Form}
- />
+ <div className="w-1/3">
+ <Formik
+ initialValues={_.defaults(item, service.default)}
+ onSubmit={onSubmit}
+ children={service.Form}
+ />
+ </div>
)}
+ {item && service.Panel && <service.Panel item={item} />}
</Page>
);
};
-export default ServiceForm;
+export default ServiceItem;
diff --git a/src/containers/Service/ServiceList.tsx b/src/containers/Service/ServiceList.tsx
index 6af2d1b..b7054eb 100644
--- a/src/containers/Service/ServiceList.tsx
+++ b/src/containers/Service/ServiceList.tsx
@@ -15,7 +15,7 @@ const ServiceList: React.FC = () => {
const handleRowClick = (index: number) => {
const item = data && data[index];
- history.push(`/${service.route}/edit/${item?._id}`);
+ history.push(`/${service.route}/${item?._id}`);
};
return (