forked from vitruv-tools/Vitruv-UI-Methodologist
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignUp.tsx
More file actions
220 lines (196 loc) · 5.92 KB
/
SignUp.tsx
File metadata and controls
220 lines (196 loc) · 5.92 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import React, { useState } from 'react';
import { useAuth } from '../../contexts/AuthContext';
import { SignUpCredentials } from '../../services/auth';
import './Auth.css';
interface SignUpProps {
onSignUpSuccess: (user: any) => void;
onSwitchToSignIn: () => void;
}
export function SignUp({ onSignUpSuccess, onSwitchToSignIn }: SignUpProps) {
const { signUp } = useAuth();
const [formData, setFormData] = useState<SignUpCredentials>({
username: '',
email: '',
password: '',
firstName: '',
lastName: '',
roleType: 'user',
});
const [confirmPassword, setConfirmPassword] = useState('');
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { name, value } = e.target;
setFormData(prev => ({
...prev,
[name]: value,
}));
// Clear error when user starts typing
if (error) setError(null);
};
const validateForm = (): boolean => {
if (!formData.username || !formData.email || !formData.password || !confirmPassword) {
setError('Please fill in all required fields');
return false;
}
if (formData.password !== confirmPassword) {
setError('Passwords do not match');
return false;
}
if (formData.password.length < 6) {
setError('Password must be at least 6 characters long');
return false;
}
if (!formData.email.includes('@')) {
setError('Please enter a valid email address');
return false;
}
return true;
};
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!validateForm()) {
return;
}
setIsLoading(true);
setError(null);
try {
await signUp(formData);
// Call success callback
onSignUpSuccess(formData);
} catch (err: any) {
console.error('Sign up error:', err);
setError(err.message || 'Sign up failed. Please try again.');
} finally {
setIsLoading(false);
}
};
return (
<div className="auth-container">
<div className="auth-card">
<div className="auth-header">
<h1>Create Account</h1>
<p>Join Vitruv and start modeling</p>
</div>
<form onSubmit={handleSubmit} className="auth-form">
{error && (
<div className="error-message">
<span className="error-icon">⚠️</span>
{error}
</div>
)}
<input
type="hidden"
name="roleType"
value={formData.roleType}
/>
<div className="form-row">
<div className="form-group">
<label htmlFor="firstName">First Name</label>
<input
type="text"
id="firstName"
name="firstName"
value={formData.firstName}
onChange={handleInputChange}
placeholder="First name"
disabled={isLoading}
/>
</div>
<div className="form-group">
<label htmlFor="lastName">Last Name</label>
<input
type="text"
id="lastName"
name="lastName"
value={formData.lastName}
onChange={handleInputChange}
placeholder="Last name"
disabled={isLoading}
/>
</div>
</div>
<div className="form-group">
<label htmlFor="username">Username *</label>
<input
type="text"
id="username"
name="username"
value={formData.username}
onChange={handleInputChange}
placeholder="Choose a username"
disabled={isLoading}
required
/>
</div>
<div className="form-group">
<label htmlFor="email">Email *</label>
<input
type="email"
id="email"
name="email"
value={formData.email}
onChange={handleInputChange}
placeholder="Enter your email"
disabled={isLoading}
required
/>
</div>
<div className="form-group">
<label htmlFor="password">Password *</label>
<input
type="password"
id="password"
name="password"
value={formData.password}
onChange={handleInputChange}
placeholder="Create a password"
disabled={isLoading}
required
/>
</div>
<div className="form-group">
<label htmlFor="confirmPassword">Confirm Password *</label>
<input
type="password"
id="confirmPassword"
name="confirmPassword"
value={confirmPassword}
onChange={(e) => setConfirmPassword(e.target.value)}
placeholder="Confirm your password"
disabled={isLoading}
required
/>
</div>
<button
type="submit"
className="auth-button primary"
disabled={isLoading}
>
{isLoading ? (
<span className="loading-spinner">
<div className="spinner"></div>
Creating Account...
</span>
) : (
'Create Account'
)}
</button>
</form>
<div className="auth-footer">
<p>
Already have an account?{' '}
<button
type="button"
className="link-button"
onClick={onSwitchToSignIn}
disabled={isLoading}
>
Sign In
</button>
</p>
</div>
</div>
</div>
);
}