Advertisement
Guest User

Untitled

a guest
Jul 30th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import {Col, Row, styled, styledFlexBoxGridSetting} from '@fcl/theme';
  4. import PlatformThemeProvider from 'material-ui/styles/MuiThemeProvider';
  5. import Card from 'material-ui/Card';
  6. import RaisedButton from 'material-ui/RaisedButton';
  7. import AltFareLogo from 'components/AltFareLogo';
  8. import Price from 'components/Price';
  9. import CategoryIndicator from 'components/CategoryIndicator';
  10. import AirlineLogo from 'components/AirlineLogo';
  11. import Selection from 'components/Selection';
  12. import Destination from 'components/FlightDestination';
  13. import AirExpoints from 'components/AirExpoints';
  14. import TravelDates from 'components/TravelDates';
  15. import LimitedAvailability from 'components/LimitedAvailability';
  16. import defaultThemeSettings from 'services/defaultThemeSettings';
  17. import isEscapeFaresSelection from 'services/isEscapeFaresSelection';
  18. import altFareWasPriceLabel from 'services/altFareWasPriceLabel';
  19.  
  20. import {bookingModalLink} from './services/bookingModalLink';
  21.  
  22. export class Tile extends React.Component {
  23.   static propTypes = {
  24.     className: PropTypes.string,
  25.     product: PropTypes.object,
  26.     mobile: PropTypes.number,
  27.     tablet: PropTypes.number,
  28.     desktop: PropTypes.number
  29.   }
  30.  
  31.   static defaultProps = {
  32.     className: '',
  33.     product: {},
  34.     mobile: 1,
  35.     tablet: 2,
  36.     desktop: 3
  37.   }
  38.  
  39.   constructor (props) {
  40.     super(props);
  41.     this.state = {shadow: 1};
  42.     this.onMouseOver = this.onMouseOver.bind(this);
  43.     this.onMouseOut = this.onMouseOut.bind(this);
  44.   }
  45.  
  46.   onMouseOver () {
  47.     this.setState({shadow: 3});
  48.   }
  49.  
  50.   onMouseOut () {
  51.     this.setState({shadow: 1});
  52.   }
  53.  
  54.   render () {
  55.     const {
  56.       className,
  57.       mobile,
  58.       tablet,
  59.       desktop,
  60.       product
  61.     } = this.props;
  62.     const {
  63.       destination,
  64.       country,
  65.       category,
  66.       air_ex_points: airExPoints,
  67.       price,
  68.       price_secondary: priceSecondary,
  69.       airline_code: airlineCode,
  70.       airlineName: airlineName,
  71.       selection,
  72.       travel_dates: travelDates,
  73.       bookable
  74.     } = product;
  75.  
  76.     const {gridSize, gutterWidth} = styledFlexBoxGridSetting.flexboxgrid;
  77.     const wasPriceLabel = isEscapeFaresSelection(selection) ? altFareWasPriceLabel() : 'Was';
  78.     const isBookable = Boolean(parseInt(bookable));
  79.  
  80.     return (
  81.       <PlatformThemeProvider muiTheme={defaultThemeSettings}>
  82.         <Col
  83.           xs={gridSize / mobile}
  84.           sm={gridSize / tablet}
  85.           md={gridSize / desktop}
  86.           className={className}
  87.         >
  88.           <Card
  89.             onMouseOver={this.onMouseOver}
  90.             onMouseOut={this.onMouseOut}
  91.             zDepth={this.state.shadow}
  92.             style={{
  93.               height: '100%',
  94.               overflow: 'hidden',
  95.               padding: '12px 8px'
  96.             }}
  97.           >
  98.             <Row>
  99.               <Col xs={12}>
  100.                 <Row>
  101.                   <Col xs={7}>
  102.                     <CategoryIndicator category={category}/>
  103.                     <AirExpoints>{`${airExPoints} to`}</AirExpoints>
  104.                     <Destination destination={destination} country={country}/>
  105.                     <AirlineLogo
  106.                       iataCode={airlineCode}
  107.                       airlineName={airlineName}
  108.                       logoType="logo_210x80"
  109.                       showName
  110.                     />
  111.                   </Col>
  112.                   <Col xs={5} style={{float: 'right'}}>
  113.                     <Row>
  114.                       <Col>
  115.                         <AltFareLogo product={product}/>
  116.                       </Col>
  117.                     </Row>
  118.                     <Row>
  119.                       <Col>
  120.                         <Selection selection={selection}/>
  121.                       </Col>
  122.                     </Row>
  123.                     <Row>
  124.                       <Col>
  125.                         <Price
  126.                           label="Flight from"
  127.                           value={price}
  128.                           wasLabel={wasPriceLabel}
  129.                           was={priceSecondary}
  130.                           pt
  131.                         />
  132.                         <LimitedAvailability product={product}/>
  133.                       </Col>
  134.                     </Row>
  135.                   </Col>
  136.                 </Row>
  137.               </Col>
  138.             </Row>
  139.             <Row>
  140.               <Col xs={12}>
  141.                 <TravelDates>{`Travel Dates ${travelDates}`}</TravelDates>
  142.               </Col>
  143.             </Row>
  144.             <Row>
  145.               <Col xs={isBookable ? 6 : 12}>
  146.                 <RaisedButton
  147.                   label="Enquire Now"
  148.                   fullWidth
  149.                   backgroundColor={defaultThemeSettings.palette.accent3Color}
  150.                   labelColor="#fff"
  151.                   href="#enquire"
  152.                 />
  153.               </Col>
  154.               {isBookable &&
  155.                 <Col xs={6}>
  156.                   <RaisedButton
  157.                     fullWidth
  158.                     label="Book Now"
  159.                     containerElement={
  160.                       <a
  161.                         className="product-action booking-modal use-ajax"
  162.                         data-open="soar-form-modal"
  163.                         href={bookingModalLink(product)}
  164.                       />
  165.                     }
  166.                   />
  167.                 </Col>
  168.               }
  169.             </Row>
  170.           </Card>
  171.         </Col>
  172.       </PlatformThemeProvider>
  173.     );
  174.   }
  175. }
  176.  
  177. export default styled(Tile)`
  178.   padding-bottom: 2rem;
  179.   font-family: Roboto, sans-serif;
  180.   position: relative;
  181.  
  182.   ${Destination} {
  183.     margin: 0 0 32px;
  184.   }
  185.  
  186.   ${AltFareLogo} {
  187.     display: block;
  188.     margin: 0 0 8px;
  189.   }
  190.  
  191.   ${Selection} {
  192.     margin: 0 0 5px;
  193.   }
  194. `;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement