From eab47e1bda68bb4f174cf25de8b720ba12d68d4d Mon Sep 17 00:00:00 2001 From: Brok3Turtl3 Date: Wed, 27 Mar 2024 09:49:17 -0400 Subject: [PATCH] CHE-39 Set up routing and basic RegistrationPage component --- client/src/App.tsx | 4 +- .../RegistrationPage/RegistrationPage.tsx | 138 +++++++++++++++++- 2 files changed, 138 insertions(+), 4 deletions(-) diff --git a/client/src/App.tsx b/client/src/App.tsx index 8eeb2d0..8e25d45 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -2,13 +2,15 @@ import React from "react"; import { BrowserRouter as Router, Route, Routes } from "react-router-dom"; import LandingPage from "./pages/LandingPage"; import NotFoundPage from "./pages/NotFoundPage/NotFoundPage"; -import AuthenticatedApp from "./AuthenticatedApp" +import AuthenticatedApp from "./AuthenticatedApp"; +import RegistrationPage from "./pages/RegistrationPage/RegistrationPage"; const App = (): JSX.Element => { return ( } /> + } /> } /> } /> diff --git a/client/src/pages/RegistrationPage/RegistrationPage.tsx b/client/src/pages/RegistrationPage/RegistrationPage.tsx index 9e1937c..002e491 100644 --- a/client/src/pages/RegistrationPage/RegistrationPage.tsx +++ b/client/src/pages/RegistrationPage/RegistrationPage.tsx @@ -1,10 +1,142 @@ -import React from "react"; +import React, { useState, useEffect } from "react"; +import { useLocation } from "react-router-dom"; const RegistrationPage: React.FC = () => { + const [formData, setFormData] = useState({ + firstName: "", + lastName: "", + email: "", + password: "", + }); + + const location = useLocation(); + + const query = new URLSearchParams(location.search); + const token = query.get("token"); + + const handleChange = (e: React.ChangeEvent) => { + setFormData({ + ...formData, + [e.target.name]: e.target.value, + }); + }; + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + if (!token) { + console.error("Token is missing."); + return; //TODO Display error feedback for user + } + try { + const response = await fetch(`/api/users/register?token=${token}`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(formData), + }); + const data = await response.json(); + if (!response.ok) { + throw new Error( + data.message || "An error occurred during registration." + ); + } + console.log("Registration successful", data); + //TODO Handle redirect here + } catch (error) { + //TODO Needs better error handling + console.error("Registration error:", error); + } + }; + return (
-

Main Page

-

Registration Form Goes Here!

+
+

+ Registration Page +

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
); };