mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 13:10:29 +00:00
refactor: the login's code step and the reservation row shapes get modules of their own
Both files had grown past their size limit with this round's fixes. The two-factor step moves to pages/login/MfaCodeStep.tsx and the reservation row types to reservation-rows.ts, re-exported from the repository, and both size baselines come down to match.
This commit is contained in:
@@ -4,7 +4,6 @@ import {
|
||||
EyeOff,
|
||||
Fingerprint,
|
||||
Globe,
|
||||
KeyRound,
|
||||
Loader2,
|
||||
Lock,
|
||||
Mail,
|
||||
@@ -18,6 +17,7 @@ import { SUPPORTED_LANGUAGES, useTranslation } from '../i18n';
|
||||
import { IDP_LOGIN_URL, useLogin } from './login/useLogin';
|
||||
import LoginWorld from './login/LoginWorld';
|
||||
import NativeServerLink from './login/NativeServerLink';
|
||||
import MfaCodeStep from './login/MfaCodeStep';
|
||||
import PasswordChecklist from '../components/shared/PasswordChecklist';
|
||||
|
||||
/** Fixed so the sky does not reshuffle on every render. */
|
||||
@@ -739,93 +739,18 @@ export default function LoginPage(): React.ReactElement {
|
||||
)}
|
||||
|
||||
{mode === 'login' && mfaStep && !passwordChangeStep && (
|
||||
<div>
|
||||
<label
|
||||
style={{
|
||||
display: 'block',
|
||||
fontSize: 'calc(12.5px * var(--fs-scale-body, 1))',
|
||||
fontWeight: 600,
|
||||
color: '#374151',
|
||||
marginBottom: 6,
|
||||
}}
|
||||
>
|
||||
{t('login.mfaCodeLabel')}
|
||||
</label>
|
||||
{/* The account the code belongs to, for password managers: they match a
|
||||
one-time code to a saved login through the username in the same form,
|
||||
and the email field is gone in this step. */}
|
||||
<input
|
||||
type="text"
|
||||
name="username"
|
||||
autoComplete="username"
|
||||
value={email}
|
||||
readOnly
|
||||
tabIndex={-1}
|
||||
aria-hidden="true"
|
||||
className="sr-only"
|
||||
/>
|
||||
<div style={{ position: 'relative' }}>
|
||||
<KeyRound
|
||||
size={15}
|
||||
className="text-[#9ca3af]"
|
||||
style={{
|
||||
position: 'absolute',
|
||||
insetInlineStart: 13,
|
||||
top: '50%',
|
||||
transform: 'translateY(-50%)',
|
||||
pointerEvents: 'none',
|
||||
}}
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
id="totp"
|
||||
name="totp"
|
||||
// Text, not numeric: backup codes carry letters. The hints are set here
|
||||
// rather than left to native/keyboardFields.ts, because autoFocus gives
|
||||
// the field focus before any touch could prepare it.
|
||||
inputMode="text"
|
||||
autoComplete="one-time-code"
|
||||
autoCapitalize="characters"
|
||||
autoCorrect="off"
|
||||
spellCheck={false}
|
||||
enterKeyHint="go"
|
||||
value={mfaCode}
|
||||
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
|
||||
setMfaCode(e.target.value.toUpperCase().slice(0, 24))
|
||||
}
|
||||
placeholder={t('login.mfaPlaceholder')}
|
||||
required
|
||||
autoFocus
|
||||
style={inputBase}
|
||||
onFocus={(e: React.FocusEvent<HTMLInputElement>) => (e.target.style.borderColor = '#111827')}
|
||||
onBlur={(e: React.FocusEvent<HTMLInputElement>) => (e.target.style.borderColor = '#e5e7eb')}
|
||||
/>
|
||||
</div>
|
||||
<p style={{ fontSize: 'calc(12px * var(--fs-scale-body, 1))', color: '#9ca3af', marginTop: 8 }}>
|
||||
{t('login.mfaHint')}
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setMfaStep(false);
|
||||
setMfaToken('');
|
||||
setMfaCode('');
|
||||
setError('');
|
||||
}}
|
||||
style={{
|
||||
marginTop: 8,
|
||||
background: 'none',
|
||||
border: 'none',
|
||||
color: '#6b7280',
|
||||
fontSize: 'calc(13px * var(--fs-scale-body, 1))',
|
||||
cursor: 'pointer',
|
||||
padding: 0,
|
||||
fontFamily: 'inherit',
|
||||
}}
|
||||
>
|
||||
{t('login.mfaBack')}
|
||||
</button>
|
||||
</div>
|
||||
<MfaCodeStep
|
||||
email={email}
|
||||
code={mfaCode}
|
||||
onCode={setMfaCode}
|
||||
inputStyle={inputBase}
|
||||
onBack={() => {
|
||||
setMfaStep(false);
|
||||
setMfaToken('');
|
||||
setMfaCode('');
|
||||
setError('');
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Username (register only) */}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
import { KeyRound } from 'lucide-react';
|
||||
import React from 'react';
|
||||
import { useTranslation } from '../../i18n';
|
||||
|
||||
interface MfaCodeStepProps {
|
||||
/** The account being signed in, kept in the form for password managers. */
|
||||
email: string;
|
||||
code: string;
|
||||
onCode: (code: string) => void;
|
||||
inputStyle: React.CSSProperties;
|
||||
onBack: () => void;
|
||||
}
|
||||
|
||||
/** The login's second step: the one-time or backup code, and the way back. */
|
||||
export default function MfaCodeStep({ email, code, onCode, inputStyle, onBack }: MfaCodeStepProps) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div>
|
||||
<label
|
||||
style={{
|
||||
display: 'block',
|
||||
fontSize: 'calc(12.5px * var(--fs-scale-body, 1))',
|
||||
fontWeight: 600,
|
||||
color: '#374151',
|
||||
marginBottom: 6,
|
||||
}}
|
||||
>
|
||||
{t('login.mfaCodeLabel')}
|
||||
</label>
|
||||
{/* The account the code belongs to, for password managers: they match a
|
||||
one-time code to a saved login through the username in the same form,
|
||||
and the email field is gone in this step. */}
|
||||
<input
|
||||
type="text"
|
||||
name="username"
|
||||
autoComplete="username"
|
||||
value={email}
|
||||
readOnly
|
||||
tabIndex={-1}
|
||||
aria-hidden="true"
|
||||
className="sr-only"
|
||||
/>
|
||||
<div style={{ position: 'relative' }}>
|
||||
<KeyRound
|
||||
size={15}
|
||||
className="text-[#9ca3af]"
|
||||
style={{
|
||||
position: 'absolute',
|
||||
insetInlineStart: 13,
|
||||
top: '50%',
|
||||
transform: 'translateY(-50%)',
|
||||
pointerEvents: 'none',
|
||||
}}
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
id="totp"
|
||||
name="totp"
|
||||
// Text, not numeric: backup codes carry letters. The hints are set here
|
||||
// rather than left to native/keyboardFields.ts, because autoFocus gives
|
||||
// the field focus before any touch could prepare it.
|
||||
inputMode="text"
|
||||
autoComplete="one-time-code"
|
||||
autoCapitalize="characters"
|
||||
autoCorrect="off"
|
||||
spellCheck={false}
|
||||
enterKeyHint="go"
|
||||
value={code}
|
||||
onChange={(e: React.ChangeEvent<HTMLInputElement>) => onCode(e.target.value.toUpperCase().slice(0, 24))}
|
||||
placeholder={t('login.mfaPlaceholder')}
|
||||
required
|
||||
autoFocus
|
||||
style={inputStyle}
|
||||
onFocus={(e: React.FocusEvent<HTMLInputElement>) => (e.target.style.borderColor = '#111827')}
|
||||
onBlur={(e: React.FocusEvent<HTMLInputElement>) => (e.target.style.borderColor = '#e5e7eb')}
|
||||
/>
|
||||
</div>
|
||||
<p style={{ fontSize: 'calc(12px * var(--fs-scale-body, 1))', color: '#9ca3af', marginTop: 8 }}>
|
||||
{t('login.mfaHint')}
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onBack}
|
||||
style={{
|
||||
marginTop: 8,
|
||||
background: 'none',
|
||||
border: 'none',
|
||||
color: '#6b7280',
|
||||
fontSize: 'calc(13px * var(--fs-scale-body, 1))',
|
||||
cursor: 'pointer',
|
||||
padding: 0,
|
||||
fontFamily: 'inherit',
|
||||
}}
|
||||
>
|
||||
{t('login.mfaBack')}
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user