-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignup.jsx
More file actions
148 lines (133 loc) · 4.25 KB
/
Signup.jsx
File metadata and controls
148 lines (133 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import React, { useState, useEffect } from "react";
import { Link, useNavigate } from "react-router-dom";
import { auth } from "../../api";
import "../../styles/auth.css";
const taglines = [
"Sign up to explore and collect art from talented creators 🌟",
"Discover one-of-a-kind artworks tailored for you 🖼️",
"Own pieces that inspire and bring joy ✨",
"Start your journey as an art collector today 💡",
];
const Signup = () => {
const [currentTagline, setCurrentTagline] = useState(0);
const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false);
const [error, setError] = useState("");
const [formData, setFormData] = useState({
name: "",
email: "",
password: "",
});
const navigate = useNavigate();
useEffect(() => {
const interval = setInterval(() => {
setCurrentTagline((prev) => (prev + 1) % taglines.length);
}, 3000);
return () => clearInterval(interval);
}, []);
const handleChange = (e) => {
// Clear error when user starts typing
if (error) setError("");
setFormData({
...formData,
[e.target.name]: e.target.value,
});
};
const validatePassword = (password) => {
if (password.length < 6) {
return "Password must be at least 6 characters long";
}
return null;
};
const handleSignup = async (e) => {
e.preventDefault();
setLoading(true);
setError("");
// Validate password
const passwordError = validatePassword(formData.password);
if (passwordError) {
setError(passwordError);
setLoading(false);
return;
}
try {
await auth.signup(formData);
setSuccess(true);
setTimeout(() => {
navigate("/explore");
}, 1200);
} catch (err) {
setError(err.message || "Signup failed. Please try again.");
setLoading(false);
}
};
return (
<div className="auth-container">
<div className="glow-bg"></div>
<div className="auth-card">
{!success ? (
<>
<h1 className="auth-title">Buyer Signup</h1>
<p className="auth-subtext">{taglines[currentTagline]}</p>
{error && (
<p className="error-text" role="alert" aria-live="polite">
{error}
</p>
)}
<form className="auth-form" onSubmit={handleSignup}>
<input
type="text"
name="name"
placeholder="Full Name"
value={formData.name}
onChange={handleChange}
required
aria-label="Full Name"
disabled={loading}
/>
<input
type="email"
name="email"
placeholder="Email Address"
value={formData.email}
onChange={handleChange}
required
aria-label="Email Address"
disabled={loading}
/>
<input
type="password"
name="password"
placeholder="Password (min. 6 characters)"
value={formData.password}
onChange={handleChange}
required
minLength="6"
aria-label="Password"
disabled={loading}
/>
<button
type="submit"
className={`auth-btn ${loading ? "loading" : ""}`}
disabled={loading}
>
{loading ? "Signing up..." : "Sign Up"}
</button>
</form>
<p className="auth-link">
Already have an account? <Link to="/login">Login</Link>
</p>
<p className="auth-link">
Are you an artist? <Link to="/artist-signup">Artist Signup</Link>
</p>
</>
) : (
<div className="success-message" role="status" aria-live="polite">
<span className="checkmark">✓</span> Signup Successful!
</div>
)}
</div>
</div>
);
};
export default Signup;