import React, { useEffect, useState } from 'react'; import ChatHistory from '../chat-history/ChatHistory'; import './activity.scss'; import { FulfillmentIcon, IActivityData, IChatItems, IHistoricalFulfillment, IKBFulfillment, IRequestData } from '../../models'; import FormatDate from '../../../../core/components/date/FormatDate'; import { ChannelIcon } from '../../../../components/aisera-icons/channel-icon/ChannelIcon'; const Activity = (props: IHistoricalActivityProps) => { const {ChatSimulatorView, request, activity, addToAnnotationWorkbench} = props; const [historicalFulfillments, setHistoricalFulfillments] = useState([]); const getCustomMessage = (message: any) => { if(typeof message === 'string') { return message; } if(Array.isArray(message)) { message = message[0]; } const list = message?.answerContents?.map((answer: any) => answer.data); if(list.length) { return list.join(''); } else { return 'N/A'; } } const getKbName = (fulfillment: IKBFulfillment) => { let kbDocument = fulfillment['kbDocument']; if (kbDocument) { return kbDocument.title } let kbSection = fulfillment['kbSection']; if(kbSection) { return kbSection.subject || kbSection.content_id || 'N/A'; } if(fulfillment.ext_definition_id) { let sectionKey: any = {contentId: fulfillment.ext_definition_id}; if (fulfillment.document_key) { sectionKey.document_key = fulfillment.document_key; } return JSON.stringify(sectionKey); } return 'N/A'; } useEffect(() => { if(request?._historicalEvents?.fulfillments?.length) { const fulfillments = request._historicalEvents.fulfillments.map(({type, ...fulfillment}) => { let icon = FulfillmentIcon[type as keyof typeof FulfillmentIcon]; let name = ''; switch(type) { case 'Flow': case 'KnowledgeFlow': name = fulfillment?.flow.name; break; case 'KB': name = getKbName(fulfillment as IKBFulfillment); break; case 'ServiceCatalog': name = fulfillment?.scItem?.title; break; case 'ResolutionNote': name = fulfillment.resolution? getCustomMessage(fulfillment.resolution) : 'N/A'; break; case 'Custom': name = fulfillment.definition ? getCustomMessage(fulfillment.definition) : 'N/A'; break; } return {icon, name, is_selected: fulfillment.is_selected}; }); setHistoricalFulfillments(fulfillments); } }, [request]); return (
Conversation  -  {activity.user.user_email}
) } export default Activity; export interface IHistoricalActivityProps { ChatSimulatorView: any; request: IRequestData; activity: IActivityData; addToAnnotationWorkbench: (phrase: string) => void; }