|
1
|
"use client" |
|
2
|
|
|
3
|
import React from "react" |
|
4
|
import { Card } from "../../../Card" |
|
5
|
import { useChat } from "@kapaai/react-sdk" |
|
6
|
import { useAiAssistant } from "../../../../providers/AiAssistant" |
|
7
|
import { useMedusaSuggestions } from "../../../../hooks/use-medusa-suggestions" |
|
8
|
import { useAnalytics } from "../../../../providers/Analytics" |
|
9
|
import { DocsTrackingEvents } from "../../../../constants" |
|
10
|
import clsx from "clsx" |
|
11
|
|
|
12
|
type AiAssistantChatWindowCalloutProps = { |
|
13
|
className?: string |
|
14
|
} |
|
15
|
|
|
16
|
export const AiAssistantChatWindowCallout = ({ |
|
17
|
className, |
|
18
|
}: AiAssistantChatWindowCalloutProps) => { |
|
19
|
const { conversation } = useChat() |
|
20
|
const { loading } = useAiAssistant() |
|
21
|
const { track } = useAnalytics() |
|
22
|
|
|
23
|
const lastQuestion = conversation.getLatestCompleted()?.question |
|
24
|
|
|
25
|
const matchedCallout = useMedusaSuggestions({ |
|
26
|
keywords: lastQuestion || "", |
|
27
|
}) |
|
28
|
|
|
29
|
if (loading || !matchedCallout) { |
|
30
|
return null |
|
31
|
} |
|
32
|
|
|
33
|
return ( |
|
34
|
<div className={clsx("px-docs_1 pt-docs_1", className)}> |
|
35
|
<div className="flex justify-center items-center"> |
|
36
|
<Card |
|
37
|
{...matchedCallout} |
|
38
|
type="bloom" |
|
39
|
onClick={() => { |
|
40
|
track({ |
|
41
|
event: { |
|
42
|
event: DocsTrackingEvents.AI_ASSISTANT_CALLOUT_CLICK, |
|
43
|
options: { |
|
44
|
user_keywords: lastQuestion || "", |
|
45
|
callout_title: matchedCallout.title || "", |
|
46
|
callout_href: matchedCallout.href || "", |
|
47
|
}, |
|
48
|
}, |
|
49
|
}) |
|
50
|
}} |
|
51
|
/> |
|
52
|
</div> |
|
53
|
</div> |
|
54
|
) |
|
55
|
} |