diff options
author | eug-vs <eug-vs@keemail.me> | 2021-03-16 01:38:54 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2021-03-16 01:38:54 +0300 |
commit | 49a44a5762a2863566267689002834ee88d06abb (patch) | |
tree | b471b6ace58355f8d08e024e7546bf57057fe8fb /src/containers/Service/ServiceForm.tsx | |
parent | 6a200e57d4a0be0532587b9648ff8d58f97e91e8 (diff) | |
download | commercel-ui-49a44a5762a2863566267689002834ee88d06abb.tar.gz |
feat: add WaybillPanel
Diffstat (limited to 'src/containers/Service/ServiceForm.tsx')
-rw-r--r-- | src/containers/Service/ServiceForm.tsx | 52 |
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; |