/* eslint-disable @next/next/no-img-element */ import {toast, ToastContainer} from "react-toastify"; import {useState} from "react"; import Head from "next/head"; import useUser from "@/hooks/useUser"; import Button from "@/components/Low/Button"; import {BsArrowRepeat} from "react-icons/bs"; import Link from "next/link"; import Input from "@/components/Low/Input"; import axios from "axios"; export default function Register() { const [name, setName] = useState(""); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [isLoading, setIsLoading] = useState(false); const {mutateUser} = useUser({ redirectTo: "/", redirectIfFound: true, }); const register = (e: any) => { e.preventDefault(); if (confirmPassword !== password) { toast.error("Your passwords do not match!", {toastId: "password-not-match"}); return; } setIsLoading(true); axios .post("/api/register", {name, email, password, profilePicture: "/defaultAvatar.png"}) .then((response) => mutateUser(response.data.user)) .catch((error) => { console.log(error.response.data); if (error.response.status === 401) { toast.error("There is already a user with that e-mail!"); return; } toast.error("There was something wrong, please try again!"); }) .finally(() => setIsLoading(false)); }; return ( <>