import { useState } from 'react'; import type { LDClient } from "launchdarkly-js-client-sdk"; import { sendFeedback, type LDFeedbackSentiment } from './sendFeedback'; const ThumbsUpIcon = () => ( ); const ThumbsDownIcon = () => ( ); const HappyFaceIcon = () => ( ); const NeutralFaceIcon = () => ( ); const FrownyFaceIcon = () => ( ); const SpeechBubbleIcon = () => ( ); type SentimentOption = { value: LDFeedbackSentiment; label: string; Icon: React.FC }; const THUMBS_OPTIONS: SentimentOption[] = [ { value: "positive", label: "Thumbs up", Icon: ThumbsUpIcon }, { value: "negative", label: "Thumbs down", Icon: ThumbsDownIcon }, ]; const SMILEY_OPTIONS: SentimentOption[] = [ { value: "positive", label: "Happy face", Icon: HappyFaceIcon }, { value: "neutral", label: "Neutral face", Icon: NeutralFaceIcon }, { value: "negative", label: "Frowny face", Icon: FrownyFaceIcon }, ]; export function PopoverFeedback({ flagKey, prompt, icons, ldClient, }: { flagKey: string; prompt: string; icons: "thumbs" | "smileys" | "none"; ldClient: LDClient; }) { const [isOpen, setIsOpen] = useState(false); const [feedback, setFeedback] = useState(""); const [sentiment, setSentiment] = useState(undefined); const [submitted, setSubmitted] = useState(false); const sentimentOptions = icons === "thumbs" ? THUMBS_OPTIONS : icons === "smileys" ? SMILEY_OPTIONS : []; const handleSubmit = () => { sendFeedback(ldClient, flagKey, feedback, sentiment, prompt); setIsOpen(false); setFeedback(""); setSentiment(undefined); setSubmitted(true); }; if (submitted) { return Thanks for your feedback!; } return (
{isOpen && (