Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ComposerFeedback.tsx

55 lines1.9 KB

1import {
2 codexFeedbackNotice,
3 type CodexFeedbackSubmission,
4} from "@t3tools/client-runtime/state/threads";
5import { msg } from "gt-react";
6import { MessageSquareIcon } from "lucide-react";
7​
8import { writeTextToClipboard } from "../../hooks/useCopyToClipboard";
9import { m, type MessageResolver } from "../../i18n/messages";
10import { Button } from "../ui/button";
11import { toastManager } from "../ui/toast";
12import type { ComposerBannerStackItem } from "./ComposerBannerStack";
13​
14export function feedbackBannerItem(
15 submission: CodexFeedbackSubmission,
16 onDismiss: () => void,
17 resolve: MessageResolver = m,
18): ComposerBannerStackItem | null {
19 const notice = codexFeedbackNotice(submission, resolve);
20 if (!notice) return null;
21 return {
22 id: `feedback:${submission.id}`,
23 variant:
24 submission.status === "failed" ? "error" : submission.status === "sent" ? "success" : "info",
25 icon: <MessageSquareIcon />,
26 ...notice,
27 actions:
28 submission.status === "sent" ? (
29 <Button
30 size="xs"
31 variant="ghost"
32 onClick={() => {
33 void writeTextToClipboard(submission.feedbackId, {
34 target: "Codex feedback thread ID",
35 unavailableMessage: msg(
36 "Clipboard API is unavailable while copying Codex feedback thread ID.",
37 ),
38 failureMessage: msg("Failed to copy Codex feedback thread ID to the clipboard."),
39 }).catch((error: unknown) => {
40 toastManager.add({
41 type: "error",
42 title: m(msg("Could not copy thread ID")),
43 description: error instanceof Error ? error.message : m(msg("An error occurred.")),
44 });
45 });
46 }}
47 >
48 {resolve(msg("Copy ID"))}
49 </Button>
50 ) : undefined,
51 ...(submission.status !== "uploading"
52 ? { dismissLabel: resolve(msg("Dismiss feedback notice")), onDismiss }
53 : {}),
54 };