reymesson1 / septimoejercicio

1 stars 0 forks source link

Dashboard Today report #71

Closed reymesson1 closed 5 years ago

reymesson1 commented 5 years ago
                            TodayReport
reymesson1 commented 5 years ago

class TodayReport extends React.Component{

    constructor() {

        super();
        this.state = {
            master: []
        }
    }

    componentDidMount(){

          fetch(API_URL+'/master',{headers: API_HEADERS})
          .then((response)=>response.json())
          .then((responseData)=>{

                  this.setState({

                      master: responseData
                  })

          })
          .catch((error)=>{
              console.log('Error fetching and parsing data', error);
          })

    }

    render(){

      var today = moment(new Date()).format('DD/MM/YYYY');      

      if(this.state.master[0]){
          var value = this.state.master[0].fechaentrega.split(' ')
          console.log(value[1]==today)
          //console.log(today)

      }

    let filteredTable = this.state.master.filter(
        (master) => master.fechaentrega.split(' ')[1] == today
    )

      return (

        <ul className="list-group">
             {filteredTable.map(

                (master, index) => <li className="list-group-item"><span className="badge">{master.fechaentrega}</span>{master.name}</li>
            )} 
        </ul>
      )
    }
}
reymesson1 commented 5 years ago

on birthday class

reymesson1 commented 5 years ago
    let newDate = event.target.fechaentrega.value;

    console.log(newDate.substring(0,4))
    console.log(newDate.substring(5,7))
    console.log(newDate.substring(8,10))

    let formatedDate = "* "+ newDate.substring(8,10) + "/" + newDate.substring(5,7) + "/" + newDate.substring(0,4)

    let newUpdate = {

        "index":index,
        "id":this.state.parameter,
        "fechaentrega": formatedDate
    }