Skip to content

Commit

Permalink
doGet contact form
Browse files Browse the repository at this point in the history
  • Loading branch information
eonurk committed Jul 29, 2024
1 parent 08ba241 commit 0c55ce3
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/components/ContactForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,28 @@ export function ContactFormDemo() {
},
});

async function onSubmit(data: z.infer<typeof FormSchema>) {
async function onSubmit(
data:
| string
| string[][]
| Record<string, string>
| URLSearchParams
| undefined
) {
try {
const params = new URLSearchParams(data).toString();
const response = await fetch(
"https://script.google.com/macros/s/AKfycbxUVRtZlOusMMHw-B076NRY0mapwcWGwgKP_naDoVlEYc_NC2TO6mNEKdYtvNNHNPSwcg/exec",
`https://script.google.com/macros/s/AKfycbwneoM8x6g-Ehsd1J8j-pcYXy2CNXX4vJtX9rVKGe2GNAETgtJSdENRwhYzogIVrZk23g/exec?${params}`,

{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
method: "GET",
redirect: "follow",
}
);

const result = await response.json();

if (result.ok === "success") {
if (result.result === "success") {
toast({
title: "Success!",
description: "Your message has been sent.",
Expand All @@ -66,7 +71,7 @@ export function ContactFormDemo() {
toast({
title: "Error!",
variant: "destructive",
description: `There was a problem submitting your form: ${result.error}`,
description: `There was a problem submitting your form.`,
});
}
} catch (error) {
Expand Down

0 comments on commit 0c55ce3

Please sign in to comment.