import React from 'react'; import { useParams, useHistory } from 'react-router-dom'; import { Formik, Form, Field } from 'formik'; import Page, { Action } from './Page'; import Input from '../components/Input'; import { useProduct } from '../hooks/useAPIClient'; import { post, patch } from '../requests'; interface Params { id: string; } const actions: Action[] = [ { name: 'Назад', variant: 'outlined', route: '..' }, { name: 'Сохранить', type: 'submit', form: 'productForm' }, ]; const ProductForm: React.FC = () => { const history = useHistory(); const { id } = useParams(); const { data: product } = useProduct(id); const onSubmit = (values: any) => { const promise = id ? patch(`/products/${id}`, values) : post('/products', values); return promise.then(() => history.push('/products')); }; return ( {(!id || product) && ( {() => (
)}
)}
); }; export default ProductForm;