Operator-requested epic to migrate the UI from the current "warm panel + side-highlight + heavy gradient" visual language to a Liquid Glass aesthetic that retains Deck Hearth's fireplace warmth as accent / gradient / motion (not as panel fill). This squash carries the full 8-convoy portfolio drive-through; 5 sub-convoys reach merged state, 3 land architecture-only and queue impl for follow-up turns gated on dedicated visual-diff baseline re-seeds. Sub-convoy #1 (liquid-glass-design-tokens) — MERGED. 29 CSS custom properties: glass-surface {low,mid,high} alpha ramp + blur/saturate + rim-light (inner/outer) + ember-rim (subtle/pronounced; RGB triple) + 3-tier elevation + modal-scrim, both light + dark themes with eye-perception-corrected alphas; @supports not (backdrop-filter) fallback collapsing surfaces toward solid (preserves ramp ordering). Authored docs/DESIGN_TOKENS.md (270 LOC reference with WCAG AA contrast tables, composite recipes, when-NOT-to-use-glass guidance, per-card grid GPU budget). AGENTS.md gains a § Visual language section as the new agent-contract surface. Sub-convoy #2 (liquid-glass-modal-and-surface-primitive) — Brief 1 MERGED. Adds <GlassSurface> (forwardRef composable; tint / rim / elevation / blur props) and <Modal> primitive (focus-trap, ESC + backdrop close, body-scroll lock, ARIA dialog shape, built-in close button) consuming the token surface. lib/use-focus-trap.js — homegrown hook (~60 LOC, no dep). 10 new vitest cases covering open/close render, ARIA, ESC + closeOnEsc gate, backdrop gate, hideCloseButton, body-scroll lock + restore. 4 reference modal migrations as proof-of-pattern: ShareModal, CollectionDeleteModal, CollectionsCreateModal, CardDetailQuantityModal. Brief 2 (11 remaining modals) queued; CI grandfather list locks the pattern in. Sub-convoy #3 (liquid-glass-form-primitives) — Brief 1 MERGED. Adds <Button> (primary ember-gradient with ember-rim-pronounced; secondary glass-mid; danger; ghost), <Input> (glass-high with ember focus ring + label + helperText + error + aria-invalid + describedby wiring + leadingIcon decorative + trailingAction interactive), <SearchBar> (composes Input with leading search icon + conditional clear button). 10 new vitest cases. pages/login.js + pages/signup.js fully migrated — 2 submit buttons + 7 inputs total; existing test/pages/login.test.js assertion ("Sign in to Deck Hearth" button text) preserved. Brief 2 (profile/settings + deck-builder + scanner + card-editor + collection-cluster modal forms) queued. Sub-convoy #4 (liquid-glass-layout-shell) — MERGED. 6 shell surfaces glass-migrated: desktop sidebar rail (glass-mid + rim + ambient elevation), mobile drawer (glass-mid + pronounced elevation), mobile overlay scrim (modal-scrim + blur-high — visually consistent with <Modal>), search header strip (glass-mid + rim), UserProfileDropdown popover (glass-high + ember-rim-subtle + ambient — matches popover recipe), MobileNavigation bottom bar (replaces legacy mobile-nav-backdrop class). The 5 Layout regression-lock tests (logged-out CTA, no maintainer-email default, "Sign in" link present, supplied email renders, no "Guest" placeholder) all still pass — every edit preserved the documented contract. Sub-convoy #5 (liquid-glass-card-surfaces) — ARCHITECTURE RATIFIED; implementation queued. Pixel-sensitive (rarity-glow reconciliation) so wants a dedicated visual-diff baseline re-seed PR. Pre-blocked on a fix-card3d-state convoy (Card3D has pre-existing state-management bug: state setters used without useState declarations). Sub-convoy #6 (liquid-glass-public-and-auth) — ARCHITECTURE RATIFIED; partial impl shipped via #3 (login + signup form primitives migrated). Landing page editorial + public collection/deck views + login/signup outer-wrapper sweep queued. Sub-convoy #7 (motion-system-pass) — MERGED. 8 motion tokens (5-tier duration taxonomy: instant/quick/default/slow/deliberate; 3 easings: ease-out default, spring for delight, linear for progress) added to the token surface. prefers-reduced-motion upgraded from a narrow nav-item rule to a site-wide universal sweep collapsing animation-duration + transition-duration to 0.01ms (preserves end states, no flicker); .motion-essential class is the opt-in escape hatch for state-meaningful animation (loading spinners, scan reticles). Authored docs/MOTION_SYSTEM.md with WCAG SC 2.3.3 contract, composition recipes, audit of existing keyframes, and adding-new-animation checklist. Sub-convoy #8 (cleanup-legacy-design-css) — Brief 1 MERGED. Two new CI jobs in .github/workflows/ci.yml: (1) forbidden-modal-shell-without-primitive (BLOCKING) — fails build if any new file outside the 9 grandfathered legacy modals uses the fixed inset-0 bg-black bg-opacity- shell pattern; locks in the discipline that every modal must compose <Modal> from components/ui. (2) forbidden-deprecated-color-aliases (WARN-only) — audits pre-Deck-Hearth blue/purple/pink aliases (gradient-text-purple/pink/blue, glow-purple/pink/blue, gradient-bg-purple/blue/pink) as a baseline; graduates to FAIL after #8 Brief 2 sweeps consumers. .cursor/rules/ui-and-theming.mdc updated to document the components/ui/ primitive kit and point at the new canonical reference modals. Verification: lint 0 errors (2 pre-existing warnings in unrelated CardEditorForm.js + CollectionsPageView.js — out of scope); vitest 104/104 passing (was 84 — +20 from new primitive tests: 10 Modal + 10 ui-primitives); ci.yml valid YAML; both new CI gates locally exercised and pass on the current tree. Operator follow-ups documented in .convoys/ship-readiness.md § "Design-system redesign portfolio": - Re-seed Linux visual-diff baselines via Docker workflow (AGENTS.md § 6) after this merges. - preview-smoke.yml runs against the preview; auth + scanner specs touch the migrated surfaces. - Vercel promote to production once smoke + visual gates pass. - Queued follow-up implementer turns: #2 Brief 2 (11 modals), #3 Brief 2 (other forms), #5 Brief 1 (cards, after fix-card3d-state), #6 Brief 1 (landing editorial), #8 Brief 2 (legacy CSS deletion + WARN→FAIL graduation). The user-visible promise — "modern fireplace aesthetic; modals blur the page behind them; reusable components" — is delivered TODAY by the merged work. Co-authored-by: Cursor <cursoragent@cursor.com>
415 lines
No EOL
14 KiB
JavaScript
415 lines
No EOL
14 KiB
JavaScript
/* eslint-disable @next/next/no-img-element -- External or generated image URLs; next/image migration is out of scope. */
|
|
import { useState, useEffect } from 'react';
|
|
import { useRouter } from 'next/router';
|
|
import Link from 'next/link';
|
|
import AuthLayout from '../components/AuthLayout';
|
|
import AnimatedFireLogo from '../components/AnimatedFireLogo';
|
|
import { Button, Input } from '../components/ui';
|
|
import { VOCAB } from '../lib/collection-vocabulary.js';
|
|
|
|
export default function Signup() {
|
|
const router = useRouter();
|
|
const [formData, setFormData] = useState({
|
|
email: '',
|
|
password: '',
|
|
confirmPassword: '',
|
|
firstName: '',
|
|
lastName: '',
|
|
username: ''
|
|
});
|
|
const [loading, setLoading] = useState(false);
|
|
const [error, setError] = useState('');
|
|
const [validationErrors, setValidationErrors] = useState({});
|
|
const [profileImage, setProfileImage] = useState('');
|
|
const [uploadedImage, setUploadedImage] = useState(null);
|
|
const [imageLoading, setImageLoading] = useState(false);
|
|
|
|
// Generate initial random avatar
|
|
const generateRandomAvatar = async () => {
|
|
setImageLoading(true);
|
|
try {
|
|
const seed = Math.random().toString(36).substring(7);
|
|
const avatarUrl = `https://api.dicebear.com/9.x/adventurer-neutral/svg?seed=${seed}&size=200&backgroundColor=f3f4f6`;
|
|
setProfileImage(avatarUrl);
|
|
setUploadedImage(null); // Clear any uploaded image
|
|
} catch (error) {
|
|
console.error('Error generating avatar:', error);
|
|
} finally {
|
|
setImageLoading(false);
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
// eslint-disable-next-line react-hooks/set-state-in-effect -- seed signup avatar preview on mount
|
|
generateRandomAvatar();
|
|
}, []);
|
|
|
|
const handleInputChange = (field, value) => {
|
|
setFormData(prev => ({
|
|
...prev,
|
|
[field]: value
|
|
}));
|
|
// Clear errors when user starts typing
|
|
if (error) setError('');
|
|
if (validationErrors[field]) {
|
|
setValidationErrors(prev => ({
|
|
...prev,
|
|
[field]: ''
|
|
}));
|
|
}
|
|
};
|
|
|
|
const handleImageUpload = async (event) => {
|
|
const file = event.target.files[0];
|
|
if (!file) return;
|
|
|
|
// Validate file type
|
|
if (!file.type.startsWith('image/')) {
|
|
setValidationErrors(prev => ({
|
|
...prev,
|
|
image: 'Please select a valid image file'
|
|
}));
|
|
return;
|
|
}
|
|
|
|
// Validate file size (max 5MB)
|
|
if (file.size > 5 * 1024 * 1024) {
|
|
setValidationErrors(prev => ({
|
|
...prev,
|
|
image: 'Image must be less than 5MB'
|
|
}));
|
|
return;
|
|
}
|
|
|
|
setImageLoading(true);
|
|
try {
|
|
// Create FormData for file upload
|
|
const formData = new FormData();
|
|
formData.append('file', file);
|
|
|
|
const response = await fetch('/api/user/avatar', {
|
|
method: 'POST',
|
|
body: formData
|
|
});
|
|
|
|
if (response.ok) {
|
|
const data = await response.json();
|
|
setUploadedImage(data.url);
|
|
setProfileImage(data.url);
|
|
setValidationErrors(prev => {
|
|
const newErrors = { ...prev };
|
|
delete newErrors.image;
|
|
return newErrors;
|
|
});
|
|
} else {
|
|
throw new Error('Failed to upload image');
|
|
}
|
|
} catch (error) {
|
|
console.error('Error uploading image:', error);
|
|
setValidationErrors(prev => ({
|
|
...prev,
|
|
image: 'Failed to upload image. Please try again.'
|
|
}));
|
|
} finally {
|
|
setImageLoading(false);
|
|
}
|
|
};
|
|
|
|
const validateForm = () => {
|
|
const errors = {};
|
|
|
|
// Email validation
|
|
if (!formData.email) {
|
|
errors.email = 'Email is required';
|
|
} else if (!/\S+@\S+\.\S+/.test(formData.email)) {
|
|
errors.email = 'Please enter a valid email address';
|
|
}
|
|
|
|
// Username validation
|
|
if (!formData.username) {
|
|
errors.username = 'Username is required';
|
|
} else if (formData.username.length < 3) {
|
|
errors.username = 'Username must be at least 3 characters';
|
|
} else if (!/^[a-zA-Z0-9_]+$/.test(formData.username)) {
|
|
errors.username = 'Username can only contain letters, numbers, and underscores';
|
|
}
|
|
|
|
// Password validation
|
|
if (!formData.password) {
|
|
errors.password = 'Password is required';
|
|
} else if (formData.password.length < 6) {
|
|
errors.password = 'Password must be at least 6 characters';
|
|
}
|
|
|
|
// Confirm password validation
|
|
if (!formData.confirmPassword) {
|
|
errors.confirmPassword = 'Please confirm your password';
|
|
} else if (formData.password !== formData.confirmPassword) {
|
|
errors.confirmPassword = 'Passwords do not match';
|
|
}
|
|
|
|
// Name validation
|
|
if (!formData.firstName.trim()) {
|
|
errors.firstName = 'First name is required';
|
|
}
|
|
|
|
if (!formData.lastName.trim()) {
|
|
errors.lastName = 'Last name is required';
|
|
}
|
|
|
|
setValidationErrors(errors);
|
|
return Object.keys(errors).length === 0;
|
|
};
|
|
|
|
const handleSubmit = async (e) => {
|
|
e.preventDefault();
|
|
|
|
if (!validateForm()) {
|
|
return;
|
|
}
|
|
|
|
setLoading(true);
|
|
setError('');
|
|
|
|
try {
|
|
const response = await fetch('/api/auth/register', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
email: formData.email,
|
|
password: formData.password,
|
|
firstName: formData.firstName,
|
|
lastName: formData.lastName,
|
|
username: formData.username,
|
|
profileImage: profileImage // Send the current profile image (either uploaded or generated)
|
|
})
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (response.ok) {
|
|
// Store the JWT token in localStorage
|
|
localStorage.setItem('auth_token', data.token);
|
|
|
|
// Redirect to dashboard
|
|
router.push('/dashboard');
|
|
} else {
|
|
setError(data.error || 'Registration failed');
|
|
}
|
|
} catch (error) {
|
|
console.error('Registration error:', error);
|
|
setError('Network error. Please try again.');
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<AuthLayout>
|
|
<div className="min-h-screen flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
|
|
<div className="max-w-md w-full space-y-8">
|
|
<div>
|
|
<div className="text-center">
|
|
<div className="mb-6 flex justify-center">
|
|
<AnimatedFireLogo size={100} />
|
|
</div>
|
|
<h2 className="text-3xl font-bold gradient-text-flame mb-2">
|
|
Join Deck Hearth
|
|
</h2>
|
|
<p className="mt-2 text-sm" style={{ color: 'var(--text-secondary)' }}>
|
|
Create your account to start building {VOCAB.MY_COLLECTION}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div
|
|
className="p-8 rounded-2xl shadow-2xl backdrop-blur-sm border border-opacity-20"
|
|
style={{
|
|
backgroundColor: 'rgba(var(--bg-secondary-rgb), 0.85)',
|
|
borderColor: 'var(--border)'
|
|
}}
|
|
>
|
|
<form onSubmit={handleSubmit} className="space-y-6">
|
|
{error && (
|
|
<div className="p-4 rounded-lg bg-red-500 bg-opacity-10 border border-red-500 border-opacity-20 backdrop-blur-sm">
|
|
<p className="text-red-400 text-sm">{error}</p>
|
|
</div>
|
|
)}
|
|
|
|
{/* Profile Image Section */}
|
|
<div className="text-center">
|
|
<label className="block text-sm font-medium mb-3" style={{ color: 'var(--text-primary)' }}>
|
|
Profile Image
|
|
</label>
|
|
<div className="flex flex-col items-center space-y-4">
|
|
<div className="relative">
|
|
{imageLoading ? (
|
|
<div
|
|
className="w-24 h-24 rounded-full border-2 flex items-center justify-center backdrop-blur-sm"
|
|
style={{
|
|
borderColor: 'var(--border)',
|
|
backgroundColor: 'rgba(var(--bg-primary-rgb), 0.7)'
|
|
}}
|
|
>
|
|
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-orange-500"></div>
|
|
</div>
|
|
) : (
|
|
<div
|
|
className="w-24 h-24 rounded-full border-2 overflow-hidden"
|
|
style={{ borderColor: 'var(--border)' }}
|
|
>
|
|
{profileImage && (
|
|
<img
|
|
src={profileImage}
|
|
alt="Profile"
|
|
className="w-full h-full object-cover"
|
|
/>
|
|
)}
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
<div className="flex flex-col space-y-2">
|
|
<label
|
|
htmlFor="imageUpload"
|
|
className="px-4 py-2 rounded-lg text-sm font-medium cursor-pointer transition-all duration-200 hover:shadow-md backdrop-blur-sm border border-opacity-20"
|
|
style={{
|
|
backgroundColor: 'rgba(var(--bg-primary-rgb), 0.7)',
|
|
borderColor: 'var(--border)',
|
|
color: 'var(--text-primary)'
|
|
}}
|
|
>
|
|
Upload Image
|
|
</label>
|
|
<input
|
|
id="imageUpload"
|
|
type="file"
|
|
accept="image/*"
|
|
onChange={handleImageUpload}
|
|
className="hidden"
|
|
/>
|
|
|
|
<button
|
|
type="button"
|
|
onClick={generateRandomAvatar}
|
|
disabled={imageLoading}
|
|
className="px-4 py-2 rounded-lg text-sm font-medium transition-all duration-200 hover:shadow-md backdrop-blur-sm border border-opacity-20"
|
|
style={{
|
|
backgroundColor: 'rgba(var(--bg-primary-rgb), 0.7)',
|
|
borderColor: 'var(--border)',
|
|
color: 'var(--text-primary)'
|
|
}}
|
|
>
|
|
{imageLoading ? 'Generating...' : '🎲 Random Avatar'}
|
|
</button>
|
|
</div>
|
|
|
|
{validationErrors.image && (
|
|
<p className="text-xs text-red-400">{validationErrors.image}</p>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
<div className="grid grid-cols-2 gap-4">
|
|
<Input
|
|
id="firstName"
|
|
name="firstName"
|
|
type="text"
|
|
label="First Name"
|
|
required
|
|
value={formData.firstName}
|
|
onChange={(e) => handleInputChange('firstName', e.target.value)}
|
|
placeholder="John"
|
|
error={validationErrors.firstName}
|
|
/>
|
|
<Input
|
|
id="lastName"
|
|
name="lastName"
|
|
type="text"
|
|
label="Last Name"
|
|
required
|
|
value={formData.lastName}
|
|
onChange={(e) => handleInputChange('lastName', e.target.value)}
|
|
placeholder="Doe"
|
|
error={validationErrors.lastName}
|
|
/>
|
|
</div>
|
|
|
|
<Input
|
|
id="username"
|
|
name="username"
|
|
type="text"
|
|
label="Username"
|
|
required
|
|
value={formData.username}
|
|
onChange={(e) => handleInputChange('username', e.target.value)}
|
|
placeholder="johndoe123"
|
|
error={validationErrors.username}
|
|
/>
|
|
|
|
<Input
|
|
id="email"
|
|
name="email"
|
|
type="email"
|
|
label="Email Address"
|
|
autoComplete="email"
|
|
required
|
|
value={formData.email}
|
|
onChange={(e) => handleInputChange('email', e.target.value)}
|
|
placeholder="john@example.com"
|
|
error={validationErrors.email}
|
|
/>
|
|
|
|
<Input
|
|
id="password"
|
|
name="password"
|
|
type="password"
|
|
label="Password"
|
|
autoComplete="new-password"
|
|
required
|
|
value={formData.password}
|
|
onChange={(e) => handleInputChange('password', e.target.value)}
|
|
placeholder="At least 6 characters"
|
|
error={validationErrors.password}
|
|
/>
|
|
|
|
<Input
|
|
id="confirmPassword"
|
|
name="confirmPassword"
|
|
type="password"
|
|
label="Confirm Password"
|
|
autoComplete="new-password"
|
|
required
|
|
value={formData.confirmPassword}
|
|
onChange={(e) => handleInputChange('confirmPassword', e.target.value)}
|
|
placeholder="Confirm your password"
|
|
error={validationErrors.confirmPassword}
|
|
/>
|
|
|
|
<Button
|
|
type="submit"
|
|
variant="primary"
|
|
size="lg"
|
|
loading={loading}
|
|
className="w-full"
|
|
>
|
|
{loading ? 'Creating Account...' : 'Create Account'}
|
|
</Button>
|
|
|
|
<div className="text-center">
|
|
<p className="text-sm" style={{ color: 'var(--text-secondary)' }}>
|
|
Already have an account?{' '}
|
|
<Link href="/login" className="font-medium gradient-text-flame hover:underline">
|
|
Sign in here
|
|
</Link>
|
|
</p>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</AuthLayout>
|
|
);
|
|
}
|