ensalamento.jsx 6.67 KB
Newer Older
1
import React, { useState } from 'react';
Matheus Horstmann's avatar
Matheus Horstmann committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
import TextField from '@material-ui/core/TextField';
import Typography from '@material-ui/core/Typography';
import Grid from '@material-ui/core/Grid';
import { makeStyles } from '@material-ui/core/styles';
import Button from '@material-ui/core/Button';


function gera_ensalamento(file_name,file,date_init,date_end) {
    console.log("--------------------------------");
    console.log(file_name);
    console.log(file);
    console.log(date_init);
    console.log(date_end);
    console.log("--------------------------------");
}


const useStyles = makeStyles(theme => ({
    container: {
        display: 'grid',
        gridTemplateColumns: 'repeat(12, 1fr)',
        gridGap: theme.spacing(3),
    },
    button: {
        backgroundColor: "#ADD68B",
        width: "190px",
        height: "45px",
        textAlign: 'left',
       fontFamily: 'Open Sans,SemiBold',
        color: "#FFFFFF"
    },
    buttonsend: {
        color: "#ADD68B",
       fontFamily: 'Open Sans,SemiBold',
    },
    buttoncancel: {
        color: "red",
       fontFamily: 'Open Sans,SemiBold',
    },
    input: {
        display: 'none',
    },
    textField: {
        marginLeft: theme.spacing(1),
        marginRight: theme.spacing(1),
        width: 200,
    },
}));

export function UploadScreen(props) {
    var [highlight, setHighligt] = useState(false);
    var highlight_color = (highlight)? "#CECECE" : "#F6F6F6";
    const styles = { backgroundColor: highlight_color,border: " 2px solid #CECECE", height: '220px', width: '375px'  }
    const styles_info = { backgroundColor: '#F6F6F6',border: " 2px solid #CECECE", height: '270px', width: '405px'  }
    const classes = useStyles();
    var [fileuploded, setFileUploded] = useState(false);
    var [file, setFile] = useState(null);
    var [file_name, setFileName] = useState("");
    //  process user input when user puts a file.
    function onFilesAdded(evt) {
        setFile(file = evt.target.files[0]);
        setFileName(file_name=file.name);
        setFileUploded(fileuploded = true);
    };
    // function when user drop file in input area
    function onDrop(event) {
        event.preventDefault()
        setFile(file = event.dataTransfer.files[0]);
        setFileName(file_name=file.name);
        setFileUploded(fileuploded = true);
        setHighligt(highlight = false);
    };
    function onDragLeave() {
        setHighligt(highlight = false);
    }
    function onDragOver(event) {
        event.preventDefault()
        setHighligt(highlight = true);
    }
    const upload_screen = (
        <div style={styles}
        onDragOver={onDragOver}
        onDragLeave={onDragLeave}
        onDrop={onDrop}
        >
                <Grid container
                    spacing={1} alignItems="center" justify="center" direction="row-reverse">
                <Grid item xs={8}>
                    <br></br>
                    </Grid>
                <Grid item xs={8}>
                        <i class="material-icons" style={{color:"#ADD68B",fontSize:"65.56px"}}>backup</i>
                    </Grid>
                    <Grid item xs={8}>
                        <div>
                            <input
                                ref={ React.createRef()}
                                className={classes.input}
                                id="outlined-button-file"
                                type="file"
                                onChange={onFilesAdded}
                            />
                            <label htmlFor="outlined-button-file">
                                <Button component="span" className={classes.button}>ESCOLHER ARQUIVO </Button>
                            </label>
                        </div>
                    </Grid>
                    <Grid item xs={8}>
110
                        <Typography  style={{color:"#606060",fontSize:"16px"}}>
Matheus Horstmann's avatar
Matheus Horstmann committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
                            Ou arraste e solte aqui
                        </Typography>
                    </Grid>
                </Grid>
            </div>
    );
    const today = new Date();
    var _date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
    var [date_init, setDateInit] = useState(_date);
    var [date_end, setDateEnd] = useState(_date);
    const upload_form = (
        <div style={styles_info}>
            <Grid container spacing={1} alignItems="center" justify="center" direction="row">
                <Grid item xs={8}><br></br></Grid>
                <form className={{display: 'flex', flexWrap: 'wrap'}} noValidate>
                    <Grid item xs={8}>
                        <TextField
                            id="date"
                            label="Início período letivo"
                            type="date"
                            defaultValue={_date}
                            className={classes.textField}
                            InputLabelProps={{ shrink: true, }} />
134
                     </Grid>
Matheus Horstmann's avatar
Matheus Horstmann committed
135 136 137 138 139 140 141 142 143 144
                <Grid item xs={8}><br></br></Grid>
                    <Grid item xs={8}>
                        <TextField
                            id="date"
                            label="Fim período letivo"
                            type="date"
                            defaultValue={_date}
                            onChange = {(evt) => setDateEnd(date_end = evt.target.value)}
                            className={classes.textField}
                            InputLabelProps={{ shrink: true, }} />
145
                     </Grid>
Matheus Horstmann's avatar
Matheus Horstmann committed
146 147
                <Grid item xs={8}><br></br></Grid>
                     <Grid item xs={8}>
148
                         <Typography  style={{color:"#606060",fontSize:"14px"}}>{file_name}</Typography>
Matheus Horstmann's avatar
Matheus Horstmann committed
149 150 151 152 153 154 155 156 157 158 159
                     </Grid>
                </form>
                <Grid item xs={8}><br></br></Grid>
                    <Grid item xs={8}>
                        <Button className={classes.buttoncancel} onClick={()=>setFileUploded(fileuploded=false)}>
                            Voltar
                        </Button>
                            <Button className={classes.buttonsend} onChange = {(evt) => setDateInit(date_init = evt.target.value)}
                                onClick={()=>gera_ensalamento(file_name,file,date_init,date_end)}>
                            Gerar ensalamento
                        </Button>
160
                     </Grid>
Matheus Horstmann's avatar
Matheus Horstmann committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181

            </Grid>
        </div>
    )
    return (fileuploded)? upload_form : upload_screen;
}
export function Upload(props) {
    return (
        <Grid
            container
            spacing={10}
            direction="column"
            alignItems="center"
            justify="center"
            style={{minHeight: '100vh'}}
        >
                <UploadScreen></UploadScreen>
        </Grid>

    );
}