From b8f8c8be992ba7eeaaa459fb0d468f7513e46f87 Mon Sep 17 00:00:00 2001 From: KharchenkoVV Date: Tue, 27 Jul 2021 13:39:20 +0500 Subject: [PATCH] =?UTF-8?q?CF2-38:=20=D0=A4=D0=BE=D1=80=D0=BC=D0=B0=20?= =?UTF-8?q?=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=BA=D1=83=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=20=D0=B2=D1=8B=D0=BD?= =?UTF-8?q?=D0=B5=D1=81=D0=B5=D0=BD=D0=B0=20=D0=B2=20=D0=BC=D0=BE=D0=B4?= =?UTF-8?q?=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=D0=B5=20=D0=BE=D0=BA=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Documents.jsx | 105 ++++++----------- .../modalWindows/DocumentCreationForm.jsx | 108 ++++++++++++++++++ 2 files changed, 140 insertions(+), 73 deletions(-) create mode 100644 src/components/modalWindows/DocumentCreationForm.jsx diff --git a/src/components/Documents.jsx b/src/components/Documents.jsx index b7cb274..4291b62 100644 --- a/src/components/Documents.jsx +++ b/src/components/Documents.jsx @@ -1,6 +1,7 @@ -import {Table, DatePicker, Form, Button, Upload, ConfigProvider} from 'antd' +import {Table, DatePicker, Button, Modal, ConfigProvider} from 'antd' import { UploadOutlined } from '@ant-design/icons' import MenuDocuments from "./MenuDocuments" +import DocumentCreationForm from './modalWindows/DocumentCreationForm' import { FileService } from '../services/api' import {useState, useEffect} from "react" import {useParams} from 'react-router-dom' @@ -20,11 +21,10 @@ export default function Documents({selectedFileCategory}) { const [range, setRange] = useState([]) const [pagination, setPagination] = useState(null) const [files, setFiles] = useState([]) - const [selectedFiles, setSelectedFiles] = useState([]) + const [isModalVisible, setIsModalVisible] = useState(false) const [isTableUpdating, setTableUpdating] = useState(false) const [loader, setLoader] = useState(false) - const [form] = Form.useForm(); const handleFileNameCLick = async (event, row) => { const element = event.target @@ -77,57 +77,18 @@ export default function Documents({selectedFileCategory}) { } ]; - const submitFileFormProps = { - progress: { - strokeColor: { - '0%': '#108ee9', - '100%': '#87d068', - }, - strokeWidth: 3, - format: percent => `${parseFloat(percent.toFixed(2))}%`, - }, - onChange({ file, fileList }) { - if (file.status !== 'uploading') { - setSelectedFiles(fileList) - } - } + const openModal = () => { + setIsModalVisible(true) + } + + const closeModal = () => { + setIsModalVisible(false) } const onChangeRange = (range) => { setRange(range) } - const onFinish = (values, form) => { - var fileList = values.fileInput.fileList - - if (fileList.length > 0) - { - setLoader(true) - const formData = new FormData(); - - fileList.forEach(val => { - formData.append('files', val.originFileObj) - }) - - fetch(`/api/files/${id}/files?idCategory=${selectedFileCategory}&idUser=${localStorage['userId']}`, { - headers: { - Authorization: 'Bearer ' + localStorage['token'] - }, - method: 'POST', - body: formData - }) - .then(async (response) => { - setLoader(false) - form.resetFields() - setTableUpdating(true) - }); - } - } - - const onFinishFailed = (errorInfo) => { - notify(`Не удалось отправить файлы по скважине "${id}".`, 'error') - } - useEffect(() => { const GetDocuments = async () => { setLoader(true) @@ -171,7 +132,7 @@ export default function Documents({selectedFileCategory}) { } } GetDocuments() - }, [id, range,page, selectedFileCategory, isTableUpdating]) + }, [id, range, page, selectedFileCategory, isTableUpdating]) return (
@@ -187,31 +148,29 @@ export default function Documents({selectedFileCategory}) {
 
-
onFinish(values, form)} - onFinishFailed={onFinishFailed} - style={{width: '300px'}} + + + - - - - - - - - - +
+ { + setIsModalVisible(false) + setTableUpdating(true) + }}> + +
+
 
{ + form + .validateFields() + .then(values => { + var fileList = values.documentFile.fileList + + if (fileList.length > 0) { + const formData = new FormData(); + + fileList.forEach(val => { + formData.append('files', val.originFileObj) + }) + + fetch(`/api/files/${id}/files?idCategory=${selectedFileCategory}&idUser=${localStorage['userId']}`, { + headers: { + Authorization: 'Bearer ' + localStorage['token'] + }, + method: 'POST', + body: formData + }) + + form.resetFields(); + closeModalHandler() + } + }).catch(info => { + console.log('Validate Failed:', info); + }); + } + + const submitFileFormProps = { + progress: { + strokeColor: { + '0%': '#108ee9', + '100%': '#87d068', + }, + strokeWidth: 3, + format: percent => `${parseFloat(percent.toFixed(2))}%`, + }, + multiple: true, + onChange({ file, fileList }) { + if (file.status !== 'uploading') { + setSelectedFiles(fileList) + } + } + } + + return ( + onFinish(form)} + > + + +

+ +

+

Кликните или перенесите сюда файлы

+

+ Возможна загрузка как одного файла, так и нескольких. +

+
+
+ +
+ + + +
+
+ + ) +} \ No newline at end of file