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