2023-07-27 22:04:25 +03:00
|
|
|
import { useState } from 'react';
|
|
|
|
import { toast } from 'react-toastify';
|
|
|
|
|
|
|
|
import Checkbox from '../../components/Common/Checkbox';
|
|
|
|
import FileInput from '../../components/Common/FileInput';
|
|
|
|
import Modal from '../../components/Common/Modal';
|
|
|
|
import { useRSForm } from '../../context/RSFormContext';
|
|
|
|
import { IRSFormUploadData } from '../../utils/models';
|
|
|
|
|
2023-07-28 00:03:37 +03:00
|
|
|
interface DlgUploadRSFormProps {
|
2023-07-27 22:04:25 +03:00
|
|
|
hideWindow: () => void
|
|
|
|
}
|
|
|
|
|
2023-07-29 03:31:21 +03:00
|
|
|
function DlgUploadRSForm({ hideWindow }: DlgUploadRSFormProps) {
|
2023-07-27 22:04:25 +03:00
|
|
|
const { upload } = useRSForm();
|
|
|
|
const [loadMetadata, setLoadMetadata] = useState(false);
|
|
|
|
const [file, setFile] = useState<File | undefined>()
|
|
|
|
|
|
|
|
const handleSubmit = () => {
|
|
|
|
if (!file) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const data: IRSFormUploadData = {
|
|
|
|
load_metadata: loadMetadata,
|
|
|
|
file: file,
|
|
|
|
fileName: file.name
|
|
|
|
};
|
|
|
|
upload(data, () => toast.success('Схема загружена из файла'));
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleFile = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
if (event.target.files && event.target.files.length > 0) {
|
|
|
|
setFile(event.target.files[0]);
|
|
|
|
} else {
|
|
|
|
setFile(undefined)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
2023-07-31 22:38:58 +03:00
|
|
|
title='Импорт схемы из Экстеора'
|
2023-07-27 22:04:25 +03:00
|
|
|
hideWindow={hideWindow}
|
|
|
|
canSubmit={!!file}
|
|
|
|
onSubmit={handleSubmit}
|
2023-07-31 22:38:58 +03:00
|
|
|
submitText='Загрузить'
|
2023-07-27 22:04:25 +03:00
|
|
|
>
|
|
|
|
<div className='max-w-[20rem]'>
|
2023-07-31 22:38:58 +03:00
|
|
|
<FileInput
|
|
|
|
label='Выбрать файл'
|
|
|
|
acceptType='.trs'
|
|
|
|
onChange={handleFile}
|
|
|
|
/>
|
|
|
|
<Checkbox
|
|
|
|
label='Загружать название и комментарий'
|
2023-07-27 22:04:25 +03:00
|
|
|
value={loadMetadata}
|
|
|
|
onChange={event => { setLoadMetadata(event.target.checked); }}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</Modal>
|
2023-07-29 03:31:21 +03:00
|
|
|
);
|
2023-07-27 22:04:25 +03:00
|
|
|
}
|
|
|
|
|
2023-07-28 00:03:37 +03:00
|
|
|
export default DlgUploadRSForm;
|