Appointment.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import React from "react";
  2. import {connect} from "react-redux";
  3. import moment from "moment";
  4. import {CustomSelect} from "./select";
  5. import {
  6. setAppointmentSpec,
  7. setAppointmentShedule,
  8. setAppointmentDoctor,
  9. clearAppointment,
  10. setAppointmentTime,
  11. setAppointmentComment,
  12. postOrders
  13. } from "../../actions/appointment";
  14. import Calendar from "../Calendar";
  15. export class Appoint extends React.Component {
  16. state = {
  17. pickedDate: null
  18. };
  19. componentDidMount() {
  20. this.props.setAppointmentDoctor(this.props.match.params.doctorId)
  21. }
  22. componentWillUnmount() {
  23. this.props.clearAppointment()
  24. }
  25. setSpec = (e) => {
  26. this.props.setAppointmentSpec({data: e, services: this.props.services})
  27. };
  28. setShedule = (e) => {
  29. this.setState({pickedDate: e.target.id});
  30. this.props.setAppointmentShedule({
  31. data: e.target.id,
  32. services: this.props.services,
  33. doctors: this.props.doctors
  34. })
  35. };
  36. setTime = (e) => {
  37. this.props.setAppointmentTime(e.target.value)
  38. };
  39. setComment = (e) => {
  40. this.props.setAppointmentComment(e.target.value)
  41. };
  42. postOrder = () => {
  43. this.props.postOrders(this.props.appointment.appointment)
  44. };
  45. render() {
  46. const {appointment, timeArray, doctors, services, match} = this.props;
  47. const doctor = doctors.find(el => el._id === match.params.doctorId);
  48. let spec;
  49. if (appointment.specId) {
  50. spec = services.find(el => el._id === appointment.specId)
  51. }
  52. console.log(appointment)
  53. return (
  54. <>
  55. <div className="main">
  56. {doctor &&
  57. <div className="info-wrap">
  58. <div className="card">
  59. <div className="card-item present">
  60. <div className="photo">
  61. <img src={`.${doctor.photo}`} alt={doctor.name}/>
  62. </div>
  63. <div className="order">
  64. <h3>{doctor.name}</h3>
  65. <p className="highlights">{doctor.profession}</p>
  66. <CustomSelect
  67. label="Выбор услуги"
  68. options={doctor.speciality}
  69. clickOptionEvent={this.setSpec}
  70. />
  71. </div>
  72. </div>
  73. <div className="card-item desc">
  74. <div className="date-container">
  75. {appointment.specId &&
  76. <Calendar
  77. doctor={doctor}
  78. action={this.setShedule}
  79. />
  80. }
  81. {appointment.sheduleId && (
  82. <div className="appointment-time">
  83. <div className="btn-box">
  84. {timeArray.map((el, index) => (
  85. <div className="radio-btn" key={Object.keys(el)}>
  86. <input
  87. type="radio"
  88. className="radio"
  89. name="choise-time"
  90. id={index}
  91. onChange={this.setTime}
  92. value={Object.keys(el)}
  93. />
  94. <label htmlFor={index}>{Object.keys(el)}</label>
  95. </div>
  96. ))}
  97. </div>
  98. {appointment.time && (
  99. <textarea
  100. className="appointment comment"
  101. rows="2"
  102. placeholder="Добавить комментарий "
  103. onChange={this.setComment}
  104. />
  105. )}
  106. </div>
  107. )}
  108. </div>
  109. {appointment.specId &&
  110. <div className="order-information">
  111. <p>{spec.name}</p>
  112. <p>Длительность: {spec.duration} ч.</p>
  113. <p>Цена от {spec.price} грн.</p>
  114. {this.state.pickedDate &&
  115. <p> {moment(this.state.pickedDate).format("DD-MMMM-YYYY")} </p>
  116. }
  117. {appointment.time &&
  118. <>
  119. <p>{appointment.time}</p>
  120. <button className="btn link" onClick={this.postOrder}>Подтвердите запись
  121. </button>
  122. </>
  123. }
  124. </div>
  125. }
  126. </div>
  127. </div>
  128. </div>
  129. }
  130. </div>
  131. </>
  132. );
  133. }
  134. }
  135. const mapStateToProps = state => {
  136. return {
  137. appointment: state.appointment.appointment,
  138. timeArray: state.appointment.timeArray,
  139. doctors: state.app.doctors,
  140. services: state.app.services
  141. };
  142. };
  143. const mapDispatchToProps = {
  144. setAppointmentSpec,
  145. setAppointmentShedule,
  146. setAppointmentDoctor,
  147. clearAppointment,
  148. setAppointmentTime,
  149. setAppointmentComment,
  150. postOrders
  151. };
  152. export default connect(mapStateToProps,mapDispatchToProps)(Appoint);