docs: add a copy button to AI assistant answers (#14052)

This commit is contained in:
Shahed Nasser
2025-11-14 16:03:00 +02:00
committed by GitHub
parent 178b1e2b47
commit 20892aee87
@@ -6,6 +6,7 @@ import {
ThumbUp, ThumbUp,
Link as LinkIcon, Link as LinkIcon,
CheckCircle, CheckCircle,
SquareTwoStack,
} from "@medusajs/icons" } from "@medusajs/icons"
import { import {
AiAssistantThreadItem as AiAssistantThreadItemType, AiAssistantThreadItem as AiAssistantThreadItemType,
@@ -26,9 +27,12 @@ export const AiAssistantThreadItemActions = ({
const { const {
config: { baseUrl }, config: { baseUrl },
} = useSiteConfig() } = useSiteConfig()
const { handleCopy, isCopied } = useCopy( const { handleCopy: handleLinkCopy, isCopied: isLinkCopied } = useCopy(
`${baseUrl}?query=${encodeURI(item.content)}` `${baseUrl}?query=${encodeURI(item.content)}`
) )
const { handleCopy: handleAnswerCopy, isCopied: isAnswerCopied } = useCopy(
item.content
)
const handleFeedback = async ( const handleFeedback = async (
reaction: Reaction, reaction: Reaction,
@@ -55,8 +59,8 @@ export const AiAssistantThreadItemActions = ({
> >
{item.type === "question" && ( {item.type === "question" && (
<div className="flex gap-docs_0.25 items-center text-medusa-fg-muted"> <div className="flex gap-docs_0.25 items-center text-medusa-fg-muted">
<ActionButton onClick={handleCopy}> <ActionButton onClick={handleLinkCopy}>
{isCopied ? <CheckCircle /> : <LinkIcon />} {isLinkCopied ? <CheckCircle /> : <LinkIcon />}
</ActionButton> </ActionButton>
</div> </div>
)} )}
@@ -74,6 +78,9 @@ export const AiAssistantThreadItemActions = ({
</div> </div>
)} )}
<div className="flex gap-docs_0.25 items-center text-medusa-fg-muted"> <div className="flex gap-docs_0.25 items-center text-medusa-fg-muted">
<ActionButton onClick={handleAnswerCopy}>
{isAnswerCopied ? <CheckCircle /> : <SquareTwoStack />}
</ActionButton>
{(feedback === null || feedback === "upvote") && ( {(feedback === null || feedback === "upvote") && (
<ActionButton <ActionButton
onClick={async () => handleFeedback("upvote", item.question_id)} onClick={async () => handleFeedback("upvote", item.question_id)}