import styled, { css } from 'styled-components'; import { useForm } from 'react-hook-form'; import { useState, useEffect, Fragment } from 'react'; import Button from '../common/button/Button'; import Modal from '../common/modal/Modal'; import { Title, BtnWrapper, InputGroup, TableStyle, AlertText } from '../../styles/Components'; import { BlackListExcelDown, BlackListMultipleUpload } from '../../apis'; const UserBlockUploadBtn = ({ disabled, setGuidList, guidList, typeError, setTypeError }) => { const token = sessionStorage.getItem('token'); // onchange states const [file, setFile] = useState(null); const [previewModal, setPreviewModal] = useState('hidden'); const handlePreview = e => { e.preventDefault(); if (previewModal === 'hidden') { setPreviewModal('view'); } else if (previewModal === 'view') { setPreviewModal('hidden'); } }; // onchange event const handleFile = async e => { let fileTypes = ['application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'text/csv']; setFile(e.target.files[0]); setGuidList(await BlackListMultipleUpload(token, e.target.files[0])); }; const handleFileDelete = e => { e.preventDefault(); document.querySelector('#fileinput').value = ''; setGuidList([]); setTypeError(true); setFile(null); }; useEffect(() => { if (typeof guidList === 'undefined') { setTypeError(true); } else if (typeof guidList !== 'undefined') { if (guidList.length > 0) { setTypeError(false); } } }); const handleDownloadExcel = async () => { const token = sessionStorage.getItem('token'); await BlackListExcelDown(token, 'block_sample.xlsx'); }; return ( <> {/* form */}