import React from 'react'; import {connect} from "react-redux"; import { setAppointmentSpec, setAppointmentShedule, setAppointmentDoctor, clearAppointment, setAppointmentTime, setAppointmentComment, postOrders } from "../actions/actions"; export class Appoint extends React.Component { componentDidMount() { console.log(this.props) this.props.setAppointmentDoctor(this.props.match.params.doctorId) } componentWillUnmount() { this.props.clearAppointment() } render() { const {doctors, appointment, timeArray, wrongDate,services} = this.props.app; const {match, setAppointmentSpec, setAppointmentShedule, setAppointmentTime, setAppointmentComment, postOrders} = this.props; const doctor = doctors.find(el => el._id === match.params.doctorId); let spec; if (appointment.spec){ spec = services.find(el => el._id === appointment.spec) } let currentDate; let choosedData; if (doctor) { if (doctor.shedule && appointment.shedule) { currentDate = new Date().toISOString().split('T')[0]; choosedData = doctor.shedule.find(el => el._id === appointment.shedule).data.split('T')[0]; } } return ( <> {doctor &&

{doctor.name}

{doctor.profession}

Опыт работы {new Date().toISOString().split('T')[0].split('-')[0] - doctor.experience.split('T')[0].split('-')[0]} лет

{doctor.skillsDescription}

{appointment.spec &&

{spec.name}

Duration:{spec.duration}h

{spec.description}

Price: {spec.price} грн.

} {appointment.spec && setAppointmentShedule(doctor.shedule.find(el => new Date(el.data).toISOString().split('T')[0] === new Date(e.target.value).toISOString().split('T')[0]) ? doctor.shedule.find(el => new Date(el.data).toISOString().split('T')[0] === new Date(e.target.value).toISOString().split('T')[0])._id : null )} /> } {!appointment.shedule ? !wrongDate ?

There is no available time to choose on this date

: null :
{ choosedData >= currentDate ?
:

Choose current or future date

}
} {appointment.time &&
setAppointmentComment(e.target.value)}/>
}
} ); } } const mapStateToProps = state => { return { app:state.app, } }; const mapDispatchToProps = { setAppointmentSpec, setAppointmentShedule, setAppointmentDoctor, clearAppointment, setAppointmentTime, setAppointmentComment, postOrders }; export default connect (mapStateToProps,mapDispatchToProps)(Appoint)