Appointment.js 7.3 KB

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