|
| 1 | +import React from 'react'; |
| 2 | +import { Link } from 'react-router' |
| 3 | + |
| 4 | +import VisitService from 'services/Visit' |
| 5 | +import Error from 'components/Error/Error' |
| 6 | +import styles from 'components/Visit/Show/styles.css' |
| 7 | +import DateHelper from 'helpers/DateHelper' |
| 8 | + |
| 9 | +class Visit extends React.Component |
| 10 | +{ |
| 11 | + constructor(props) { |
| 12 | + super(props); |
| 13 | + this.state = { |
| 14 | + visit : null, |
| 15 | + error: '' |
| 16 | + }; |
| 17 | + this.getVisit(this.props.params.id); |
| 18 | + } |
| 19 | + |
| 20 | + getVisit(id) { |
| 21 | + VisitService.find(id).then((response) => { |
| 22 | + this.setState({visit: response.data.visit.shift()}); |
| 23 | + }).catch((error) => { |
| 24 | + this.setState({error: 'Error Found: Trying get visit'}); |
| 25 | + let isValidResponse = typeof error.response.data !== 'undefined' |
| 26 | + if (typeof error.response.data.error !== 'undefined') { |
| 27 | + this.setState({error: error.response.data.error}); |
| 28 | + } |
| 29 | + }); |
| 30 | + } |
| 31 | + |
| 32 | + render() { |
| 33 | + if (this.state.error) { |
| 34 | + return (<Error error={this.state.error} />); |
| 35 | + } |
| 36 | + if (!this.state.visit) { |
| 37 | + return <div>Loading...</div>; |
| 38 | + } |
| 39 | + |
| 40 | + return ( |
| 41 | + <div className="container column is-12"> |
| 42 | + <div className="section profile-heading profile-heading-color profile-visit"> |
| 43 | + <div className="columns"> |
| 44 | + <div className="column is-4"> |
| 45 | + <div className="image is-2by1"> |
| 46 | + <img src="https://placehold.it/256x256" /> |
| 47 | + </div> |
| 48 | + </div> |
| 49 | + <div className="column is-4 name"> |
| 50 | + <h3 className="title is-3 color-black"> |
| 51 | + <strong>{this.state.visit.client.name}</strong> |
| 52 | + </h3> |
| 53 | + <p className="tagline"> |
| 54 | + <strong>Visit Date: </strong>{DateHelper.formateDate(this.state.visit.visit_date)} |
| 55 | + </p> |
| 56 | + <p className="tagline"> |
| 57 | + <strong>Address: </strong>{this.state.visit.client.address} |
| 58 | + </p> |
| 59 | + <p className="tagline"> |
| 60 | + <strong>Area: </strong>{this.state.visit.client.area._id} |
| 61 | + </p> |
| 62 | + </div> |
| 63 | + <div className="column is-2 followers has-text-centered"> |
| 64 | + <p className="stat-val"><strong>R$ {this.state.visit.value_received}</strong></p> |
| 65 | + <p className="stat-key">Value Received</p> |
| 66 | + </div> |
| 67 | + <div className="column is-2 likes has-text-centered"> |
| 68 | + <p className="stat-val"><strong>{this.state.visit.sales_quantity}</strong></p> |
| 69 | + <p className="stat-key">Sales Quantity</p> |
| 70 | + </div> |
| 71 | + </div> |
| 72 | + </div> |
| 73 | + </div> |
| 74 | + ); |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +export default Visit; |
0 commit comments