diff --git a/app/setup/SetupPage.tsx b/app/setup/SetupPage.tsx index 694a75b..ea615df 100644 --- a/app/setup/SetupPage.tsx +++ b/app/setup/SetupPage.tsx @@ -2,10 +2,23 @@ import { useState } from "react" import { Mail, User, Lock } from "lucide-react" +import ErrorToast from "@/components/Error" +import { useRouter } from "next/navigation" + +import axios from "axios" export default function SetupPage() { + const router = useRouter() const [step, setStep] = useState(1) + const [email, setEmail] = useState("") + const [username, setUsername] = useState("") + const [name, setName] = useState("") + const [password, setPassword] = useState("") + const [passwordConfirm, setPasswordConfirm] = useState("") + + const [error, setError] = useState("") + const handleNextStep = () => { setStep(2) } @@ -14,23 +27,46 @@ export default function SetupPage() { setStep(1) } - return ( -
-
-
-
    -
  • Create account
  • -
  • Next Steps
  • -
-
+ const handleComplete = async () => { + if (password !== passwordConfirm) { + setError("Passwords do not match") + return + } + try { + const response = await axios.post("/api/user/create", { + email, + username, + name, + password + }) + if (response.status === 201) { + router.push("/") + } + } catch (error: any) { + setError(error.response.data.error) + } + } + + -
-
- {step === 1 && ( + return ( +
+
+
+
+
    +
  • Create account
  • +
  • Next Steps
  • +
+
+ +
+
+ {step === 1 && (

Create account

-

Please create an account to get started

+

Please create an account to get started.

@@ -38,7 +74,7 @@ export default function SetupPage() { Email
Enter valid email address
@@ -48,7 +84,7 @@ export default function SetupPage() { Username
Enter valid username
@@ -57,7 +93,7 @@ export default function SetupPage() { Full Name
Enter valid full name
@@ -70,7 +106,7 @@ export default function SetupPage() { Password
Enter valid password
@@ -79,7 +115,7 @@ export default function SetupPage() { Repeat Password
Enter valid repeat password
@@ -114,7 +150,7 @@ export default function SetupPage() { - +
)} @@ -122,5 +158,7 @@ export default function SetupPage() {
+ setError("")} /> +
) } diff --git a/components/Error.tsx b/components/Error.tsx new file mode 100644 index 0000000..5b6cac0 --- /dev/null +++ b/components/Error.tsx @@ -0,0 +1,46 @@ +"use client"; + +import { useEffect } from "react"; + +type ErrorToastProps = { + message: string; + show: boolean; + onClose: () => void; +}; + +export default function ErrorToast({ message, show, onClose }: ErrorToastProps) { + useEffect(() => { + if (show) { + const timer = setTimeout(() => { + onClose(); + }, 5000); + return () => clearTimeout(timer); + } + }, [show, onClose]); + + if (!show) return null; + + return ( +
+
+ + + +
+ ERROR: + {message} +
+
+
+ ); +} \ No newline at end of file