feat(client): add profile and donation page

This commit is contained in:
carraya 2022-04-17 02:02:22 -04:00
parent 8074b7d042
commit 7a3190ad07
4 changed files with 126 additions and 6 deletions

View File

@ -7,7 +7,29 @@ export default function AuthComponent() {
const router = useRouter();
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const [registerUsername, setRegisterUsername] = useState("");
const [registerPassword, setRegisterPassword] = useState("");
async function handleRegisterSubmit(e) {
try {
const requestOptions = {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
username: registerUsername,
password: registerPassword,
}),
};
const response = await fetch(
"http://localhost:8000/api/profile/create",
requestOptions
);
const dataa = await response.json();
console.log(dataa);
} catch (error) {
console.log(error);
}
}
async function handleSubmit(e) {
try {
console.log(username);
@ -29,6 +51,18 @@ export default function AuthComponent() {
console.log(data);
localStorage.setItem("token", data.access);
localStorage.setItem("username", username);
// const reqOps = {
// method: "GET",
// headers: {
// "Content-Type": "application/json",
// Authorization: `Bearer ${data.access}`,
// },
// };
// const resp = await fetch("http://localhost:8000/api/foundation/", reqOps);
// const data2 = await resp.json();
// console.log(data2);
router.push("/");
} catch (error) {
@ -38,9 +72,9 @@ export default function AuthComponent() {
return (
<>
<h1>Register</h1>
<h1>Login</h1>
<input
placeholder="Email"
placeholder="Username"
onChange={(e) => setUsername(e.target.value)}
/>
<input
@ -49,6 +83,21 @@ export default function AuthComponent() {
onChange={(e) => setPassword(e.target.value)}
/>
<button onClick={handleSubmit}>Submit</button>
<br />
<h1>OR</h1>
<br />
<h1>Register</h1>
<input
placeholder="Username"
onChange={(e) => setRegisterUsername(e.target.value)}
/>
<input
placeholder="Password"
type="password"
onChange={(e) => setRegisterPassword(e.target.value)}
/>
<button onClick={handleRegisterSubmit}>Submit</button>
</>
);
}

View File

@ -0,0 +1,32 @@
import { useEffect, useState } from "react";
export default function DonatePage() {
const [foundation, setFoundation] = useState("");
useEffect(() => {
async function getData() {
const reqOps = {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${localStorage.getItem("token")}`,
},
};
const resp = await fetch("http://localhost:8000/api/foundation/", reqOps);
const data = await resp.json();
// console.log(data);
setFoundation(JSON.stringify(data));
}
// const d = ;
getData();
console.log(foundation);
// setFoundation(d);
}, []);
return (
<div>
<h1>This is the donate page.</h1>
<p>This page is under construction. Please check back later.</p>
{/* {foundation.map((item) => (
<h1>{item.name}</h1>
))} */}
</div>
);
}

View File

@ -1,11 +1,13 @@
import { useAuth } from "../common/lib/firebase/authContext";
// import { useAuth } from "../common/lib/firebase/authContext";
export default function HomePage() {
const { currentUser } = useAuth();
// const { currentUser } = useAuth();
return (
<div>
<h1>This is HackTJ 2022!</h1>
{currentUser ? (
<p>You're logged in! Current email: {currentUser.email}</p>
{localStorage.getItem("username") ? (
<p>
You're logged in! Current username: {localStorage.getItem("username")}
</p>
) : (
<p>Not logged in</p>
)}

View File

@ -0,0 +1,37 @@
import { useState } from "react";
export default function Profile() {
const [wallet, setWallet] = useState("");
async function handleSubmit(e) {
try {
const reqOps = {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${localStorage.getItem("token")}`, //prettier-ignore
},
body: {
"address": wallet, //prettier-ignore
},
};
const resp = await fetch(
"http://localhost:8000/api/profile/add_wallet",
reqOps
);
const data = await resp.json();
console.log(data);
} catch (error) {
console.log(error);
}
}
return (
<div>
<h1>Profile</h1>
<h2>Add Wallet</h2>
<input
placeholder="Address"
onChange={(e) => setWallet(e.target.value)}
/>
<button onClick={handleSubmit}>Submit</button>
</div>
);
}