From 341739bd14e5f1af391fba73d88a9ebca1b21881 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sat, 11 Jul 2026 13:49:34 +0000 Subject: [PATCH] Changes Co-authored-by: wolfoftyreso-debug <250630591+wolfoftyreso-debug@users.noreply.github.com> --- src/components/admin/LeadsGenerator.tsx | 44 +++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/components/admin/LeadsGenerator.tsx b/src/components/admin/LeadsGenerator.tsx index de54081..8c88419 100644 --- a/src/components/admin/LeadsGenerator.tsx +++ b/src/components/admin/LeadsGenerator.tsx @@ -35,8 +35,52 @@ export function LeadsGenerator() { const [researchingLead, setResearchingLead] = useState(null); const [emailDialog, setEmailDialog] = useState(null); const [copiedField, setCopiedField] = useState(null); + const [recipient, setRecipient] = useState(""); + const [sending, setSending] = useState(false); const { toast } = useToast(); + useEffect(() => { + setRecipient(""); + }, [emailDialog?.company_name]); + + const sendEmail = async () => { + if (!emailDialog || !recipient) return; + setSending(true); + try { + const res = await fetch( + `${import.meta.env.VITE_SUPABASE_URL}/functions/v1/send-outreach-email`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${import.meta.env.VITE_SUPABASE_PUBLISHABLE_KEY}`, + }, + body: JSON.stringify({ + to_email: recipient, + to_name: emailDialog.company_name, + subject: emailDialog.email.subject, + body: emailDialog.email.body, + }), + }, + ); + const data = await res.json(); + if (!res.ok) throw new Error(data.error || "Kunde inte skicka mejl"); + toast({ + title: "Mejl skickat!", + description: `Skickat från konditorivaror@gmail.com till ${recipient}`, + }); + setEmailDialog(null); + } catch (err) { + toast({ + title: "Fel vid utskick", + description: err instanceof Error ? err.message : "Okänt fel", + variant: "destructive", + }); + } finally { + setSending(false); + } + }; + const generateLeads = async () => { setIsLoading(true); try {