Spaces:
Runtime error
Runtime error
Download frontend/src/pages/Signup.jsx from cuiconnect/backend: direct link, hf CLI and curl.
- Browser
- Download file 6.52 kB
-
https://huggingface.co/spaces/cuiconnect/backend/resolve/main/frontend/src/pages/Signup.jsx
- Command line
-
hf download hf://spaces/cuiconnect/backend/frontend/src/pages/Signup.jsx
-
curl -L -o Signup.jsx https://huggingface.co/spaces/cuiconnect/backend/resolve/main/frontend/src/pages/Signup.jsx
6.52 kB
| import { useState } from 'react' | |
| import { Link, useNavigate } from 'react-router-dom' | |
| import { signup } from '../api/auth' | |
| import AuthLayout from './AuthLayout' | |
| function UserIcon({ className = '' }) { | |
| return ( | |
| <svg className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" aria-hidden> | |
| <path | |
| strokeLinecap="round" | |
| strokeLinejoin="round" | |
| d="M15.75 6a3.75 3.75 0 11-7.5 0 3.75 3.75 0 017.5 0zM4.501 20.118a7.5 7.5 0 0114.998 0A17.933 17.933 0 0112 21.75c-2.676 0-5.216-.584-7.499-1.632z" | |
| /> | |
| </svg> | |
| ) | |
| } | |
| function EnvelopeIcon({ className = '' }) { | |
| return ( | |
| <svg className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" aria-hidden> | |
| <path | |
| strokeLinecap="round" | |
| strokeLinejoin="round" | |
| d="M21.75 6.75v10.5a2.25 2.25 0 01-2.25 2.25h-15a2.25 2.25 0 01-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25m19.5 0v.243a2.25 2.25 0 01-1.07 1.916l-7.5 4.615a2.25 2.25 0 01-2.36 0L3.32 8.91a2.25 2.25 0 01-1.07-1.916V6.75" | |
| /> | |
| </svg> | |
| ) | |
| } | |
| function LockIcon({ className = '' }) { | |
| return ( | |
| <svg className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" aria-hidden> | |
| <path | |
| strokeLinecap="round" | |
| strokeLinejoin="round" | |
| d="M16.5 10.5V6.75a4.5 4.5 0 10-9 0v3.75m-.75 11.25h10.5a2.25 2.25 0 002.25-2.25v-6.75a2.25 2.25 0 00-2.25-2.25H6.75a2.25 2.25 0 00-2.25 2.25v6.75a2.25 2.25 0 002.25 2.25z" | |
| /> | |
| </svg> | |
| ) | |
| } | |
| export default function Signup() { | |
| const navigate = useNavigate() | |
| const [email, setEmail] = useState('') | |
| const [password, setPassword] = useState('') | |
| const [fullName, setFullName] = useState('') | |
| const [error, setError] = useState('') | |
| const [loading, setLoading] = useState(false) | |
| async function handleSubmit(e) { | |
| e.preventDefault() | |
| setError('') | |
| if (password.length < 6) { | |
| setError('Password must be at least 6 characters.') | |
| return | |
| } | |
| setLoading(true) | |
| try { | |
| await signup({ email: email.trim(), password, full_name: fullName }) | |
| navigate('/login', { | |
| replace: false, | |
| state: { email: email.trim(), registered: true }, | |
| }) | |
| } catch (err) { | |
| setError(err.message || 'Signup failed') | |
| } finally { | |
| setLoading(false) | |
| } | |
| } | |
| return ( | |
| <AuthLayout | |
| brandTo="/signup" | |
| title="Create account" | |
| subtitle="Register to use CUI Connect." | |
| > | |
| <form onSubmit={handleSubmit} className="flex flex-col gap-5 sm:gap-6"> | |
| {error ? ( | |
| <div | |
| role="alert" | |
| className="rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-800" | |
| > | |
| {error} | |
| </div> | |
| ) : null} | |
| <div className="flex flex-col gap-1.5"> | |
| <label htmlFor="signup-name" className="text-sm font-medium text-slate-700"> | |
| Full name <span className="font-normal text-slate-500">(optional)</span> | |
| </label> | |
| <div className="relative"> | |
| <UserIcon className="pointer-events-none absolute left-3.5 top-1/2 h-5 w-5 -translate-y-1/2 text-slate-400" /> | |
| <input | |
| id="signup-name" | |
| name="full_name" | |
| type="text" | |
| autoComplete="name" | |
| value={fullName} | |
| onChange={(e) => setFullName(e.target.value)} | |
| className="min-h-[48px] w-full rounded-xl border border-slate-300 bg-white py-3 pl-11 pr-4 text-base text-slate-900 shadow-sm outline-none transition-colors focus:border-comsats-blue focus:ring-2 focus:ring-comsats-blue/20 sm:text-sm" | |
| /> | |
| </div> | |
| </div> | |
| <div className="flex flex-col gap-1.5"> | |
| <label htmlFor="signup-email" className="text-sm font-medium text-slate-700"> | |
| </label> | |
| <div className="relative"> | |
| <EnvelopeIcon className="pointer-events-none absolute left-3.5 top-1/2 h-5 w-5 -translate-y-1/2 text-slate-400" /> | |
| <input | |
| id="signup-email" | |
| name="email" | |
| type="email" | |
| autoComplete="email" | |
| required | |
| value={email} | |
| onChange={(e) => setEmail(e.target.value)} | |
| className="min-h-[48px] w-full rounded-xl border border-slate-300 bg-white py-3 pl-11 pr-4 text-base text-slate-900 shadow-sm outline-none transition-colors focus:border-comsats-blue focus:ring-2 focus:ring-comsats-blue/20 sm:text-sm" | |
| /> | |
| </div> | |
| </div> | |
| <div className="flex flex-col gap-1.5"> | |
| <label htmlFor="signup-password" className="text-sm font-medium text-slate-700"> | |
| Password | |
| </label> | |
| <div className="relative"> | |
| <LockIcon className="pointer-events-none absolute left-3.5 top-1/2 h-5 w-5 -translate-y-1/2 text-slate-400" /> | |
| <input | |
| id="signup-password" | |
| name="password" | |
| type="password" | |
| autoComplete="new-password" | |
| required | |
| minLength={6} | |
| value={password} | |
| onChange={(e) => setPassword(e.target.value)} | |
| className="min-h-[48px] w-full rounded-xl border border-slate-300 bg-white py-3 pl-11 pr-4 text-base text-slate-900 shadow-sm outline-none transition-colors focus:border-comsats-blue focus:ring-2 focus:ring-comsats-blue/20 sm:text-sm" | |
| /> | |
| </div> | |
| <p className="text-xs text-slate-500">Minimum 6 characters.</p> | |
| </div> | |
| <button | |
| type="submit" | |
| disabled={loading} | |
| className="mt-1 flex min-h-[48px] w-full items-center justify-center rounded-xl bg-gradient-to-r from-comsats-purple to-[#3d2469] px-4 py-3 text-sm font-semibold text-white shadow-md shadow-comsats-purple/25 transition-all hover:brightness-105 focus:outline-none focus-visible:ring-2 focus-visible:ring-comsats-blue focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-60" | |
| > | |
| {loading ? 'Creating account…' : 'Sign up'} | |
| </button> | |
| <p className="text-center text-sm text-slate-600"> | |
| Already registered?{' '} | |
| <Link | |
| to="/login" | |
| className="font-semibold text-comsats-blue underline-offset-2 hover:underline" | |
| > | |
| Sign in | |
| </Link> | |
| </p> | |
| </form> | |
| </AuthLayout> | |
| ) | |
| } | |