import React, { useState, FormEvent } from "react"; import { useNavigate } from "react-router-dom"; import { LogoIconLarge } from "../components/icons/Logo"; import { EyeIcon } from "../components/icons/ExportCommonIcons"; import { useLoadingProgress, useOrganization, useUserName } from "../store/store"; import { signInApi } from "../services/factoryBuilder/signInSignUp/signInApi"; import { signUpApi } from "../services/factoryBuilder/signInSignUp/signUpApi"; const UserAuth: React.FC = () => { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [showPassword, setShowPassword] = useState(false); const [error, setError] = useState(""); const [isSignIn, setIsSignIn] = useState(true); const { userName, setUserName } = useUserName(); const { setOrganization } = useOrganization(); const { setLoadingProgress } = useLoadingProgress(); const navigate = useNavigate(); const handleLogin = async (e: FormEvent) => { e.preventDefault(); const organization = (email.split("@")[1]).split(".")[0]; try { const res = await signInApi(email, password, organization); if (res.message === "login successfull") { setError(""); setOrganization(organization); setUserName(res.name); localStorage.setItem("userId", res.userId); localStorage.setItem("email", res.email); localStorage.setItem("userName", res.name); if (res.isShare) { setLoadingProgress(1); navigate("/Project"); } } else if (res.message === "User Not Found!!! Kindly signup...") { setError("Account not found"); } } catch (error) { } }; const handleRegister = async (e: FormEvent) => { e.preventDefault(); if (email && password && userName) { setError(""); try { const organization = (email.split("@")[1]).split(".")[0]; const res = await signUpApi(userName, email, password, organization); if (res.message === "New User created") { setIsSignIn(true); } if (res.message === "User already exists") { setError("User already exists"); } } catch (error) { } } else { setError("Please fill all the fields!"); } }; return ( <>

Welcome to Dwinzo

{isSignIn ? ( <> Don’t have an account?{" "} setIsSignIn(false)} style={{ cursor: "pointer" }} > Register here! ) : ( <> Already have an account?{" "} setIsSignIn(true)} style={{ cursor: "pointer" }} > Login here! )}

{error &&
🛈 {error}
}
{!isSignIn && ( setUserName(e.target.value)} required /> )} setEmail(e.target.value)} required />
setPassword(e.target.value)} required />
{!isSignIn && (
I have read and agree to the terms of service
)}

By signing up for, or logging into, an account, you agree to our{" "} navigate("/privacy")} style={{ cursor: "pointer" }} > privacy policy {" "} &{" "} navigate("/terms")} style={{ cursor: "pointer" }} > terms of service {" "} whether you read them or not. You can also find these terms on our website.

); }; export default UserAuth;