diff --git a/src/App.css b/src/App.css index b9d355df..0835ea28 100644 --- a/src/App.css +++ b/src/App.css @@ -1,42 +1,44 @@ -#root { - max-width: 1280px; +.form-container { + padding: 20px; + max-width: 400px; margin: 0 auto; - padding: 2rem; - text-align: center; } -.logo { - height: 6em; - padding: 1.5em; - will-change: filter; - transition: filter 300ms; +.form-group { + margin-bottom: 15px; } -.logo:hover { - filter: drop-shadow(0 0 2em #646cffaa); + +.form-input { + width: 100%; + padding: 8px; + margin-top: 5px; } -.logo.react:hover { - filter: drop-shadow(0 0 2em #61dafbaa); + +.submit-button { + padding: 10px 20px; + background-color: #007bff; + color: white; + border: none; + border-radius: 4px; + cursor: pointer; } -@keyframes logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } +.submit-button:disabled { + cursor: not-allowed; } -@media (prefers-reduced-motion: no-preference) { - a:nth-of-type(2) .logo { - animation: logo-spin infinite 20s linear; - } +.message { + margin-top: 15px; + padding: 10px; + border-radius: 4px; } -.card { - padding: 2em; +.message.success { + background-color: #d4edda; + color: #155724; } -.read-the-docs { - color: #888; +.message.error { + background-color: #f8d7da; + color: #721c24; } diff --git a/src/App.tsx b/src/App.tsx index d7a72df3..ab2bccfc 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,38 +1,130 @@ -import { useEffect, useState } from "react"; -import type { Schema } from "../amplify/data/resource"; -import { generateClient } from "aws-amplify/data"; +import { useState } from "react"; +import "./App.css"; -const client = generateClient(); +interface FormData { + firstName: string; + lastName: string; + email: string; + phone: string; +} function App() { - const [todos, setTodos] = useState>([]); + const [formData, setFormData] = useState({ + firstName: "", + lastName: "", + email: "", + phone: "" + }); + const [isSubmitting, setIsSubmitting] = useState(false); + const [message, setMessage] = useState(""); - useEffect(() => { - client.models.Todo.observeQuery().subscribe({ - next: (data) => setTodos([...data.items]), - }); - }, []); + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + setIsSubmitting(true); + setMessage(""); - function createTodo() { - client.models.Todo.create({ content: window.prompt("Todo content") }); - } + try { + const response = await fetch( + "https://0ovbdtb93d.execute-api.us-east-1.amazonaws.com/prod/SignUpForm", + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(formData), + } + ); + + if (response.ok) { + setMessage("Form submitted successfully!"); + setFormData({ firstName: "", lastName: "", email: "", phone: "" }); + } else { + setMessage(`Error: ${response.status}`); + } + } catch (error) { + setMessage(`Network error: ${error}`); + } finally { + setIsSubmitting(false); + } + }; + + const handleChange = (e: React.ChangeEvent) => { + setFormData({ + ...formData, + [e.target.name]: e.target.value + }); + }; return ( -
-

My todos

- -
    - {todos.map((todo) => ( -
  • {todo.content}
  • - ))} -
-
- 🥳 App successfully hosted. Try creating a new todo. -
- - Review next step of this tutorial. - -
+
+

Contact Form

+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + +
+ + {message && ( +
+ {message} +
+ )}
); }