@kiwicom/smart-faq
Version:
Smart FAQ
89 lines (76 loc) • 2.29 kB
JavaScript
// @flow
import * as React from 'react';
import InitIntl from '@kiwicom/nitro/lib/components/InitIntl';
import * as intlContext from '@kiwicom/nitro/lib/services/intl/context';
import { langInfos } from './translations/langInfos';
import fallbackTranslations from './translations/enKeys.json';
import ContactFormChat from './ContactFormChat/ContactFormChat';
import GuaranteeChatInfo from './shared/context/GuaranteeChatInfo';
import { setTracker } from './shared/cuckoo/tracker';
import type { CuckooLogger } from './shared/cuckoo/cuckooTypes';
import { Provider } from './ContactFormChat/BookingInfo';
type Props = {
cuckoo?: CuckooLogger,
bid: ?number,
loginToken: ?string,
kwAuthToken: ?string,
simpleToken: ?string,
enableChat: boolean,
translations: { [key: string]: string } | null,
chatConfig: { [key: string]: string } | null,
language: string,
brand: string,
};
class ContactFormChatApp extends React.Component<Props> {
static BookingInfoProvider = Provider;
constructor(props: Props) {
super(props);
if (props.cuckoo) {
setTracker(props.cuckoo);
}
}
render() {
const {
language,
loginToken,
kwAuthToken,
simpleToken,
bid,
brand,
enableChat,
} = this.props;
const langInfo = langInfos[language];
const translations = this.props.translations
? this.props.translations
: fallbackTranslations;
if (!loginToken && !(simpleToken && bid)) {
return null;
}
const intl = { language: langInfo, translations };
return (
<InitIntl raw={intl}>
{intl => (
<intlContext.Provider value={intl}>
<GuaranteeChatInfo
enableChat={enableChat}
chatConfig={this.props.chatConfig}
>
<ContactFormChat
loginToken={loginToken}
simpleToken={simpleToken}
kwAuthToken={kwAuthToken}
bid={bid}
brand={brand}
language={language}
/>
</GuaranteeChatInfo>
</intlContext.Provider>
)}
</InitIntl>
);
}
}
if (typeof window !== 'undefined') {
window.ContactFormChatApp = ContactFormChatApp;
}
export default ContactFormChatApp;