refactor(webui): refine onboarding layout
Give agreement reading and password setup a calmer responsive layout.\n\nKeep existing motion behavior while aligning actions and improving mobile form ergonomics.
This commit is contained in:
4 files changed
+200
-93
No files matched your search
@@ -191,7 +191,7 @@ export function FloatingLabelInput({
|
|||||||
<div className={`w-full ${className}`}>
|
<div className={`w-full ${className}`}>
|
||||||
<div className="relative pt-[20px]">
|
<div className="relative pt-[20px]">
|
||||||
<div
|
<div
|
||||||
className={`relative h-10 rounded-[10px] border-2 transition-[background-color,border-color,box-shadow] duration-150 ${
|
className={`relative h-11 rounded-[10px] border-2 transition-[background-color,border-color,box-shadow] duration-150 sm:h-10 ${
|
||||||
invalid
|
invalid
|
||||||
? "border-destructive bg-background"
|
? "border-destructive bg-background"
|
||||||
: focused
|
: focused
|
||||||
@@ -228,7 +228,7 @@ export function FloatingLabelInput({
|
|||||||
fieldProps.onChange(event);
|
fieldProps.onChange(event);
|
||||||
onChange?.(event.currentTarget.value, event);
|
onChange?.(event.currentTarget.value, event);
|
||||||
}}
|
}}
|
||||||
className={`absolute inset-0 h-full w-full rounded-[9px] bg-transparent px-3 py-0 text-[13px] leading-[20px] text-foreground outline-none focus-visible:outline-none disabled:cursor-not-allowed ${
|
className={`absolute inset-0 h-full w-full rounded-[9px] bg-transparent px-3 py-0 text-base leading-5 text-foreground outline-none focus-visible:outline-none disabled:cursor-not-allowed sm:text-[13px] ${
|
||||||
endAdornment ? "pr-16" : ""
|
endAdornment ? "pr-16" : ""
|
||||||
}`}
|
}`}
|
||||||
/>
|
/>
|
||||||
@@ -249,7 +249,7 @@ export function FloatingLabelInput({
|
|||||||
}}
|
}}
|
||||||
transition={move}
|
transition={move}
|
||||||
style={{ originX: 0, originY: 0, willChange: "transform" }}
|
style={{ originX: 0, originY: 0, willChange: "transform" }}
|
||||||
className={`absolute left-3 top-[32px] block cursor-text select-none text-[13px] leading-[16px] ${
|
className={`absolute left-3 top-[32px] block cursor-text select-none text-base leading-5 sm:text-[13px] sm:leading-[16px] ${
|
||||||
invalid
|
invalid
|
||||||
? "text-destructive"
|
? "text-destructive"
|
||||||
: raised
|
: raised
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import type { KeyboardEvent, ReactNode } from "react";
|
import type { CSSProperties, KeyboardEvent, ReactNode } from "react";
|
||||||
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
|
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
|
||||||
|
|
||||||
const EASE = [0.23, 1, 0.32, 1] as const;
|
const EASE = [0.23, 1, 0.32, 1] as const;
|
||||||
@@ -94,8 +94,28 @@ export type WizardStep = {
|
|||||||
canSkip?: boolean;
|
canSkip?: boolean;
|
||||||
onSkip?: () => void;
|
onSkip?: () => void;
|
||||||
hideAdvance?: boolean;
|
hideAdvance?: boolean;
|
||||||
|
hideBack?: boolean;
|
||||||
|
scrollMode?: "panel" | "content";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type WizardNavigationControls = {
|
||||||
|
back: () => void;
|
||||||
|
next: () => void;
|
||||||
|
goTo: (index: number) => void;
|
||||||
|
index: number;
|
||||||
|
total: number;
|
||||||
|
isFirst: boolean;
|
||||||
|
isLast: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
const WizardNavigationContext = createContext<WizardNavigationControls | null>(null);
|
||||||
|
|
||||||
|
export function useWizardNavigation(): WizardNavigationControls {
|
||||||
|
const controls = useContext(WizardNavigationContext);
|
||||||
|
if (!controls) throw new Error("useWizardNavigation must be used inside <WizardSteps>");
|
||||||
|
return controls;
|
||||||
|
}
|
||||||
|
|
||||||
export type WizardStepsProps = {
|
export type WizardStepsProps = {
|
||||||
steps: WizardStep[];
|
steps: WizardStep[];
|
||||||
index?: number;
|
index?: number;
|
||||||
@@ -103,7 +123,7 @@ export type WizardStepsProps = {
|
|||||||
onIndexChange?: (index: number, direction: WizardDirection) => void;
|
onIndexChange?: (index: number, direction: WizardDirection) => void;
|
||||||
onComplete?: () => void;
|
onComplete?: () => void;
|
||||||
complete?: boolean;
|
complete?: boolean;
|
||||||
height?: number;
|
height?: CSSProperties["height"];
|
||||||
backLabel?: string;
|
backLabel?: string;
|
||||||
nextLabel?: string;
|
nextLabel?: string;
|
||||||
finishLabel?: string;
|
finishLabel?: string;
|
||||||
@@ -112,6 +132,8 @@ export type WizardStepsProps = {
|
|||||||
completeHint?: string;
|
completeHint?: string;
|
||||||
label?: string;
|
label?: string;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
spacious?: boolean;
|
||||||
|
fill?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function WizardSteps({
|
export function WizardSteps({
|
||||||
@@ -130,6 +152,8 @@ export function WizardSteps({
|
|||||||
completeHint = "Step back to change anything",
|
completeHint = "Step back to change anything",
|
||||||
label = "Steps",
|
label = "Steps",
|
||||||
className = "",
|
className = "",
|
||||||
|
spacious = false,
|
||||||
|
fill = false,
|
||||||
}: WizardStepsProps) {
|
}: WizardStepsProps) {
|
||||||
const wizard = useWizard({
|
const wizard = useWizard({
|
||||||
total: steps.length,
|
total: steps.length,
|
||||||
@@ -206,13 +230,32 @@ export function WizardSteps({
|
|||||||
if (!step) return null;
|
if (!step) return null;
|
||||||
|
|
||||||
const position = `Step ${at + 1} of ${total}: ${step.label}`;
|
const position = `Step ${at + 1} of ${total}: ${step.label}`;
|
||||||
|
const navigation = {
|
||||||
|
back: () => {
|
||||||
|
intent.current = "panel";
|
||||||
|
back();
|
||||||
|
},
|
||||||
|
next: () => {
|
||||||
|
if (!isLast) intent.current = "panel";
|
||||||
|
next();
|
||||||
|
},
|
||||||
|
goTo,
|
||||||
|
index: at,
|
||||||
|
total,
|
||||||
|
isFirst,
|
||||||
|
isLast,
|
||||||
|
} satisfies WizardNavigationControls;
|
||||||
|
const showBack = !isFirst && !step.hideBack;
|
||||||
|
const showSkip = Boolean(step.canSkip);
|
||||||
|
const showAdvance = !complete && !step.hideAdvance;
|
||||||
|
const showNavigation = showBack || showSkip || showAdvance;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`w-full ${className}`}>
|
<div className={`${fill ? "flex min-h-0 flex-1 flex-col" : ""} w-full ${className}`}>
|
||||||
<p aria-live="polite" className="sr-only">{position}</p>
|
<p aria-live="polite" className="sr-only">{position}</p>
|
||||||
<span
|
<span
|
||||||
aria-hidden
|
aria-hidden
|
||||||
className="mb-2 grid select-none text-[13px] font-medium text-foreground"
|
className={`${spacious ? "mb-1 text-sm" : "mb-2 text-[13px]"} grid select-none font-medium text-foreground`}
|
||||||
>
|
>
|
||||||
{steps.map((candidate, stepIndex) => (
|
{steps.map((candidate, stepIndex) => (
|
||||||
<motion.span
|
<motion.span
|
||||||
@@ -229,7 +272,7 @@ export function WizardSteps({
|
|||||||
<ol
|
<ol
|
||||||
ref={listRef}
|
ref={listRef}
|
||||||
aria-label={label}
|
aria-label={label}
|
||||||
className="mb-4 flex list-none items-center gap-1 p-0"
|
className={`${spacious ? "mb-3 gap-2" : "mb-4 gap-1"} flex list-none items-center p-0`}
|
||||||
>
|
>
|
||||||
{steps.map((candidate, stepIndex) => {
|
{steps.map((candidate, stepIndex) => {
|
||||||
const done = complete || stepIndex < at;
|
const done = complete || stepIndex < at;
|
||||||
@@ -279,7 +322,7 @@ export function WizardSteps({
|
|||||||
intent.current = "list";
|
intent.current = "list";
|
||||||
goTo(stepIndex);
|
goTo(stepIndex);
|
||||||
}}
|
}}
|
||||||
className="rounded-[8px] outline-none focus-visible:shadow-[0_0_0_1.5px_var(--ring)]"
|
className="relative rounded-[8px] outline-none after:absolute after:-inset-2 after:content-[''] focus-visible:shadow-[0_0_0_1.5px_var(--ring)]"
|
||||||
>
|
>
|
||||||
{tile}
|
{tile}
|
||||||
</button>
|
</button>
|
||||||
@@ -314,8 +357,12 @@ export function WizardSteps({
|
|||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
role="group"
|
role="group"
|
||||||
aria-label={position}
|
aria-label={position}
|
||||||
style={{ height }}
|
style={{ height: fill ? undefined : height }}
|
||||||
className="relative overflow-hidden rounded-[11px] border border-border bg-card shadow-sm outline-none transition-[border-color,box-shadow] duration-150 focus-visible:border-ring"
|
className={`${fill ? "min-h-0 flex-1" : ""} relative overflow-hidden border border-border bg-card outline-none transition-[border-color,box-shadow] duration-150 focus-visible:border-ring ${
|
||||||
|
spacious
|
||||||
|
? "rounded-[24px] shadow-[0_0_0_1px_rgb(255_255_255/0.02),0_18px_50px_rgb(0_0_0/0.12)]"
|
||||||
|
: "rounded-[11px] shadow-sm"
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
<AnimatePresence initial={false} custom={direction}>
|
<AnimatePresence initial={false} custom={direction}>
|
||||||
<motion.div
|
<motion.div
|
||||||
@@ -327,7 +374,9 @@ export function WizardSteps({
|
|||||||
exit="exit"
|
exit="exit"
|
||||||
transition={panelTransition}
|
transition={panelTransition}
|
||||||
style={{ scrollbarGutter: "stable" }}
|
style={{ scrollbarGutter: "stable" }}
|
||||||
className="absolute inset-0 overflow-y-auto overscroll-contain p-4 text-[13.5px] leading-relaxed text-foreground"
|
className={`absolute inset-0 overscroll-contain text-foreground ${
|
||||||
|
step.scrollMode === "content" ? "overflow-hidden" : "overflow-y-auto"
|
||||||
|
} ${spacious ? "p-4 text-sm leading-relaxed sm:p-5 lg:p-6" : "p-4 text-[13.5px] leading-relaxed"}`}
|
||||||
>
|
>
|
||||||
{complete ? (
|
{complete ? (
|
||||||
<div className="flex h-full flex-col items-center justify-center gap-1.5">
|
<div className="flex h-full flex-col items-center justify-center gap-1.5">
|
||||||
@@ -335,14 +384,16 @@ export function WizardSteps({
|
|||||||
<p className="text-[12.5px] text-muted-foreground">{completeHint}</p>
|
<p className="text-[12.5px] text-muted-foreground">{completeHint}</p>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
step.content
|
<WizardNavigationContext.Provider value={navigation}>
|
||||||
|
{step.content}
|
||||||
|
</WizardNavigationContext.Provider>
|
||||||
)}
|
)}
|
||||||
</motion.div>
|
</motion.div>
|
||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-3 flex h-9 items-center gap-3">
|
{showNavigation ? <div className={`${spacious ? "mt-4 h-11" : "mt-3 h-9"} flex items-center gap-3`}>
|
||||||
<AnimatePresence initial={false}>
|
<AnimatePresence initial={false}>
|
||||||
{isFirst ? null : (
|
{showBack ? (
|
||||||
<motion.button
|
<motion.button
|
||||||
key="back"
|
key="back"
|
||||||
type="button"
|
type="button"
|
||||||
@@ -354,16 +405,15 @@ export function WizardSteps({
|
|||||||
}}
|
}}
|
||||||
transition={reduced ? { duration: 0 } : { duration: 0.16, ease: EASE }}
|
transition={reduced ? { duration: 0 } : { duration: 0.16, ease: EASE }}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
intent.current = "panel";
|
navigation.back();
|
||||||
back();
|
|
||||||
}}
|
}}
|
||||||
className="h-9 rounded-[9px] border border-border bg-background px-3 text-[13px] font-medium text-foreground outline-none transition-[border-color,box-shadow] duration-150 hover:border-foreground/20 focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/40"
|
className={`${spacious ? "h-11 px-4 text-sm" : "h-9 px-3 text-[13px]"} rounded-[9px] border border-border bg-background font-medium text-foreground outline-none transition-[border-color,box-shadow] duration-150 hover:border-foreground/20 focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/40`}
|
||||||
>
|
>
|
||||||
{backLabel}
|
{backLabel}
|
||||||
</motion.button>
|
</motion.button>
|
||||||
)}
|
) : null}
|
||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
{step.canSkip ? (
|
{showSkip ? (
|
||||||
<motion.button
|
<motion.button
|
||||||
key={`skip-${step.id}`}
|
key={`skip-${step.id}`}
|
||||||
type="button"
|
type="button"
|
||||||
@@ -379,20 +429,19 @@ export function WizardSteps({
|
|||||||
if (!isLast) intent.current = "panel";
|
if (!isLast) intent.current = "panel";
|
||||||
next();
|
next();
|
||||||
}}
|
}}
|
||||||
className="h-9 rounded-[9px] px-3 text-[13px] font-medium text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-[3px] focus-visible:ring-ring/40"
|
className={`${spacious ? "h-11 px-4 text-sm" : "h-9 px-3 text-[13px]"} rounded-[9px] font-medium text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-[3px] focus-visible:ring-ring/40`}
|
||||||
>
|
>
|
||||||
{skipLabel}
|
{skipLabel}
|
||||||
</motion.button>
|
</motion.button>
|
||||||
) : null}
|
) : null}
|
||||||
<AnimatePresence initial={false}>
|
<AnimatePresence initial={false}>
|
||||||
{complete || step.hideAdvance ? null : (
|
{showAdvance ? (
|
||||||
<motion.button
|
<motion.button
|
||||||
key="advance"
|
key="advance"
|
||||||
type="button"
|
type="button"
|
||||||
aria-label={isLast ? finishLabel : nextLabel}
|
aria-label={isLast ? finishLabel : nextLabel}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (!isLast) intent.current = "panel";
|
navigation.next();
|
||||||
next();
|
|
||||||
}}
|
}}
|
||||||
initial={{ opacity: 0, scale: 0.96 }}
|
initial={{ opacity: 0, scale: 0.96 }}
|
||||||
animate={{ opacity: 1, scale: 1 }}
|
animate={{ opacity: 1, scale: 1 }}
|
||||||
@@ -404,7 +453,7 @@ export function WizardSteps({
|
|||||||
: { duration: 0.14, ease: EXIT_EASE },
|
: { duration: 0.14, ease: EXIT_EASE },
|
||||||
}}
|
}}
|
||||||
transition={reduced ? { duration: 0 } : CROSSFADE}
|
transition={reduced ? { duration: 0 } : CROSSFADE}
|
||||||
className="ml-auto grid h-9 place-items-center rounded-[9px] bg-foreground px-3.5 text-[13px] font-medium text-background outline-none focus-visible:shadow-[inset_0_0_0_1.5px_var(--ring)]"
|
className={`${spacious ? "h-11 px-4 text-sm" : "h-9 px-3.5 text-[13px]"} ml-auto grid place-items-center rounded-[9px] bg-foreground font-medium text-background outline-none focus-visible:shadow-[inset_0_0_0_1.5px_var(--ring)]`}
|
||||||
>
|
>
|
||||||
<span aria-hidden className="invisible col-start-1 row-start-1">
|
<span aria-hidden className="invisible col-start-1 row-start-1">
|
||||||
{finishLabel.length > nextLabel.length ? finishLabel : nextLabel}
|
{finishLabel.length > nextLabel.length ? finishLabel : nextLabel}
|
||||||
@@ -428,9 +477,9 @@ export function WizardSteps({
|
|||||||
{finishLabel}
|
{finishLabel}
|
||||||
</motion.span>
|
</motion.span>
|
||||||
</motion.button>
|
</motion.button>
|
||||||
)}
|
) : null}
|
||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
</div>
|
</div> : null}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useEffect, useMemo, useState, type ReactNode } from 'react';
|
||||||
import { AnimatePresence, motion } from 'motion/react';
|
import { AnimatePresence, motion } from 'motion/react';
|
||||||
import { Loader2 } from 'lucide-react';
|
import { Loader2 } from 'lucide-react';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
import { PasswordVisibilityIcon } from '@/components/ui/password-visibility-icon';
|
import { PasswordVisibilityIcon } from '@/components/ui/password-visibility-icon';
|
||||||
import { actionErrorMessage, useActionFeedback } from '@/contexts/ActionFeedbackContext';
|
import { actionErrorMessage, useActionFeedback } from '@/contexts/ActionFeedbackContext';
|
||||||
import { useTheme } from '@/contexts/ThemeContext';
|
import { useTheme } from '@/contexts/ThemeContext';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
export interface PasswordRule {
|
export interface PasswordRule {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -28,6 +29,8 @@ const EMPTY_RULES: readonly PasswordRule[] = [
|
|||||||
const STRENGTH_LABELS = ['未输入', '很弱', '较弱', '一般', '良好', '强'] as const;
|
const STRENGTH_LABELS = ['未输入', '很弱', '较弱', '一般', '良好', '强'] as const;
|
||||||
|
|
||||||
export interface ChangePasswordFormProps {
|
export interface ChangePasswordFormProps {
|
||||||
|
/** Selects whether the form changes credentials or only rehearses validation. */
|
||||||
|
mode?: 'change' | 'rehearsal';
|
||||||
/**
|
/**
|
||||||
* When provided, the "current password" field is omitted entirely and this
|
* When provided, the "current password" field is omitted entirely and this
|
||||||
* value is used as the old password.
|
* value is used as the old password.
|
||||||
@@ -51,9 +54,16 @@ export interface ChangePasswordFormProps {
|
|||||||
/** Disambiguates input ids if two instances ever mount at once. */
|
/** Disambiguates input ids if two instances ever mount at once. */
|
||||||
idPrefix?: string;
|
idPrefix?: string;
|
||||||
submitLabel?: string;
|
submitLabel?: string;
|
||||||
|
className?: string;
|
||||||
|
renderActions?: (state: {
|
||||||
|
canSubmit: boolean;
|
||||||
|
submitting: boolean;
|
||||||
|
submitLabel: string;
|
||||||
|
}) => ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ChangePasswordForm({
|
export function ChangePasswordForm({
|
||||||
|
mode = 'change',
|
||||||
knownOldPassword,
|
knownOldPassword,
|
||||||
checkStrength,
|
checkStrength,
|
||||||
submit,
|
submit,
|
||||||
@@ -61,8 +71,11 @@ export function ChangePasswordForm({
|
|||||||
onCancel,
|
onCancel,
|
||||||
idPrefix = 'cpw',
|
idPrefix = 'cpw',
|
||||||
submitLabel = '保存新密码',
|
submitLabel = '保存新密码',
|
||||||
|
className,
|
||||||
|
renderActions,
|
||||||
}: ChangePasswordFormProps) {
|
}: ChangePasswordFormProps) {
|
||||||
const carriesOld = knownOldPassword !== undefined;
|
const rehearsing = mode === 'rehearsal';
|
||||||
|
const carriesOld = rehearsing || knownOldPassword !== undefined;
|
||||||
const { runAction } = useActionFeedback();
|
const { runAction } = useActionFeedback();
|
||||||
const { appearance } = useTheme();
|
const { appearance } = useTheme();
|
||||||
const reduceMotion = appearance.reduceMotion || appearance.disableMotion;
|
const reduceMotion = appearance.reduceMotion || appearance.disableMotion;
|
||||||
@@ -85,7 +98,7 @@ export function ChangePasswordForm({
|
|||||||
const [submitting, setSubmitting] = useState(false);
|
const [submitting, setSubmitting] = useState(false);
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
|
|
||||||
const effectiveOld = carriesOld ? (knownOldPassword as string) : oldPassword;
|
const effectiveOld = rehearsing ? '' : carriesOld ? (knownOldPassword as string) : oldPassword;
|
||||||
const checkedCurrentPassword = strengthResult.password === newPassword;
|
const checkedCurrentPassword = strengthResult.password === newPassword;
|
||||||
const valid = checkedCurrentPassword && strengthResult.valid;
|
const valid = checkedCurrentPassword && strengthResult.valid;
|
||||||
const strengthError = strengthFailure?.password === newPassword
|
const strengthError = strengthFailure?.password === newPassword
|
||||||
@@ -106,7 +119,11 @@ export function ChangePasswordForm({
|
|||||||
);
|
);
|
||||||
const confirmMatches = newPassword.length > 0 && newPassword === confirmPassword;
|
const confirmMatches = newPassword.length > 0 && newPassword === confirmPassword;
|
||||||
const canSubmit =
|
const canSubmit =
|
||||||
!submitting && effectiveOld.length > 0 && valid && confirmMatches && effectiveOld !== newPassword;
|
!submitting
|
||||||
|
&& (rehearsing || effectiveOld.length > 0)
|
||||||
|
&& valid
|
||||||
|
&& confirmMatches
|
||||||
|
&& (rehearsing || effectiveOld !== newPassword);
|
||||||
|
|
||||||
// Debounce the strength check so we don't slam the API on every keystroke.
|
// Debounce the strength check so we don't slam the API on every keystroke.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -145,11 +162,11 @@ export function ChangePasswordForm({
|
|||||||
try {
|
try {
|
||||||
const res = await runAction(
|
const res = await runAction(
|
||||||
{
|
{
|
||||||
title: '正在更新访问密码',
|
title: rehearsing ? '正在验证密码设置步骤' : '正在更新访问密码',
|
||||||
detail: '正在保存新密码并使其他会话失效',
|
detail: rehearsing ? '演练内容不会保存' : '正在保存新密码并使其他会话失效',
|
||||||
successTitle: '访问密码已更新',
|
successTitle: rehearsing ? '密码设置演练已完成' : '访问密码已更新',
|
||||||
successDetail: '其他会话已失效',
|
successDetail: rehearsing ? '未修改真实访问密码' : '其他会话已失效',
|
||||||
errorTitle: '访问密码更新失败',
|
errorTitle: rehearsing ? '密码设置演练失败' : '访问密码更新失败',
|
||||||
resultError: (result) => result.success ? null : result.message || '修改失败',
|
resultError: (result) => result.success ? null : result.message || '修改失败',
|
||||||
},
|
},
|
||||||
() => submit(effectiveOld, newPassword),
|
() => submit(effectiveOld, newPassword),
|
||||||
@@ -167,7 +184,7 @@ export function ChangePasswordForm({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={handleSubmit} className="flex flex-col gap-3">
|
<form onSubmit={handleSubmit} className={cn('flex flex-col gap-3', className)}>
|
||||||
{!carriesOld && (
|
{!carriesOld && (
|
||||||
<InlineValidation
|
<InlineValidation
|
||||||
id={`${idPrefix}-old`}
|
id={`${idPrefix}-old`}
|
||||||
@@ -206,7 +223,7 @@ export function ChangePasswordForm({
|
|||||||
validationKey={effectiveOld}
|
validationKey={effectiveOld}
|
||||||
validate={(value) => {
|
validate={(value) => {
|
||||||
if (value.length === 0) return '请输入新密码';
|
if (value.length === 0) return '请输入新密码';
|
||||||
if (value === effectiveOld) return '新密码不能与当前密码相同';
|
if (!rehearsing && value === effectiveOld) return '新密码不能与当前密码相同';
|
||||||
return null;
|
return null;
|
||||||
}}
|
}}
|
||||||
showValidIcon={false}
|
showValidIcon={false}
|
||||||
@@ -277,22 +294,24 @@ export function ChangePasswordForm({
|
|||||||
)}
|
)}
|
||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
|
|
||||||
<div className="flex items-center gap-2 pt-1">
|
{renderActions ? renderActions({ canSubmit, submitting, submitLabel }) : (
|
||||||
{onCancel && (
|
<div className="flex items-center gap-2 pt-1">
|
||||||
<Button type="button" variant="ghost" onClick={onCancel} className="h-10">
|
{onCancel && (
|
||||||
取消
|
<Button type="button" variant="ghost" onClick={onCancel} className="h-10">
|
||||||
</Button>
|
取消
|
||||||
)}
|
</Button>
|
||||||
<Button type="submit" disabled={!canSubmit} className="ml-auto h-10">
|
|
||||||
{submitting ? (
|
|
||||||
<>
|
|
||||||
<Loader2 className="size-4 animate-spin" /> 提交中…
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
submitLabel
|
|
||||||
)}
|
)}
|
||||||
</Button>
|
<Button type="submit" disabled={!canSubmit} className="ml-auto h-10">
|
||||||
</div>
|
{submitting ? (
|
||||||
|
<>
|
||||||
|
<Loader2 className="size-4 animate-spin" /> 提交中…
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
submitLabel
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -311,7 +330,7 @@ function PasswordVisibilityButton({
|
|||||||
type="button"
|
type="button"
|
||||||
onClick={onToggle}
|
onClick={onToggle}
|
||||||
aria-label={visible ? '隐藏密码' : '显示密码'}
|
aria-label={visible ? '隐藏密码' : '显示密码'}
|
||||||
className="flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary"
|
className="flex size-9 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary sm:size-7"
|
||||||
>
|
>
|
||||||
<PasswordVisibilityIcon visible={visible} reduceMotion={reduceMotion} />
|
<PasswordVisibilityIcon visible={visible} reduceMotion={reduceMotion} />
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import { useState, type ReactNode } from 'react';
|
import { useState, type ReactNode } from 'react';
|
||||||
import { Check, ScrollText, ShieldAlert, ShieldCheck } from 'lucide-react';
|
import { Check, Loader2, ScrollText, ShieldAlert, ShieldCheck } from 'lucide-react';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { ThemeToggle } from '@/components/theme-toggle';
|
import { ThemeToggle } from '@/components/theme-toggle';
|
||||||
import { SegmentedControl } from '@/components/interior/segmented-control';
|
import { SegmentedControl } from '@/components/interior/segmented-control';
|
||||||
import { WizardSteps, type WizardStep } from '@/components/interior/wizard-steps';
|
import {
|
||||||
|
useWizardNavigation,
|
||||||
|
WizardSteps,
|
||||||
|
type WizardStep,
|
||||||
|
} from '@/components/interior/wizard-steps';
|
||||||
import { ChangePasswordForm, type PasswordRule } from '@/components/pages/change-password-form';
|
import { ChangePasswordForm, type PasswordRule } from '@/components/pages/change-password-form';
|
||||||
import {
|
import {
|
||||||
advanceOnboardingStep,
|
advanceOnboardingStep,
|
||||||
@@ -28,6 +32,7 @@ interface OnboardingWizardPageProps {
|
|||||||
needsConsent: boolean;
|
needsConsent: boolean;
|
||||||
mustChangePassword: boolean;
|
mustChangePassword: boolean;
|
||||||
knownOldPassword?: string;
|
knownOldPassword?: string;
|
||||||
|
passwordMode?: 'change' | 'rehearsal';
|
||||||
onAccept: () => Promise<{ success: boolean; message?: string }>;
|
onAccept: () => Promise<{ success: boolean; message?: string }>;
|
||||||
onConsentComplete: () => void;
|
onConsentComplete: () => void;
|
||||||
onDecline: () => void;
|
onDecline: () => void;
|
||||||
@@ -52,6 +57,7 @@ export function OnboardingWizardPage({
|
|||||||
needsConsent,
|
needsConsent,
|
||||||
mustChangePassword,
|
mustChangePassword,
|
||||||
knownOldPassword,
|
knownOldPassword,
|
||||||
|
passwordMode = 'change',
|
||||||
onAccept,
|
onAccept,
|
||||||
onConsentComplete,
|
onConsentComplete,
|
||||||
onDecline,
|
onDecline,
|
||||||
@@ -85,6 +91,8 @@ export function OnboardingWizardPage({
|
|||||||
label: '阅读并同意协议',
|
label: '阅读并同意协议',
|
||||||
canSkip: false,
|
canSkip: false,
|
||||||
hideAdvance: true,
|
hideAdvance: true,
|
||||||
|
hideBack: true,
|
||||||
|
scrollMode: 'content',
|
||||||
content: (
|
content: (
|
||||||
<AgreementStep
|
<AgreementStep
|
||||||
documents={documents}
|
documents={documents}
|
||||||
@@ -104,9 +112,11 @@ export function OnboardingWizardPage({
|
|||||||
label: '设置访问密码',
|
label: '设置访问密码',
|
||||||
canSkip: false,
|
canSkip: false,
|
||||||
hideAdvance: true,
|
hideAdvance: true,
|
||||||
|
hideBack: true,
|
||||||
content: (
|
content: (
|
||||||
<PasswordStep
|
<PasswordStep
|
||||||
knownOldPassword={knownOldPassword}
|
knownOldPassword={knownOldPassword}
|
||||||
|
mode={passwordMode}
|
||||||
checkStrength={checkStrength}
|
checkStrength={checkStrength}
|
||||||
submit={submitPassword}
|
submit={submitPassword}
|
||||||
onComplete={() => {
|
onComplete={() => {
|
||||||
@@ -133,7 +143,7 @@ export function OnboardingWizardPage({
|
|||||||
if (total === 0) return null;
|
if (total === 0) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative flex min-h-screen items-center justify-center overflow-x-hidden bg-background px-4 py-6">
|
<div className="relative min-h-dvh overflow-x-clip bg-background antialiased">
|
||||||
<div
|
<div
|
||||||
className="pointer-events-none absolute inset-0"
|
className="pointer-events-none absolute inset-0"
|
||||||
style={{
|
style={{
|
||||||
@@ -141,28 +151,29 @@ export function OnboardingWizardPage({
|
|||||||
'radial-gradient(80% 60% at 50% 0%, color-mix(in oklab, var(--primary) 18%, transparent) 0%, transparent 70%)',
|
'radial-gradient(80% 60% at 50% 0%, color-mix(in oklab, var(--primary) 18%, transparent) 0%, transparent 70%)',
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<div className="absolute right-4 top-4">
|
<div className="absolute right-4 top-4 z-20 sm:right-6 sm:top-6">
|
||||||
<ThemeToggle />
|
<ThemeToggle />
|
||||||
</div>
|
</div>
|
||||||
<main className="relative z-10 w-full max-w-3xl">
|
<main className="relative z-10 mx-auto flex h-dvh min-h-0 w-full max-w-5xl flex-col overflow-hidden px-4 pb-4 pt-14 sm:px-6 sm:pb-5 sm:pt-4">
|
||||||
<div className="mb-5">
|
<header className="mx-auto mb-2 w-full max-w-2xl shrink-0 text-center">
|
||||||
<p className="text-xs font-medium text-primary">SnowLuma WebUI</p>
|
<p className="text-xs font-semibold tracking-wide text-primary">SnowLuma WebUI</p>
|
||||||
<h1 className="mt-1 text-xl font-semibold tracking-tight">完成首次使用设置</h1>
|
<h1 className="mt-1 text-balance text-2xl font-semibold tracking-tight sm:text-3xl">完成首次使用设置</h1>
|
||||||
<p className="mt-1 text-sm text-muted-foreground">
|
<p className="mx-auto mt-1 max-w-xl text-pretty text-sm leading-relaxed text-muted-foreground">
|
||||||
按顺序完成必要步骤后即可进入控制台。
|
按顺序完成必要步骤后即可进入控制台。
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</header>
|
||||||
<WizardSteps
|
<WizardSteps
|
||||||
steps={steps}
|
steps={steps}
|
||||||
index={index}
|
index={index}
|
||||||
onIndexChange={setIndex}
|
onIndexChange={setIndex}
|
||||||
onComplete={onComplete}
|
onComplete={onComplete}
|
||||||
height={520}
|
|
||||||
label="首次使用设置步骤"
|
label="首次使用设置步骤"
|
||||||
backLabel="上一步"
|
backLabel="上一步"
|
||||||
nextLabel="下一步"
|
nextLabel="下一步"
|
||||||
finishLabel="完成"
|
finishLabel="完成"
|
||||||
skipLabel="跳过"
|
skipLabel="跳过"
|
||||||
|
spacious
|
||||||
|
fill
|
||||||
/>
|
/>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
@@ -208,21 +219,21 @@ function AgreementStep({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex min-h-full flex-col">
|
<div className="flex h-full min-h-0 flex-col">
|
||||||
<div className="flex items-start gap-3">
|
<div className="flex items-start gap-3 sm:gap-4">
|
||||||
<div className="flex size-11 shrink-0 items-center justify-center rounded-xl bg-primary/10 ring-1 ring-primary/20">
|
<div className="flex size-10 shrink-0 items-center justify-center rounded-xl bg-primary/10 ring-1 ring-primary/20 sm:size-12 sm:rounded-2xl">
|
||||||
<ScrollText className="size-5 text-primary" />
|
<ScrollText className="size-5 text-primary" />
|
||||||
</div>
|
</div>
|
||||||
<div className="min-w-0">
|
<div className="min-w-0">
|
||||||
<h2 className="text-base font-semibold">请阅读并同意以下协议</h2>
|
<h2 className="text-balance text-lg font-semibold tracking-tight sm:text-xl">请阅读并同意以下协议</h2>
|
||||||
<p className="mt-1 text-xs leading-relaxed text-muted-foreground">
|
<p className="mt-0.5 max-w-2xl text-pretty text-xs leading-relaxed text-muted-foreground sm:mt-1 sm:text-sm">
|
||||||
同意一次后无需重复确认;仅当协议内容更新时才会再次请求确认。
|
同意一次后无需重复确认;仅当协议内容更新时才会再次请求确认。
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{documents.length > 1 ? (
|
{documents.length > 1 ? (
|
||||||
<div className="mt-4 max-w-full overflow-x-auto">
|
<div className="mt-3 max-w-full overflow-x-auto pb-1 sm:mt-4">
|
||||||
<SegmentedControl
|
<SegmentedControl
|
||||||
label="协议文档"
|
label="协议文档"
|
||||||
value={activeId}
|
value={activeId}
|
||||||
@@ -238,19 +249,25 @@ function AgreementStep({
|
|||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{active && (active.declaredVersion || active.effectiveDate) ? (
|
{active && (active.declaredVersion || active.effectiveDate) ? (
|
||||||
<p className="mt-2 text-meta text-muted-foreground">
|
<p className="mt-1.5 px-0.5 text-meta leading-relaxed text-muted-foreground">
|
||||||
{active.declaredVersion ? `版本 / Version ${active.declaredVersion}` : ''}
|
{active.declaredVersion ? `版本 / Version ${active.declaredVersion}` : ''}
|
||||||
{active.declaredVersion && active.effectiveDate ? ' · ' : ''}
|
{active.declaredVersion && active.effectiveDate ? ' · ' : ''}
|
||||||
{active.effectiveDate ? `生效 / Effective ${active.effectiveDate}` : ''}
|
{active.effectiveDate ? `生效 / Effective ${active.effectiveDate}` : ''}
|
||||||
</p>
|
</p>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
<div className="mt-3 min-h-48 flex-1 overflow-y-auto rounded-lg border border-border bg-background/60 p-4">
|
<div
|
||||||
{active ? (
|
tabIndex={0}
|
||||||
<Markdown content={active.text} />
|
aria-label={active?.title ? `${active.title}正文` : '协议正文'}
|
||||||
) : (
|
className="mt-3 min-h-0 flex-1 overflow-y-auto overscroll-contain rounded-2xl border border-border/80 bg-background/55 p-3 outline-none shadow-[inset_0_1px_2px_rgb(0_0_0/0.06)] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/30 sm:p-5"
|
||||||
<p className="text-sm text-muted-foreground">未能加载协议文本,请刷新页面重试。</p>
|
>
|
||||||
)}
|
<div className="mx-auto max-w-3xl">
|
||||||
|
{active ? (
|
||||||
|
<Markdown content={active.text} />
|
||||||
|
) : (
|
||||||
|
<p className="text-sm text-muted-foreground">未能加载协议文本,请刷新页面重试。</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
@@ -258,7 +275,7 @@ function AgreementStep({
|
|||||||
onClick={() => setAgreed((current) => !current)}
|
onClick={() => setAgreed((current) => !current)}
|
||||||
aria-pressed={agreed}
|
aria-pressed={agreed}
|
||||||
className={cn(
|
className={cn(
|
||||||
'mt-3 flex w-full items-center gap-3 rounded-lg border px-3.5 py-2.5 text-left transition-colors',
|
'mt-3 flex min-h-11 w-full items-center gap-3 rounded-xl border px-3.5 py-2.5 text-start outline-none transition-[background-color,border-color,box-shadow] duration-150 focus-visible:ring-[3px] focus-visible:ring-ring/40 sm:min-h-12 sm:px-4 sm:py-3',
|
||||||
agreed
|
agreed
|
||||||
? 'border-primary/60 bg-primary/5'
|
? 'border-primary/60 bg-primary/5'
|
||||||
: 'border-border hover:border-primary/40 hover:bg-accent/40',
|
: 'border-border hover:border-primary/40 hover:bg-accent/40',
|
||||||
@@ -274,20 +291,20 @@ function AgreementStep({
|
|||||||
>
|
>
|
||||||
{agreed ? <Check className="size-3.5" strokeWidth={3} /> : null}
|
{agreed ? <Check className="size-3.5" strokeWidth={3} /> : null}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-sm font-medium">我已阅读并同意《用户协议》与《隐私政策》</span>
|
<span className="text-sm font-medium leading-relaxed">我已阅读并同意《用户协议》与《隐私政策》</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{error ? <p role="alert" className="mt-2 text-xs text-destructive">{error}</p> : null}
|
{error ? <p role="alert" className="mt-2 text-xs text-destructive">{error}</p> : null}
|
||||||
|
|
||||||
<div className="mt-3 flex items-center justify-between gap-2">
|
<div className="mt-3 flex items-center gap-3 sm:justify-between">
|
||||||
<span className="text-micro text-muted-foreground/70">
|
<span className="hidden text-micro text-muted-foreground/70 sm:inline">
|
||||||
agreements {version.slice(0, 8)}
|
agreements {version.slice(0, 8)}
|
||||||
</span>
|
</span>
|
||||||
<div className="flex gap-2">
|
<div className="grid w-full grid-cols-2 gap-3 sm:ml-auto sm:flex sm:w-auto sm:items-center">
|
||||||
<Button type="button" variant="ghost" onClick={onDecline} disabled={submitting}>
|
<Button type="button" variant="outline" onClick={onDecline} disabled={submitting} className="h-11 w-full sm:w-auto">
|
||||||
不同意并退出
|
不同意并退出
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="button" onClick={() => { void accept(); }} disabled={!agreed || submitting}>
|
<Button type="button" onClick={() => { void accept(); }} disabled={!agreed || submitting} className="h-11 w-full sm:min-w-36 sm:w-auto">
|
||||||
<ShieldCheck className="size-4" />
|
<ShieldCheck className="size-4" />
|
||||||
{submitting ? '提交中…' : '同意并继续'}
|
{submitting ? '提交中…' : '同意并继续'}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -299,11 +316,13 @@ function AgreementStep({
|
|||||||
|
|
||||||
function PasswordStep({
|
function PasswordStep({
|
||||||
knownOldPassword,
|
knownOldPassword,
|
||||||
|
mode,
|
||||||
checkStrength,
|
checkStrength,
|
||||||
submit,
|
submit,
|
||||||
onComplete,
|
onComplete,
|
||||||
}: {
|
}: {
|
||||||
knownOldPassword?: string;
|
knownOldPassword?: string;
|
||||||
|
mode: 'change' | 'rehearsal';
|
||||||
checkStrength: (password: string) => Promise<{ rules: PasswordRule[]; valid: boolean }>;
|
checkStrength: (password: string) => Promise<{ rules: PasswordRule[]; valid: boolean }>;
|
||||||
submit: (
|
submit: (
|
||||||
oldPassword: string,
|
oldPassword: string,
|
||||||
@@ -311,26 +330,46 @@ function PasswordStep({
|
|||||||
) => Promise<{ success: boolean; message?: string }>;
|
) => Promise<{ success: boolean; message?: string }>;
|
||||||
onComplete: () => void;
|
onComplete: () => void;
|
||||||
}) {
|
}) {
|
||||||
|
const { back } = useWizardNavigation();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto flex w-full max-w-lg flex-col">
|
<div className="mx-auto flex min-h-full w-full max-w-xl flex-col justify-center py-2 sm:py-5">
|
||||||
<div className="mb-5 flex items-start gap-3">
|
<div className="mb-8 flex items-start gap-4">
|
||||||
<div className="flex size-11 shrink-0 items-center justify-center rounded-xl bg-primary/10 ring-1 ring-primary/20">
|
<div className="flex size-12 shrink-0 items-center justify-center rounded-2xl bg-primary/10 ring-1 ring-primary/20">
|
||||||
<ShieldAlert className="size-5 text-primary" />
|
<ShieldAlert className="size-5 text-primary" />
|
||||||
</div>
|
</div>
|
||||||
<div className="min-w-0">
|
<div className="min-w-0">
|
||||||
<h2 className="text-base font-semibold">设置新的访问密码</h2>
|
<h2 className="text-balance text-lg font-semibold tracking-tight sm:text-xl">设置新的访问密码</h2>
|
||||||
<p className="mt-1 text-xs leading-relaxed text-muted-foreground">
|
<p className="mt-1 text-pretty text-sm leading-relaxed text-muted-foreground">
|
||||||
将首次启动生成的临时密码替换为符合要求的强密码。
|
{mode === 'rehearsal'
|
||||||
|
? '验证密码设置步骤的界面与规则;本次演练不会保存输入内容。'
|
||||||
|
: '将首次启动生成的临时密码替换为符合要求的强密码。'}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<ChangePasswordForm
|
<ChangePasswordForm
|
||||||
knownOldPassword={knownOldPassword}
|
knownOldPassword={knownOldPassword}
|
||||||
|
mode={mode}
|
||||||
checkStrength={checkStrength}
|
checkStrength={checkStrength}
|
||||||
submit={submit}
|
submit={submit}
|
||||||
onSuccess={onComplete}
|
onSuccess={onComplete}
|
||||||
idPrefix="onboarding-cpw"
|
idPrefix="onboarding-cpw"
|
||||||
submitLabel="保存并完成"
|
submitLabel={mode === 'rehearsal' ? '完成演练' : '保存并完成'}
|
||||||
|
className="gap-5"
|
||||||
|
renderActions={({ canSubmit, submitting, submitLabel }) => (
|
||||||
|
<div className="grid gap-3 pt-2 sm:flex sm:items-center">
|
||||||
|
<Button type="button" variant="outline" onClick={back} disabled={submitting} className="h-11 w-full sm:w-auto">
|
||||||
|
上一步
|
||||||
|
</Button>
|
||||||
|
<Button type="submit" disabled={!canSubmit} className="h-11 w-full sm:ml-auto sm:min-w-36 sm:w-auto">
|
||||||
|
{submitting ? (
|
||||||
|
<>
|
||||||
|
<Loader2 className="size-4 animate-spin" /> 提交中…
|
||||||
|
</>
|
||||||
|
) : submitLabel}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in new issue
Block a user