From a149662806a6b6e73f5bf19cbc03708dfa14cd07 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Wed, 26 Feb 2025 16:24:44 +0000 Subject: [PATCH] Fix: Connected The prompt indicated a connection issue needed to be addressed. This commit addresses that issue. --- src/components/panel/MessageComposer.tsx | 37 +++++++++++++++---- supabase/functions/_shared/cors.ts | 5 +++ supabase/functions/send-sms/index.ts | 47 ++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 supabase/functions/_shared/cors.ts create mode 100644 supabase/functions/send-sms/index.ts diff --git a/src/components/panel/MessageComposer.tsx b/src/components/panel/MessageComposer.tsx index 386e40b..4cd3298 100644 --- a/src/components/panel/MessageComposer.tsx +++ b/src/components/panel/MessageComposer.tsx @@ -5,21 +5,41 @@ import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Card } from "@/components/ui/card"; import { toast } from "sonner"; +import { createClient } from "@supabase/supabase-js"; + +const supabase = createClient( + import.meta.env.VITE_SUPABASE_URL, + import.meta.env.VITE_SUPABASE_ANON_KEY +); export function MessageComposer() { const [message, setMessage] = useState(""); const [phoneNumber, setPhoneNumber] = useState(""); + const [isSending, setIsSending] = useState(false); - const handleSend = () => { + const handleSend = async () => { if (!message.trim() || !phoneNumber.trim()) { toast.error("Please enter both phone number and message"); return; } - - // Mock send functionality - toast.success("Message sent successfully!"); - setMessage(""); - setPhoneNumber(""); + + setIsSending(true); + try { + const { data, error } = await supabase.functions.invoke('send-sms', { + body: { phoneNumber, message } + }); + + if (error) throw error; + + toast.success("Message sent successfully!"); + setMessage(""); + setPhoneNumber(""); + } catch (error) { + console.error('Error sending message:', error); + toast.error("Failed to send message. Please try again."); + } finally { + setIsSending(false); + } }; return ( @@ -40,6 +60,7 @@ export function MessageComposer() { value={phoneNumber} onChange={(e) => setPhoneNumber(e.target.value)} className="w-full" + disabled={isSending} />