Skip to content
Snippets Groups Projects
Select Git revision
  • 19ef6c19e1ad01f1d575f88365909f101100f2d6
  • master default
  • dockerization
  • staging
  • backup-before-cleaning-repo
  • dockerfiles-pour-maelle
6 results

SubmitForm.js

Blame
  • Forked from an inaccessible project.
    user avatar
    Thomas Bouquet authored
    19ef6c19
    History
    SubmitForm.js 2.52 KiB
    import React, { useState, useEffect } from "react";
    import { MDBRow, MDBCol, MDBInput, MDBBtn, MDBCard, MDBCardBody, MDBModalFooter, MDBIcon, MDBContainer } from 'mdbreact';
    import axios from 'axios';
    import eventData from "../../eventData/eventData.json";
    
    function Submit(props) {
    
        /*var [participants,setParticipants] = useState([]);
            useEffect(() => {
                const interval = setInterval(() => {
                axios.get('/api/participants_by_id',{
                    id: props.participant.value
                }).then((response) => setParticipants(response.data));
                }, 500);
            return () => clearInterval(interval);
            }, []);*/
    
    
        function addScore() {
    
            /*if (participants[0] === undefined) {
                axios.post('/api/staff/new_participant_with_id',
            {
                id: props.participant.value,
                name: props.participant.label
            })
            }*/
    
            if (Date.now() < 0) {
    
            axios.post('/api/staff/new_score',
                {
                    score: Math.max(0, props.score),
                    equipe: props.equipe.value,
                    participant: props.participant.value
                })
                .then(() => {
                    axios.post('/api/staff/new_participant_with_id',
                        {
                            id: props.participant.value,
                            name: props.participant.label
                        })
                })
                .then(() => {
                    alert("Score ajouté");
                    window.location = '/Input';
                }, (error) => {
                    console.log(error);
                })
    
            }
    
            else {
                axios.post('/api/staff/new_score',
                {
                    score: Math.max(0, props.score),
                    equipe: props.equipe.value,
                    participant: "sprint"
                })
                .then(() => {
                    axios.post('/api/staff/new_participant_with_id',
                        {
                            id: "sprint",
                            name: "Sprint"
                        })
                })
                .then(() => {
                    alert("Score ajouté");
                    window.location = '/Input';
                }, (error) => {
                    console.log(error);
                })
            }
        };
    
    
    
    
    
    
    
    
        const onSubmit = () => { addScore() };
    
        return (
            <MDBBtn type="submit" icon="send" gradient="blue" rounded disabled={props.unlock} className="btn-block z-depth-1a" onClick={onSubmit}><MDBIcon icon="paper-plane" className="ml-1" /> Envoyer</MDBBtn>
        )
    }
    
    export default Submit;