import { useState } from "react"; import { useNavigate } from "react-router-dom"; import axiosapi from "../../api/AuthenticationApi"; import { useCallback } from "react"; import Particles from "react-tsparticles"; import { loadFull } from "tsparticles"; import { FcGoogle } from "react-icons/fc"; import { useGoogleLogin } from "@react-oauth/google"; import { useAuth } from "src/hooks/AuthHooks"; function Copyright(props) { return (
{"Copyright © "} TurTask {" "} {new Date().getFullYear()} {"."}
); } export default function SignUp() { const Navigate = useNavigate(); const { setIsAuthenticated } = useAuth; const [formData, setFormData] = useState({ email: "", username: "", password: "", }); const [error, setError] = useState(null); const [isSubmitting, setIsSubmitting] = useState(false); const handleSubmit = async (e) => { e.preventDefault(); setIsSubmitting(true); setError(null); try { axiosapi.createUser(formData); } catch (error) { console.error("Error creating user:", error); setError("Registration failed. Please try again."); } finally { setIsSubmitting(false); } Navigate("/login"); }; const handleChange = (e) => { const { name, value } = e.target; setFormData({ ...formData, [name]: value }); console.log(formData); }; { /* Particles Loader*/ } const particlesInit = useCallback(async (engine) => { console.log(engine); await loadFull(engine); }, []); const particlesLoaded = useCallback(async (container) => { console.log(container); }, []); const googleLoginImplicit = useGoogleLogin({ flow: "auth-code", redirect_uri: "postmessage", onSuccess: async (response) => { try { const loginResponse = await axiosapi.googleLogin(response.code); if (loginResponse && loginResponse.data) { const { access_token, refresh_token } = loginResponse.data; localStorage.setItem("access_token", access_token); localStorage.setItem("refresh_token", refresh_token); setIsAuthenticated(true); Navigate("/"); } } catch (error) { console.error("Error with the POST request:", error); setIsAuthenticated(false); } }, onError: (errorResponse) => console.log(errorResponse), }); return (
{/* Particles Container */}
{/* Register Form */}

Signup

{/* Email Input */}
{/* Username Input */}
{/* Password Input */}


{/* Signups Button */}
OR
{/* Login with Google Button */} {/* Already have an account? */}
Already have an account?
); }