Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. import * as React from 'react';
  2. import './carInformation.component.scss';
  3. import i18next from 'i18next';
  4. import {
  5. Popover, ButtonToolbar, OverlayTrigger, Button, Container, Row,
  6. } from 'react-bootstrap';
  7.  
  8.  
  9. const subscribe = require('./../../../../../../src/statics/icons/info.svg');
  10. const calendarIcon = require('./../../../../../../src/statics/icons/icon-delivery-date.svg');
  11.  
  12. interface IProps {
  13. carDetail: any,
  14. }
  15.  
  16. interface State {
  17. date: string,
  18. thereIsDate: boolean,
  19. }
  20.  
  21. class CarInformationComponent extends React.Component<IProps, State> {
  22. state = {
  23. date: '',
  24. thereIsDate: false,
  25. }
  26.  
  27. componentWillMount() {
  28. const { carDetail } = this.props;
  29. if (carDetail && carDetail.deliveryDate) {
  30. const options = {
  31. year: 'numeric',
  32. month: 'long',
  33. day: 'numeric',
  34. };
  35. const arrDate = carDetail.deliveryDate.split('.');
  36. const event = new Date(Date.UTC(arrDate[2], (arrDate[1]) - 1, arrDate[0], 0, 0, 0));
  37. const date = event.toLocaleDateString('de-DE', options);
  38.  
  39. this.setState({
  40. date,
  41. thereIsDate: true,
  42. })
  43. }
  44. }
  45.  
  46. render() {
  47. const { carDetail } = this.props;
  48. const regExp = new RegExp(/Spain/gi);
  49. const { date, thereIsDate } = this.state;
  50. let dateInTooltip = null;
  51.  
  52. if (thereIsDate) {
  53. dateInTooltip = (
  54. <div>
  55. <div className="calender">
  56. <img src={calendarIcon} alt="Calendar" />
  57. <h2>Lieferdatum</h2>
  58. </div>
  59. <h3>{date}</h3>
  60. </div>
  61. )
  62. }
  63. return (
  64. <ButtonToolbar id="tooltip" className="ioutline">
  65. <OverlayTrigger
  66. trigger="click"
  67. rootClose
  68. key="bottom"
  69. placement="bottom"
  70. overlay={(
  71. <Popover id="ipopover-positioned-bottom" className="information">
  72. <Container fluid>
  73. <Row className="row-top-icontainer">
  74. <div>
  75. <h2>Modell:</h2>
  76. <h3>{carDetail ? carDetail.model : ''}</h3>
  77. </div>
  78. <div>
  79. <h2>Herkunft:</h2>
  80. <h3>{carDetail ? carDetail.origin.replace(regExp, i18next.t('countries.spain')) : ''}</h3>
  81. </div>
  82. <div>
  83. <h2>Zielort:</h2>
  84. <h3>{carDetail ? carDetail.destination : ''}</h3>
  85. </div>
  86. </Row>
  87. <Row className="row-bottom-icontainer">
  88. {dateInTooltip}
  89. </Row>
  90. </Container>
  91. </Popover>
  92. )}
  93. >
  94. <Button className="button-subscribe"><img src={subscribe} className="info-button" alt="subscribe" /></Button>
  95. </OverlayTrigger>
  96. </ButtonToolbar>
  97. );
  98. }
  99. }
  100.  
  101. export default CarInformationComponent;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement