@kiwicom/smart-faq
Version:
Smart FAQ
88 lines (80 loc) • 2.21 kB
JavaScript
// @flow
import * as React from 'react';
import css from 'styled-jsx/css';
import { graphql, createFragmentContainer } from 'react-relay';
import Translate from '@kiwicom/nitro/lib/components/Translate';
import BaggageLoader from './BaggageLoader';
import BaggageDescriptionFragment from './BaggageDescription';
import {
replaceWithCurrentDomain,
addDeepLink,
} from '../../../../SmartFAQ/helpers/UrlHelpers';
import { simpleTracker } from '../../../../shared/helpers/analytics/trackers';
import type { BaggageSummary as BaggageSummaryProps } from './__generated__/BaggageSummary.graphql';
import { track } from '../../../../shared/cuckoo/tracker';
type Props = {|
data: ?BaggageSummaryProps,
mmbUrl: string,
|};
const styles = css`
.moreInfo {
margin: 20px 24px;
font-size: 12px;
font-style: italic;
}
.moreInfo a {
color: #00a991;
font-size: 12px;
text-decoration: none;
font-weight: 500;
font-style: normal;
}
hr.separationLine {
height: 1px;
background-color: #e8edf1;
border: none;
}
`;
const addMoreBagsTraker = () => {
simpleTracker('smartFAQ', {
action: 'addMoreBags',
});
track('Baggage', 'addMoreBags');
};
export const RawBaggageSummary = ({ data, mmbUrl }: Props) => {
return data ? (
<React.Fragment>
{data.map((baggage, i) => (
/* eslint-disable react/no-array-index-key*/
<BaggageDescriptionFragment key={i} data={baggage} />
))}
<div className="moreInfo">
<a
target="_blank"
rel="noopener noreferrer"
href={replaceWithCurrentDomain(addDeepLink(mmbUrl, 'bags'))}
onClick={addMoreBagsTraker}
>
<Translate
t={__('smartfaq.baggage_info.go_to_mmb_baggage_section')}
/>
</a>
</div>
<style jsx>{styles}</style>
</React.Fragment>
) : (
<React.Fragment>
<hr className="separationLine" />
<BaggageLoader />
<style jsx>{styles}</style>
</React.Fragment>
);
};
export default createFragmentContainer(
RawBaggageSummary,
graphql`
fragment BaggageSummary on BookingBaggage @relay(plural: true) {
...BaggageDescription
}
`,
);