Shedule.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import React from 'react';
  2. import moment from "moment";
  3. import { CustomSelect } from "../hooks/select"
  4. import Calendar from "../Calendar";
  5. export default class Shedule extends React.Component {
  6. state ={
  7. startDate:null,
  8. endDate:null,
  9. };
  10. post = (e) => {
  11. e.preventDefault();
  12. let current = new Date(this.state.startDate);
  13. let end = new Date (this.state.endDate);
  14. while (current.toISOString().split('T')[0] <= end.toISOString().split('T')[0]){
  15. if (moment(current).day()!==6 && moment(current).day()!==0){
  16. this.props.postShedule({
  17. ...this.props.postNewShedule,
  18. data:current.toISOString().split('T')[0],
  19. });
  20. }
  21. current = new Date(+current + 86400000)
  22. }
  23. };
  24. changeStart = (e) => {
  25. this.setState({startDate:e.target.value } )
  26. };
  27. changeEnd = (e) => {
  28. this.setState ( { endDate:e.target.value } )
  29. };
  30. setDoctor = (e) => {
  31. this.props.setSheduleDoctor({data:e,doctors:this.props.doctors})
  32. };
  33. render() {
  34. const {doctors, postNewShedule} = this.props;
  35. const doctor = doctors.find(el => el._id === postNewShedule.doctor);
  36. return (
  37. <div className = "shedule-container" >
  38. <div className = "option" >
  39. <CustomSelect
  40. label="Выберите доктора"
  41. options= {doctors }
  42. clickOptionEvent={this.setDoctor}
  43. />
  44. {postNewShedule.doctor &&
  45. <div className = "input-box">
  46. <input className = "shedule-input " type="date" onChange = {this.changeStart}/>
  47. <input className = "shedule-input right" type="date" onChange = {this.changeEnd}/>
  48. </div>
  49. }
  50. {(this.state.startDate && this.state.endDate) &&
  51. <button className = "btn admin" onClick = {this.post}> Отправить </button>
  52. }
  53. </div>
  54. {postNewShedule.doctor &&
  55. <Calendar
  56. doctor={doctor}
  57. action = {console.log }
  58. />
  59. }
  60. </div>
  61. );
  62. }
  63. }