summaryrefslogtreecommitdiff
path: root/src/containers/Service/ServiceForm.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/containers/Service/ServiceForm.tsx')
-rw-r--r--src/containers/Service/ServiceForm.tsx52
1 files changed, 0 insertions, 52 deletions
diff --git a/src/containers/Service/ServiceForm.tsx b/src/containers/Service/ServiceForm.tsx
deleted file mode 100644
index 0c02cbd..0000000
--- a/src/containers/Service/ServiceForm.tsx
+++ /dev/null
@@ -1,52 +0,0 @@
-import React, { useContext } from 'react';
-import { useParams, useHistory } from 'react-router-dom';
-import { Formik } from 'formik';
-import _ from 'lodash';
-import Page, { Action } from '../Page';
-import hooks from '../../hooks/useAPIClient';
-import { post, patch, del } from '../../requests';
-import ServiceContext from './ServiceContext';
-
-interface Params {
- id: string;
-}
-
-const ServiceForm: React.FC = () => {
- const service = useContext(ServiceContext);
- const history = useHistory();
- const { id } = useParams<Params>();
- const { data: item, mutate } = hooks[service.route].useItem(id);
-
- const handleDelete = () => del(`/${service.route}/${id}`)
- .then(() => history.push(`/${service.route}`));
-
- const onSubmit = (values: any) => {
- const promise = id
- ? patch(`/${service.route}/${id}`, values)
- : post(`/${service.route}`, values);
- return promise.then(response => {
- mutate(response.data);
- history.push(`/${service.route}`);
- });
- };
-
- const actions: Action[] = [
- { name: 'Назад', variant: 'outlined', route: '..' },
- { name: 'Удалить', variant: 'outlined', onClick: handleDelete },
- { name: 'Сохранить', type: 'submit', form: 'form' },
- ];
-
- return (
- <Page title={id ? item?.name : `Новый ${service.nameSingular}`} actions={actions}>
- {(!id || item) && (
- <Formik
- initialValues={_.defaults(item, service.default)}
- onSubmit={onSubmit}
- children={service.Form}
- />
- )}
- </Page>
- );
-};
-
-export default ServiceForm;