Appointment.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import React from 'react';
  2. import {connect} from "react-redux";
  3. // import { CustomSelect } from "./select";
  4. import {
  5. setAppointmentSpec,
  6. setAppointmentShedule,
  7. setAppointmentDoctor,
  8. clearAppointment,
  9. setAppointmentTime,
  10. setAppointmentComment,
  11. postOrders
  12. } from "../../actions/actions";
  13. import Calendar from "./Calendar";
  14. export class Appoint extends React.Component {
  15. componentDidMount() {
  16. this.props.setAppointmentDoctor(this.props.match.params.doctorId)
  17. }
  18. componentWillUnmount() {
  19. this.props.clearAppointment()
  20. }
  21. render() {
  22. const {doctors, appointment, timeArray,services} = this.props.app;
  23. const {match, setAppointmentSpec, setAppointmentShedule, setAppointmentTime, setAppointmentComment, postOrders} = this.props;
  24. const doctor = doctors.find(el => el._id === match.params.doctorId);
  25. let spec;
  26. if (appointment.spec){
  27. spec = services.find(el => el._id === appointment.spec)
  28. }
  29. return (
  30. <>
  31. <div className="main">
  32. {doctor &&
  33. <div className = "info-wrap">
  34. <div className="card">
  35. <div className="card-item">
  36. <img src={`.${doctor.photo}`} alt={doctor.name}/>
  37. </div>
  38. <div className="card-item desc">
  39. <h3>{doctor.name}</h3>
  40. <p className = "highlights">{doctor.profession}</p>
  41. {/* <CustomSelect label="Выбор услуги" /> */}
  42. {appointment.spec &&
  43. <div>
  44. <p>{spec.name}</p>
  45. <p>Длительность: {spec.duration} ч.</p>
  46. <p>Цена от {spec.price} грн.</p>
  47. </div>
  48. }
  49. <select className = "appointment " onChange={(e)=>setAppointmentSpec(e.target.value)} defaultValue='Выбор услуги'>
  50. <option disabled >Выбор услуги</option>
  51. {
  52. doctor.speciality.map(el=> (
  53. <option key={el._id}>{el.name}</option>
  54. ))
  55. }
  56. </select>
  57. {appointment.spec &&
  58. <Calendar
  59. doctor={doctor}
  60. action={setAppointmentShedule}
  61. />
  62. }
  63. {appointment.shedule &&
  64. <div className = "appointment-time" >
  65. <div className="btn-box" >
  66. { timeArray.map ( (el, index)=> (
  67. <label key={Object.keys(el)[0]} >
  68. <input type ="radio" name = "choise-time" id = {index} onChange={(e)=> setAppointmentTime(e.target.value)}
  69. value = {Object.keys(el)[0]} />
  70. {Object.keys(el)[0]}
  71. </label>
  72. ))
  73. }
  74. </div>
  75. </div>
  76. }
  77. {appointment.time &&
  78. <div style={{display:"flex",flexDirection:"column"}}>
  79. <input className = "appointment comment" type='text' placeholder='Добавить комментарий' onChange={(e)=>setAppointmentComment(e.target.value)}/>
  80. <button className = "btn link" onClick={() => postOrders(appointment)}>Подтвердите запись</button>
  81. </div>
  82. }
  83. </div>
  84. </div>
  85. </div>
  86. }
  87. </div>
  88. </>
  89. );
  90. }
  91. }
  92. const mapStateToProps = state => {
  93. return {
  94. app:state.app
  95. }
  96. };
  97. const mapDispatchToProps = {
  98. setAppointmentSpec,
  99. setAppointmentShedule,
  100. setAppointmentDoctor,
  101. clearAppointment,
  102. setAppointmentTime,
  103. setAppointmentComment,
  104. postOrders,
  105. };
  106. export default connect (mapStateToProps,mapDispatchToProps)(Appoint)
  107. // <div className = "btn appointment-link" onClick={(e)=> setAppointmentTime(e.target.value)} key={Object.keys(el)[0]} >
  108. // {Object.keys(el)[0]}
  109. // </div>
  110. // setAppointmentTime