From 1131b2d448910625a40a7089c05e2d36b1e9a97a Mon Sep 17 00:00:00 2001 From: keannu125 Date: Mon, 27 Feb 2023 12:38:34 +0800 Subject: [PATCH] Added registration page --- src/Components/Api/Api.tsx | 18 +++++++ src/Routes/Register/Register.tsx | 83 ++++++++++++++++++++++++++++++++ src/index.tsx | 5 ++ 3 files changed, 106 insertions(+) create mode 100644 src/Routes/Register/Register.tsx diff --git a/src/Components/Api/Api.tsx b/src/Components/Api/Api.tsx index b0ad2bf..a9478b3 100644 --- a/src/Components/Api/Api.tsx +++ b/src/Components/Api/Api.tsx @@ -26,6 +26,24 @@ export function DeleteNote(id: number) { } // User APIs +export interface register { + email: string; + username: string; + password: string; +} + +export function UserRegister(register: register) { + return axios + .post("http://localhost:8000/api/v1/accounts/users/", register) + .then(async (response) => { + console.log(response.data); + return true; + }) + .catch((error) => { + console.log("Registration failed: " + error); + return false; + }); +} export interface user { username: string; diff --git a/src/Routes/Register/Register.tsx b/src/Routes/Register/Register.tsx new file mode 100644 index 0000000..ecff80a --- /dev/null +++ b/src/Routes/Register/Register.tsx @@ -0,0 +1,83 @@ +import * as React from "react"; +import styles from "../../styles"; + +import { useNavigate } from "react-router-dom"; +import Header from "../../Components/Header/Header"; +import { useState } from "react"; +import { Button } from "@mui/material"; +import { UserInfo, UserLogin } from "../../Components/Api/Api"; + +import { UserRegister } from "../../Components/Api/Api"; + +export default function Register() { + const navigate = useNavigate(); + const [user, setUser] = useState({ + email: "", + username: "", + password: "", + }); + const [feedback, setFeedback] = useState(""); + return ( +
+
+
+

Create an Account

+
+

Email

+
+ { + setUser({ ...user, email: e.target.value }); + }} + maxLength={20} + /> +
+
+

Username

+
+ { + setUser({ ...user, username: e.target.value }); + }} + maxLength={20} + /> +
+
+

Password

+
+ { + setUser({ ...user, password: e.target.value }); + }} + maxLength={20} + /> +
+ +

{feedback}

+
+
+ ); +} diff --git a/src/index.tsx b/src/index.tsx index a2f5a4d..2adba04 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -8,6 +8,7 @@ import Home from "./Routes/Home/Home"; import NewNote from "./Routes/NewNote/NewNote"; import Login from "./Routes/Login/Login"; import Activation from "./Routes/Activation/Activation"; +import Register from "./Routes/Register/Register"; import { QueryClient, QueryClientProvider } from "react-query"; @@ -29,6 +30,10 @@ const router = createBrowserRouter([ path: "/Login", element: , }, + { + path: "/Register", + element: , + }, { path: "/Activation/:uid/:token", element: ,