UNPKG

@kiwicom/smart-faq

Version:

49 lines (39 loc) 1.1 kB
// @flow strict import * as React from 'react'; import LogContext from '@kiwicom/nitro/lib/services/log/context'; import type { Context as LogContextType } from '@kiwicom/nitro/lib/services/log/context'; import type { Props as EventProps } from '@kiwicom/nitro/lib/records/Event'; import { defaultDestinations } from '../../../const/events'; type Props = {| subCategory: string, action: string, props?: EventProps, |}; // TODO ship this into nitrolib export default class LogUnmount extends React.Component<Props> { openedAt: number; context: LogContextType; static contextType = LogContext; static defaultProps = { props: {}, }; componentDidMount() { this.openedAt = Date.now(); } componentWillUnmount() { const { subCategory, action, props } = this.props; const timeOpen = Math.round((Date.now() - this.openedAt) / 1000); this.context.log( { category: 'SmartFAQ', subCategory, action, destinations: defaultDestinations, }, { ...props, timeOpen }, ); } render() { return null; } }