Orders.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import React, {Component} from 'react';
  2. import {Link} from 'react-router-dom'
  3. class Orders extends Component {
  4. componentDidMount() {
  5. this.props.getUsers();
  6. this.props.getOrders({doctors:this.props.doctors,services:this.props.services,users:this.props.users});
  7. }
  8. changeInputFindOrder = (e) => {
  9. this.props.changeInputFindOrder(e.target.value)
  10. };
  11. findOrders = () => {
  12. this.props.findOrdersArray()
  13. };
  14. enterPressed = (e) => {
  15. if (e.key === 'Enter') {
  16. this.findOrders();
  17. }
  18. };
  19. render() {
  20. const{findOrderInput,ordersArray,searching,orders} = this.props;
  21. console.log(this.props);
  22. return (
  23. <div style={{
  24. display:'flex',
  25. }}>
  26. <div style={{
  27. width:'50%'
  28. }}>
  29. <input type="text" onKeyDown={this.enterPressed} onChange={this.changeInputFindOrder}/>
  30. {findOrderInput &&
  31. <button id='enter' onClick={this.findOrders}>Find User</button>
  32. }
  33. {searching && ordersArray.length === 0 && <p>Order not found</p>}
  34. {ordersArray.map(el => (
  35. <div key={el._id} style={{
  36. display:'flex',
  37. }}>
  38. <Link to={`/order/${el._id}`}>{el.orderNumber}</Link>
  39. <div>
  40. <p>{el.date.split('T')[0]}</p>
  41. <p>{el.time}</p>
  42. </div>
  43. <Link to={`/user/${el.user._id}`}>{el.user.email}</Link>
  44. <Link to={`/doctors/${el.doctor._id}`}>{el.doctor.name}</Link>
  45. <Link to={`/services/${el.spec._id}`}>{el.spec.name}</Link>
  46. </div>
  47. ))}
  48. </div>
  49. <div style={{
  50. display:'flex',
  51. flexDirection:'column',
  52. width:'50%'
  53. }}>
  54. {orders.map(el => (
  55. <div key={el._id} style={{
  56. display:'flex',
  57. }}>
  58. <Link to={`/order/${el._id}`}>{el.orderNumber}</Link>
  59. <div>
  60. <p>{el.date.split('T')[0]}</p>
  61. <p>{el.time}</p>
  62. </div>
  63. <Link to={`/user/${el.user._id}`}>{el.user.email}</Link>
  64. <Link to={`/doctors/${el.doctor._id}`}>{el.doctor.name}</Link>
  65. <Link to={`/services/${el.spec._id}`}>{el.spec.name}</Link>
  66. </div>
  67. ))}
  68. </div>
  69. </div>
  70. );
  71. }
  72. }
  73. export default Orders;