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