@kiwicom/smart-faq
Version:
Smart FAQ
79 lines (73 loc) • 2.78 kB
JavaScript
// @flow
import * as React from 'react';
import { withRouter } from 'react-router-dom';
import { TextLink } from '@kiwicom/orbit-components';
import Translate from '@kiwicom/nitro/lib/components/Translate';
import { Consumer as IntlConsumer } from '@kiwicom/nitro/lib/services/intl/context';
import { GuaranteeChatContext } from '../../../shared/context/GuaranteeChatInfo';
import { UserContext, withLogin } from '../../context/User';
import { SelectedBooking } from '../../context/SelectedBooking';
import { simpleTracker } from '../../../shared/helpers/analytics/trackers';
import type { UserContextType } from '../../context/User';
import type { State as GuaranteeChatInfoStateType } from '../../../shared/context/GuaranteeChatInfo';
import type { State } from '../../context/SelectedBooking';
import type { onLogin } from '../../../types';
import { track } from '../../../shared/cuckoo/tracker';
type Props = {|
onLogin: onLogin,
history: {
push: string => void,
},
match: {
params: {
articleId: string,
categoryId: string,
[key: string]: ?string,
},
},
|};
const SelectAnotherBookingLink = (props: Props) => (
<IntlConsumer>
{intl => (
<GuaranteeChatContext.Consumer>
{({ isChatActive }: GuaranteeChatInfoStateType) => (
<SelectedBooking.Consumer>
{({ onDisplayAll }: State) => (
<UserContext.Consumer>
{({ simpleToken, user }: UserContextType) => (
<TextLink
onClick={e => {
e.preventDefault();
if (
isChatActive &&
!window.confirm(
intl.translate(
__('smartfaq.guarantee_chat.confirmation'),
),
)
) {
return;
}
simpleTracker('smartFAQBookingOverview', {
action: 'selectAnotherBooking',
});
track('BookingOverview', 'selectAnotherBooking');
simpleToken && !user ? props.onLogin() : onDisplayAll();
}}
type="secondary"
size="small"
href=""
dataTest="btn-other-bookings"
>
<Translate t={__('smartfaq.select_another_booking')} />
</TextLink>
)}
</UserContext.Consumer>
)}
</SelectedBooking.Consumer>
)}
</GuaranteeChatContext.Consumer>
)}
</IntlConsumer>
);
export default withRouter(withLogin(SelectAnotherBookingLink));