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 +

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