"use client"; import { useEffect, useState } from "react"; import { Loader2, MessageSquare, Zap } from "lucide-react"; import { useTranslations } from "next-intl"; import { Dialog, DialogContent, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import type { QuickReply } from "@/types"; import { interactivePayloadPreviewText } from "@/lib/whatsapp/interactive"; interface QuickReplyPickerProps { open: boolean; onOpenChange: (open: boolean) => void; onPick: (qr: QuickReply) => void; } /** * Lists the account's saved quick replies for insertion into the * composer. Text snippets fill the textarea; interactive snippets open * the builder pre-filled (handled by the caller's `onPick`). */ export function QuickReplyPicker({ open, onOpenChange, onPick, }: QuickReplyPickerProps) { const t = useTranslations("Inbox.composer"); const [items, setItems] = useState([]); const [loading, setLoading] = useState(false); useEffect(() => { if (!open) return; let cancelled = false; setLoading(true); void (async () => { try { const res = await fetch("/api/quick-replies", { cache: "no-store" }); const data = await res.json().catch(() => ({})); if (!cancelled && res.ok) { setItems((data.quick_replies as QuickReply[]) ?? []); } } finally { if (!cancelled) setLoading(false); } })(); return () => { cancelled = true; }; }, [open]); return ( {t("quickReplies")}
{loading ? (
) : items.length === 0 ? (

{t("quickRepliesEmpty")}

) : (
    {items.map((qr) => (
  • ))}
)}
); }