Skip to content

Commit

Permalink
resend api added
Browse files Browse the repository at this point in the history
  • Loading branch information
korih committed Nov 21, 2024
1 parent 2e4de3b commit 1e778fc
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/components/contact/mailForm.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import React, { useState } from 'react'
import { createClient } from '@supabase/supabase-js'
import { IoSend } from 'react-icons/io5'
import { FaLinkedin, FaInstagram } from 'react-icons/fa'
import { LuMail } from 'react-icons/lu'

const supabaseUrl = 'https://rpsuamzzbfswevkexntj.supabase.co'
const supabaseKey = process.env.REACT_APP_SUPABASE_KEY
const supabase = supabaseKey ? createClient(supabaseUrl, supabaseKey) : null
if (!supabaseKey)
console.warn(
'WARNING: No supabase key found. Requests will not be sent to backend'
)

function MailForm() {
const [firstName, setFirstName] = useState('')
const [lastName, setLastName] = useState('')
Expand All @@ -23,17 +14,20 @@ function MailForm() {
e.preventDefault()

try {
if (!supabase) {
throw Error()
}

const { data, error } = await supabase
.from('messages')
.insert([{ firstName, lastName, email, phone, message }])
.select()
const response = await fetch("https://twilight-wildflower-fcec.ubcagrobot.workers.dev/", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: {
"firstName": firstName,
"lastName": lastName,
"phoneNumber": phone,
"email": email,
"body": message
}
})

if (error) {
console.error('Error: ', error)
if (!response.ok) {
throw Error()
} else {
setFirstName('')
Expand Down

0 comments on commit 1e778fc

Please sign in to comment.