Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. import React from 'react';
  2. import { Header, Table, Modal, Button } from 'semantic-ui-react';
  3. import {
  4. getSchedule,
  5. payload,
  6. generateTokenIfNeeded
  7. } from "../../helpers/api";
  8. import {formattedAddress, unwrapAppointment} from "../../helpers/func";
  9. import AuthRoute from "../AuthRoute";
  10. import Timeline from "../elements/timeline/Timeline";
  11.  
  12. class SchedulePage extends AuthRoute {
  13.  
  14. state = {
  15. account: '',
  16. appointments: [],
  17. appointmentRows: [],
  18. selectedAppointment: {},
  19. modalOpen: false
  20. };
  21.  
  22. clicked = appointment => () => {
  23. this.setState({modalOpen: true, selectedAppointment: appointment});
  24. }; // Opens the appointment modal.
  25.  
  26. modalDidClose = () => {
  27. this.setState({modalOpen: false});
  28. };
  29.  
  30.  
  31. renderTableRow = function(appointment) {
  32. const self = this;
  33. return(
  34. <Table.Row onClick={self.clicked(appointment)} key={appointment["uuid"]}>
  35. <Table.Cell>
  36. {appointment["assigned_to"].fname + ' ' + appointment["assigned_to"].lname}
  37. </Table.Cell>
  38. <Table.Cell>
  39. {appointment["client"].fname + ' ' + appointment["client"].lname}
  40. </Table.Cell>
  41. <Table.Cell>
  42. {appointment["description"]}
  43. </Table.Cell>
  44. <Table.Cell>
  45. {appointment["date_time"]}
  46. </Table.Cell>
  47. </Table.Row>
  48. );
  49. };
  50.  
  51. //Todo -> Stop the endpoint from getting called twice.
  52. componentDidMount() {
  53. super.componentDidMount();
  54. const self = this;
  55.  
  56. generateTokenIfNeeded().then(function () {
  57. console.log('Retrieving Schedule...');
  58. return getSchedule();
  59. }).then(function (res) {
  60. const appts = payload(res).appointments;
  61. const apptRows = appts.map((appt) => {
  62. return self.renderTableRow(appt);
  63. });
  64. self.setState({appointmentRows: apptRows, appointments: appts});
  65. });
  66. }
  67.  
  68. render() {
  69. const { modalOpen, selectedAppointment } = this.state;
  70. const appt = unwrapAppointment(selectedAppointment);
  71. return (
  72. <div className="Scheduler-body">
  73. <Timeline/>
  74. <Modal size={'large'} open={modalOpen} onClose={this.modalDidClose}>
  75. <Modal.Header>
  76. <Header content={appt.description + ' for ' + appt.client.fname + ' ' + appt.client.lname} as={'h1'}/>
  77. </Modal.Header>
  78. <Modal.Content>
  79. <p><b>Assigned To: </b>{appt.assignedTo.fname + ' ' + appt.assignedTo.lname}</p>
  80. <p><b>Client: </b>{appt.client.fname + ' ' + appt.client.lname}</p>
  81. <p><b>Description: </b>{appt.description} </p>
  82. <p><b>Date/Time: </b>{appt.dateTime} </p>
  83. <div><b>Address: </b> {formattedAddress(appt.client.address)}</div>
  84. </Modal.Content>
  85. <Modal.Actions>
  86. <Button positive onClick={this.modalDidClose} icon='checkmark' labelPosition='right' content='Close' />
  87. </Modal.Actions>
  88. </Modal>
  89. </div>
  90. );
  91. }
  92. }
  93.  
  94.  
  95. export default SchedulePage;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement