@kiwicom/smart-faq
Version:
105 lines (81 loc) • 5.93 kB
JavaScript
"use strict";
require("core-js/modules/es.array.concat");
require("core-js/modules/es.function.name");
require("core-js/modules/es.object.get-own-property-descriptor");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.RawAccordionLastLeg = void 0;
var React = _interopRequireWildcard(require("react"));
var _reactRelay = require("react-relay");
var _TripDate = _interopRequireDefault(require("@kiwicom/orbit-components/lib/TripSector/TripDate"));
var _TripSegment = _interopRequireDefault(require("@kiwicom/orbit-components/lib/TripSegment"));
var _context = require("@kiwicom/nitro/lib/services/intl/context");
var _dateUtils = require("../../helpers/dateUtils");
var _AccordionLegCitiesInfo = _interopRequireDefault(require("./AccordionLegCitiesInfo"));
var _bookingLegTypes = _interopRequireDefault(require("../../common/booking/bookingLegTypes"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
// @flow
var AccordionLastLeg = function AccordionLastLeg(props
/*: LastLegProps*/
) {
var _ref, _ref2, _ref3, _ref4, _departure$airport, _departure$airport$ci, _ref5, _departure$airport2, _ref6, _arrival$airport, _arrival$airport$city, _ref7, _arrival$airport2, _ref8, _leg$airline, _ref9, _leg$airline2, _leg$duration;
var leg = props.leg;
var departure = leg.departure,
arrival = leg.arrival,
type = leg.type;
var initialDeparture = (_ref = departure === null || departure === void 0 ? void 0 : departure.localTime) !== null && _ref !== void 0 ? _ref : '';
var departureTime = (_ref2 = departure && departure.localTime) !== null && _ref2 !== void 0 ? _ref2 : '';
var arrivalTime = (_ref3 = arrival && arrival.localTime) !== null && _ref3 !== void 0 ? _ref3 : '';
var departureCityName = (_ref4 = departure === null || departure === void 0 ? void 0 : (_departure$airport = departure.airport) === null || _departure$airport === void 0 ? void 0 : (_departure$airport$ci = _departure$airport.city) === null || _departure$airport$ci === void 0 ? void 0 : _departure$airport$ci.name) !== null && _ref4 !== void 0 ? _ref4 : '';
var departureCityCode = (_ref5 = departure === null || departure === void 0 ? void 0 : (_departure$airport2 = departure.airport) === null || _departure$airport2 === void 0 ? void 0 : _departure$airport2.locationId) !== null && _ref5 !== void 0 ? _ref5 : '';
var arrivalCityName = (_ref6 = arrival === null || arrival === void 0 ? void 0 : (_arrival$airport = arrival.airport) === null || _arrival$airport === void 0 ? void 0 : (_arrival$airport$city = _arrival$airport.city) === null || _arrival$airport$city === void 0 ? void 0 : _arrival$airport$city.name) !== null && _ref6 !== void 0 ? _ref6 : '';
var arrivalCityCode = (_ref7 = arrival === null || arrival === void 0 ? void 0 : (_arrival$airport2 = arrival.airport) === null || _arrival$airport2 === void 0 ? void 0 : _arrival$airport2.locationId) !== null && _ref7 !== void 0 ? _ref7 : '';
var carrier = {
code: (_ref8 = (_leg$airline = leg.airline) === null || _leg$airline === void 0 ? void 0 : _leg$airline.code) !== null && _ref8 !== void 0 ? _ref8 : '',
name: (_ref9 = (_leg$airline2 = leg.airline) === null || _leg$airline2 === void 0 ? void 0 : _leg$airline2.name) !== null && _ref9 !== void 0 ? _ref9 : ''
};
var carrierTypes = function carrierTypes(type) {
if (type === _bookingLegTypes.default.AIRCRAFT) return 'airline';
if (type === _bookingLegTypes.default.BUS) return 'bus';
if (type === _bookingLegTypes.default.TRAIN) return 'train';
throw new Error("Unknown carrier type");
};
var _timeDurationTranslat = (0, _dateUtils.timeDurationTranslationData)({
mins: (_leg$duration = leg.duration) !== null && _leg$duration !== void 0 ? _leg$duration : 0,
isLayover: false
}),
translationKey = _timeDurationTranslat.translationKey,
translationVariables = _timeDurationTranslat.translationVariables;
return React.createElement(_context.Consumer, null, function (intl) {
return React.createElement(React.Fragment, null, React.createElement(_TripDate.default, null, (0, _dateUtils.FormatDate)({
dateString: initialDeparture
})), React.createElement(_TripSegment.default, {
carrier: {
code: carrier.code,
type: carrierTypes(type),
name: carrier.name
},
duration: intl.translate(translationKey, translationVariables),
departure: "".concat(departureCityName, " ").concat(departureCityCode),
departureTime: (0, _dateUtils.formatHour)(departureTime),
arrival: "".concat(arrivalCityName, " ").concat(arrivalCityCode),
arrivalTime: (0, _dateUtils.formatHour)(arrivalTime)
}, React.createElement(_AccordionLegCitiesInfo.default, {
leg: leg
})));
});
};
var RawAccordionLastLeg = AccordionLastLeg;
exports.RawAccordionLastLeg = RawAccordionLastLeg;
var _default = (0, _reactRelay.createFragmentContainer)(AccordionLastLeg, {
leg: function leg() {
var node = require("./__generated__/AccordionBodyLastLeg_leg.graphql");
if (node.hash && node.hash !== "36db5f90deb32aac5e6d62edec4c2aa5") {
console.error("The definition of 'AccordionBodyLastLeg_leg' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data.");
}
return require("./__generated__/AccordionBodyLastLeg_leg.graphql");
}
});
exports.default = _default;