2021-09-13 12:46:52 +05:30
|
|
|
import React, { useState, useEffect } from 'react';
|
2021-07-20 22:11:32 +05:30
|
|
|
import axios from 'axios';
|
|
|
|
|
import {
|
2021-07-30 19:12:28 +05:30
|
|
|
CCol,
|
|
|
|
|
CFormGroup,
|
|
|
|
|
CInput,
|
|
|
|
|
CInputFile,
|
|
|
|
|
CLabel,
|
|
|
|
|
CButton,
|
|
|
|
|
CCard,
|
|
|
|
|
CCardHeader,
|
|
|
|
|
CCardBody,
|
|
|
|
|
CCardFooter,
|
|
|
|
|
} from '@coreui/react'
|
2021-07-20 22:11:32 +05:30
|
|
|
import CIcon from '@coreui/icons-react'
|
|
|
|
|
|
|
|
|
|
|
2021-09-13 12:46:52 +05:30
|
|
|
function Uploader(props) {
|
2021-07-20 22:11:32 +05:30
|
|
|
|
2021-07-30 19:12:28 +05:30
|
|
|
const [file, setFile] = useState(null);
|
2021-09-13 12:46:52 +05:30
|
|
|
|
2021-07-30 19:12:28 +05:30
|
|
|
function onChangeHandler(e) {
|
|
|
|
|
setFile(e.target.files[0])
|
|
|
|
|
}
|
2021-07-20 22:11:32 +05:30
|
|
|
|
2021-07-30 19:12:28 +05:30
|
|
|
function onClickHandler(e) {
|
|
|
|
|
const data = new FormData()
|
2021-09-13 12:46:52 +05:30
|
|
|
data.append('email', props.email);
|
2021-09-13 15:13:15 +05:30
|
|
|
// data.append('file', file);
|
2021-09-02 14:42:12 +05:30
|
|
|
const chk = file.name.trim();
|
2021-09-02 15:25:24 +05:30
|
|
|
const collator = new Intl.Collator('ja');
|
|
|
|
|
const order1 = collator.compare('ini_工程内検査票.xlsx', chk);
|
|
|
|
|
const order2 = collator.compare('ini_データ入力シート.xlsx', chk);
|
|
|
|
|
if(order1 === 0 || order2 === 0)
|
2021-08-13 10:18:36 +05:30
|
|
|
{
|
|
|
|
|
axios.post("https://fsbsso.sumasen.net/upload", data, { // receive two parameter endpoint url ,form data
|
2021-07-30 19:12:28 +05:30
|
|
|
})
|
|
|
|
|
.then(res => { // then print response status
|
2021-08-02 15:50:55 +05:30
|
|
|
//console.log(res.statusText)
|
|
|
|
|
if (res.statusText == 'OK') {
|
|
|
|
|
alert("正常にアップロードされました");
|
|
|
|
|
}
|
2021-07-30 19:12:28 +05:30
|
|
|
});
|
2021-08-13 10:18:36 +05:30
|
|
|
}
|
|
|
|
|
else {
|
2021-08-13 11:04:47 +05:30
|
|
|
alert("指定されたファイル名" + file.name + "が間違っています。ini_工程内検査表.xlsx または ini_データ入力シート.xlsx のどちらかに名前を変更してください。");
|
2021-08-13 10:18:36 +05:30
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//console.log(file.name);
|
|
|
|
|
//console.log('calling upload');
|
|
|
|
|
|
2021-07-30 19:12:28 +05:30
|
|
|
}
|
2021-07-20 22:11:32 +05:30
|
|
|
|
2021-09-13 12:46:52 +05:30
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<CCard >
|
|
|
|
|
<CCardHeader>
|
|
|
|
|
アップロード
|
|
|
|
|
</CCardHeader>
|
|
|
|
|
<CCardBody >
|
|
|
|
|
<CFormGroup row>
|
|
|
|
|
<CCol md = "3">
|
|
|
|
|
<CLabel htmlFor = "date-input" > アップロードするファイルを選んでください < /CLabel>
|
|
|
|
|
</CCol >
|
|
|
|
|
<CCol xs = "12"md = "9" >
|
|
|
|
|
<CInputFile type = "file"onChange = { onChangeHandler } id = "file-input" name = "file-input" / >
|
|
|
|
|
</CCol>
|
|
|
|
|
</CFormGroup >
|
2021-08-09 11:42:23 +05:30
|
|
|
<CCardFooter >
|
|
|
|
|
<CButton type = "submit"
|
2021-07-30 19:12:28 +05:30
|
|
|
onClick = { onClickHandler }
|
|
|
|
|
size = "sm"
|
2021-09-13 12:46:52 +05:30
|
|
|
color = "primary" > < CIcon name = "cil-scrubber" / > アップロード </CButton>
|
|
|
|
|
</CCardFooter>
|
2021-08-09 11:42:23 +05:30
|
|
|
</CCardBody>
|
|
|
|
|
</CCard>
|
|
|
|
|
</div>
|
2021-07-30 19:12:28 +05:30
|
|
|
)
|
2021-07-20 22:11:32 +05:30
|
|
|
}
|
|
|
|
|
|
2021-08-02 15:50:55 +05:30
|
|
|
export default Uploader
|