diff options
Diffstat (limited to 'src/containers')
| -rw-r--r-- | src/containers/TransfersUpload.tsx | 42 | ||||
| -rw-r--r-- | src/containers/WaybillForm.tsx | 2 | 
2 files changed, 43 insertions, 1 deletions
| diff --git a/src/containers/TransfersUpload.tsx b/src/containers/TransfersUpload.tsx new file mode 100644 index 0000000..8239ab9 --- /dev/null +++ b/src/containers/TransfersUpload.tsx @@ -0,0 +1,42 @@ +import React from 'react'; +import { useHistory } from 'react-router-dom'; +import { Form, Formik } from 'formik'; +import Button from '../components/Button'; +import Input from '../components/Input'; +import Page, { Action } from './Page'; +import { post } from '../requests'; + +const TransfersUpload: React.FC = () => { +  const history = useHistory(); + +  const handleSubmitFile = () => { +    const reader = new FileReader(); +    const file = document.getElementById('file').files[0]; +    reader.readAsDataURL(file); +    reader.onload = (e: any) => { +      const uri = e.target.result; +      post('/uploads', { uri }) +        .then(() => history.push('/transfers')); +    }; +  }; + +  const actions: Action[] = [ +    { name: 'Назад', variant: 'outlined', onClick: history.goBack }, +    { name: 'Загрузить', type: 'submit', form: 'form' }, +  ]; + +  return ( +    <Page +      title="Загрузить выписку" +      actions={actions} +    > +      <Formik onSubmit={handleSubmitFile} initialValues={{}}> +        <Form id="form"> +          <Input name="file" type="file" accept=".pdf" label="Прикрепите файл" id="file" /> +        </Form> +      </Formik> +    </Page> +  ); +}; + +export default TransfersUpload; diff --git a/src/containers/WaybillForm.tsx b/src/containers/WaybillForm.tsx index a6a37e2..5fcdb7d 100644 --- a/src/containers/WaybillForm.tsx +++ b/src/containers/WaybillForm.tsx @@ -17,7 +17,7 @@ const WaybillForm: React.FC<FormikProps> = ({ setFieldValue, values }) => {    const { data: contractors } = hooks.contractors.useList();    if (!values.date) setFieldValue('date', moment().format('YYYY-MM-DD')); -  if (!values.contractorId && contractors) setFieldValue('contractorId', contractors[0]._id); +  if (!values.contractorId && contractors?.length) setFieldValue('contractorId', contractors[0]._id);    const handleAddRecord = () => setFieldValue('records', [...values.records, {      productId: _.map(products, '_id').reduce((acc, id) => { | 
