1 import moment from 'moment';
2 import PropTypes from 'prop-types';
3 import React from 'react';
4 import { ListGroup } from 'react-bootstrap';
5 import { useTranslation } from 'react-i18next';
7 import { getUserName } from '../../helpers/User';
9 const getEntryDate = entry => moment(entry.created_at).fromNow();
11 const getEntryOrigin = (entry, t) => {
12 return t('chatBotLog.origin.chatLog', {
13 channel: entry.origin.params[0],
14 date: new Date(entry.origin.created_at),
15 nick: entry.origin.nick,
19 const getEntryInfo = (entry, t) => {
20 if (entry.user && entry.category) {
21 return t('chatBotLog.info.userCat', {
22 category: t(`twitchBot.chatCategories.${entry.category}`),
23 date: getEntryDate(entry),
24 user: getUserName(entry.user),
28 return t('chatBotLog.info.cat', {
29 category: t(`twitchBot.chatCategories.${entry.category}`),
30 date: getEntryDate(entry),
34 return t('chatBotLog.info.user', {
35 date: getEntryDate(entry),
36 user: getUserName(entry.user),
39 return getEntryDate(entry);
42 const Item = ({ entry }) => {
43 const { t } = useTranslation();
45 return <ListGroup.Item>
52 className="text-muted"
54 {getEntryOrigin(entry, t)}
58 className="text-muted"
59 title={moment(entry.created_at).format('LLLL')}
61 {getEntryInfo(entry, t)}
68 entry: PropTypes.shape({
69 created_at: PropTypes.string,
70 origin: PropTypes.shape({}),
71 text: PropTypes.string,