Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | /**
* SelfRegistration — full-screen self-service account creation form.
*
* Mirrors the Login component's full-screen layout (product area / card / org
* brand area). The component is prop-driven: it does not call the backend
* itself — the app/suite wires `onRegister` (via the auth orchestrator) and
* `onGoogle` (OAuth redirect).
*/
import './SelfRegistration.css';
import {InputText, Message, Password} from '../../primereact/index.js';
import React, {useState} from 'react';
import {Button} from '../Button/Button.js';
import {SocialLoginButton} from '../SocialLoginButton/SocialLoginButton.js';
export interface ISelfRegistrationCredentials {
emailAddress: string;
password: string;
firstName: string;
middleName?: string;
lastName: string;
birthDate?: string;
gender?: string;
nationality?: string;
occupation?: string;
}
export interface ISelfRegistrationProps {
onRegister: (credentials: ISelfRegistrationCredentials) => Promise<void>;
/** Starts the Google OAuth flow (window redirect). Optional. */
onGoogle?: () => Promise<void> | void;
/** Return to the login screen. Optional. */
onBack?: () => void;
title?: string;
logoIcon?: string;
logoUrl?: string;
orgTitle?: string;
orgIcon?: string;
orgLogoUrl?: string;
/** External error to display above the form. */
error?: string;
loading?: boolean;
/** Label for the submit button. Default: 'Create account'. */
submitLabel?: string;
}
export function SelfRegistration({
onRegister,
onGoogle,
onBack,
title,
logoIcon = 'pi pi-user-plus',
logoUrl,
orgTitle,
orgIcon = 'pi pi-building',
orgLogoUrl,
error: externalError,
loading: externalLoading,
submitLabel = 'Create account',
}: ISelfRegistrationProps) {
const [firstName, setFirstName] = useState('');
const [lastName, setLastName] = useState('');
const [emailAddress, setEmailAddress] = useState('');
const [password, setPassword] = useState('');
const [confirmPassword, setConfirmPassword] = useState('');
const [error, setError] = useState('');
const [loading, setLoading] = useState(false);
const isLoading = externalLoading ?? loading;
const displayError = externalError ?? error;
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setError('');
if (!firstName.trim()) {
setError('First name is required');
return;
}
if (!lastName.trim()) {
setError('Last name is required');
return;
}
if (!emailAddress.trim()) {
setError('Email address is required');
return;
}
if (password.length < 8) {
setError('Password must be at least 8 characters');
return;
}
if (password !== confirmPassword) {
setError('Passwords do not match');
return;
}
setLoading(true);
try {
await onRegister({
emailAddress: emailAddress.trim(),
password,
firstName: firstName.trim(),
lastName: lastName.trim(),
});
} catch (err) {
setError(String((err as Error).message ?? err));
} finally {
setLoading(false);
}
};
const handleGoogle = async () => {
if (!onGoogle) return;
try {
await onGoogle();
} catch {
/* ignore — navigation may be blocked; parent shows its own error */
}
};
return (
<div className="blong-self-registration p-component">
{/* Product area — 1fr row above the card */}
<div className="blong-self-registration__top">
{(title || logoUrl || logoIcon) && (
<div className="blong-self-registration__brand">
{logoUrl ? (
<img
src={logoUrl}
alt={title ?? 'logo'}
className="blong-self-registration__brand-img"
/>
) : (
<i className={`blong-self-registration__brand-icon ${logoIcon}`} />
)}
{title && (
<span className="blong-self-registration__brand-name">{title}</span>
)}
</div>
)}
</div>
{/* Registration card — auto-height middle row */}
<div className="blong-self-registration__card">
<p className="blong-self-registration__card-heading">Create your account</p>
{displayError && (
<Message
severity="error"
text={displayError}
className="blong-self-registration__error"
/>
)}
<form
className="blong-self-registration__form"
onSubmit={e => void handleSubmit(e)}
>
<div className="blong-self-registration__row">
<div className="blong-field">
<label
htmlFor="register-first-name"
className="blong-field__label"
>
First Name
</label>
<InputText
id="register-first-name"
name="firstName"
value={firstName}
onChange={e => setFirstName(e.target.value)}
className="w-full"
autoFocus
disabled={isLoading}
/>
</div>
<div className="blong-field">
<label
htmlFor="register-last-name"
className="blong-field__label"
>
Last Name
</label>
<InputText
id="register-last-name"
name="lastName"
value={lastName}
onChange={e => setLastName(e.target.value)}
className="w-full"
disabled={isLoading}
/>
</div>
</div>
<div className="blong-field">
<label htmlFor="register-email" className="blong-field__label">
Email Address
</label>
<InputText
id="register-email"
name="emailAddress"
type="email"
value={emailAddress}
onChange={e => setEmailAddress(e.target.value)}
className="w-full"
disabled={isLoading}
/>
</div>
<div className="blong-self-registration__row">
<div className="blong-field">
<label htmlFor="register-password" className="blong-field__label">
Password
</label>
<Password
inputId="register-password"
name="password"
value={password}
onChange={e => setPassword(e.target.value)}
toggleMask
disabled={isLoading}
/>
</div>
<div className="blong-field">
<label htmlFor="register-confirm" className="blong-field__label">
Confirm Password
</label>
<Password
inputId="register-confirm"
name="confirmPassword"
value={confirmPassword}
onChange={e => setConfirmPassword(e.target.value)}
toggleMask
disabled={isLoading}
/>
</div>
</div>
<Button
type="submit"
label={submitLabel}
loading={isLoading}
className="blong-self-registration__submit"
data-testid="register-submit"
/>
</form>
{onGoogle && (
<>
<div className="blong-self-registration__divider">
<span>or</span>
</div>
<SocialLoginButton
onClick={() => void handleGoogle()}
loading={isLoading}
/>
</>
)}
{onBack && (
<div className="blong-self-registration__back">
<Button
label="Back to Login"
icon="pi pi-arrow-left"
className="p-button-text"
onClick={onBack}
disabled={isLoading}
/>
</div>
)}
</div>
{/* Org brand area — 1fr row below the card */}
<div className="blong-self-registration__bottom">
{(orgTitle || orgLogoUrl || orgIcon) && (
<div className="blong-self-registration__org-brand">
{orgLogoUrl ? (
<img
src={orgLogoUrl}
alt={orgTitle ?? 'logo'}
className="blong-self-registration__org-img"
/>
) : orgIcon ? (
<i className={`blong-self-registration__org-icon ${orgIcon}`} />
) : null}
{orgTitle && (
<span className="blong-self-registration__org-name">{orgTitle}</span>
)}
</div>
)}
</div>
</div>
);
}
|