import { format } from 'date-fns'; import React, { useEffect, useState, useContext } from 'react'; import styled from 'styled-components/macro'; import { axiosInstance } from '../utils/axiosInstance'; import { useSnackbar } from 'notistack'; import CloseIcon from '@material-ui/icons/Close'; import { SyncLoader } from 'react-spinners'; import { CASContext } from '../contexts/CASProvider'; import LogoutIcon from '../assets/logout.svg'; import LogoPlanNaPlan from '../assets/logo.svg'; const StyledCloseIcon = styled(CloseIcon)` color: #000000; &:hover { color: white; cursor: pointer; } `; const Icon = styled.img` width: 40px; margin-left: 40px; cursor: pointer; @media only screen and (max-width: 670px) { width: 35px; } position:absolute; top:10px; right:10px; `; const SaveButton = styled.button` display: flex; justify-content: center; align-items: center; user-select: none; background-color: #c7a424; border: none; font-weight: bold; cursor: pointer; height: 40px; margin:10px; &:hover { color: #ffffff; box-shadow: 0px 5px 4px 0px rgba(0, 0, 0, 0.24); } width: 150px; `; const AdministratorWrapper = styled.div` display: flex; flex-direction: column; margin: 0 auto; height: 100vh; `; const Wrap = styled.div` display: flex; flex: 1; flex-direction: column; justify-content: center; align-items: center; margin:20px; `; const LogoWrapper = styled.div` display: flex; flex-direction: column; justify-content: center; align-items: center; margin-top:-50px; `; const Text = styled.div` font-family: 'Roboto', sans-serif; font-size: 5rem; user-select: none; margin-bottom:60px; `; const Logo = styled.img` width: 400px; height: 400px; `; const Form = styled.form` flex: 1; display: flex; justify-content: center; align-items: center; flex-direction: column; input { padding: 5px; margin-top: 10px; margin-bottom: 10px; width: 210px; } `; const DownloadSection = styled.div` flex: 1; display: flex; justify-content: center; align-items: center; flex-direction: column; input { padding: 5px; margin-top: 10px; margin-bottom: 10px; width: 210px; } `; export const Administrator = () => { const { logout } = useContext(CASContext)!; const { enqueueSnackbar } = useSnackbar(); const { closeSnackbar } = useSnackbar(); const today = new Date(); const dd = String(today.getDate()).padStart(2, '0'); const mm = String(today.getMonth() + 1).padStart(2, '0'); const yyyy = today.getFullYear(); const date = yyyy + '-' + mm + '-' + dd; const [selectedFile, setSelectedFile] = useState(null); const [startFirstDate, setStartFirstDate] = useState(null); const [endFirstDate, setEndFirstDate] = useState(null); const [startSecondDate, setStartSecondDate] = useState(null); const [endSecondDate, setEndSecondDate] = useState(null); const [loading, setLoading] = useState(false); const downloadFile = async () => { const {data} = await axiosInstance.get(`${process.env.REACT_APP_API_URL}/api/v1/commisions/export/csv`,{responseType:"blob"}); const downloadUrl = window.URL.createObjectURL(new Blob([data])); const link = document.createElement('a'); link.href = downloadUrl; link.setAttribute('download', 'file.csv'); document.body.appendChild(link); link.click(); link.remove(); }; const uploadFile = async (event: React.FormEvent) => { const action = (key: any) => ( <> { closeSnackbar(key); }} > ); event.preventDefault(); const formData = new FormData(); formData.append('file', selectedFile as Blob); if (startFirstDate !== null) { formData.append('firstTourBegin', format(startFirstDate, 'dd.MM.yyyy')); } if (endFirstDate !== null) { formData.append('firstTourEnd', format(endFirstDate, 'dd.MM.yyyy')); } if (startSecondDate !== null) { formData.append('secondTourBegin', format(startSecondDate, 'dd.MM.yyyy')); } if (endSecondDate !== null) { formData.append('secondTourEnd', format(endSecondDate, 'dd.MM.yyyy')); } const config = { headers: { 'content-type': 'multipart/form-data', }, }; try { setLoading(true); const response = await axiosInstance.post( `${process.env.REACT_APP_API_URL}/api/v1/configurator/config/`, formData, config, ); enqueueSnackbar('Ustawienia zostały zapisane', { variant: 'success', action, }); } catch (e) { enqueueSnackbar('Ustawienia nie zostały zapisane', { variant: 'error', action, }); console.log(e); } setLoading(false); }; const xd = true; return ( plan na plan {xd === true ? (
Start pierwszej tury:
{' '}
setStartFirstDate(e.target.valueAsDate)} />
Koniec pierwszej tury:
{' '}
setEndFirstDate(e.target.valueAsDate)} />
Start drugiej tury:
{' '}
setStartSecondDate(e.target.valueAsDate)} />
Koniec drugiej tury:
{' '}
setEndSecondDate(e.target.valueAsDate)} />
{ if (e.target.files && e.target.files[0]) { const file = e.target.files[0]; setSelectedFile(file); } }} />
{loading === false ? 'Zapisz' : }
Pobierz dane.csv
) : (
)}
); };