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 */}
{file ? 파일 삭제 : 엑셀 업로드} {typeError === false ? (
업로드 미리보기 총 제재 인원 : 45 GUID 닉네임 유효성 체크 {guidList && guidList.map((data, idx) => ( {data.guid} {data.nickname} {data.validate === true ? true : false} ))}