Skip to content

Commit

Permalink
create user form
Browse files Browse the repository at this point in the history
  • Loading branch information
Morimoto Mana committed Nov 11, 2024
1 parent cdd609b commit 2ef9abf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/app/Components/UserForm/UserForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"use client";
import React, { useState } from "react";
export default function UserForm() {
const [name, setName] = useState("");

const handleSubmit = async (event: React.FormEvent) => {
event.preventDefault();

try {
const response = await fetch(
"http://127.0.0.1:5001/todo-real-c28fa/asia-northeast1/firestore/user/",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ name }),
}
);

if (!response.ok) {
throw new Error("Network response was not ok");
}
const data = await response.json();
console.log("Success:", data);
} catch (error) {
console.error("Error:", error);
}
};

return (
<form onSubmit={handleSubmit}>
<label>
Username:
<input
type="text"
value={name}
onChange={(e) => setName(e.target.value)}
required
/>
</label>
<button type="submit">Submit</button>
</form>
);
}
2 changes: 2 additions & 0 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import Posts from "./Components/Posts/Posts";
import UserForm from "./Components/UserForm/UserForm";

export default function Home() {
return (
<>
<Posts />
<UserForm />
</>
);
}

0 comments on commit 2ef9abf

Please sign in to comment.