fix(app): settings and 去补点数 open in place on every page instead of going back to the chat first (BUG-2127)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXp2Vp62Ur3C7yRWQdSq
This commit is contained in:
@@ -28712,3 +28712,15 @@
|
||||
- 尚未处理:拆分方式是按原顺序重算每一小段,只在与原结果一致时保留,需占星师确认这符合她「不得重新执行任意表达式来猜分支」的要求;`any(...)` 一类单行表达式和多语句规则仍整体记录;整个表达式出错时不保留分支记录;资料章节的格局汇总表仍写「满足自定义条件」。
|
||||
- 关联记录:BUG-2075,占星师 2026-11-20 第 10 问。
|
||||
- 修复版本:`claude/custom-branch-trace-2124`。
|
||||
|
||||
## BUG-2127 | 不在聊天页时点头像菜单的设置,会先跳回聊天页再弹出设置
|
||||
|
||||
- 状态:fixed-pending-verify。
|
||||
- 首次发现 / 最近更新:2026-11-21 / 2026-11-21。
|
||||
- 触发与现象:在星盘、人物、报告、合盘、生时纠正、星历等页面点头像菜单里的个人资料 / 账户与点数 / 通用设置 / 退出,页面先跳到首页聊天界面,再弹出设置弹窗;各处「去补点数」也一样。
|
||||
- 触发条件:任何非首页页面。
|
||||
- 根因:设计限制,不是回归。设置弹窗的状态、遮罩、头像保存、退出、Esc 与焦点处理和 `?account=` 深链都只挂在首页 `(app)/page.tsx`;其他页面的菜单项因此只能是 `/?account=<dialog>` 链接(TASK-self-edit-avatar-menu-20260928 S2,`frontend/src/lib/account-dialog-intent.ts`),点了先回首页、首页加载完再开弹窗。
|
||||
- 修复:新 `frontend/src/components/account-dialog-provider.tsx`(`AccountDialogProvider` + `AccountDialogHost`)接管原来首页的弹窗状态和处理函数(函数体原样搬过来),挂在 `(app)/layout.tsx`,所有页面原地打开同一个弹窗;只用共享的会话列表账户,不另取账户,首页不重复加载、其他页面首屏不等它;`?account=` 深链在首页和其他页面都能用。侧栏菜单在非首页直接打开弹窗并把焦点还给头像;首页 `openAccountDialog` 改为调用共享的打开函数。年运报告、合盘选人、个人报告开始卡片、报告提问面板的「去补点数」改用 `BillingDialogLink`(同一个链接外观,普通点击原地打开账户与点数,带修饰键时仍是普通链接)。保留:`LegalConsentGate` 与 BUG-2072 报告提醒的挂载顺序和条件、BUG-2070 点数记录先关弹窗再跳转、BUG-2086 在其他页面保存头像不会让首页重走首次引导、BUG-2059 弹窗 880×640 且在提问面板之上。
|
||||
- 验证与防复发:`frontend/tests/account-dialogs-every-page-2127.test.tsx`(6 条:非首页打开不跳转、深链在首页和报告页都能打开且只去掉 account 参数、在合盘页保存头像后首次引导不重来、外壳只有一个弹窗且首页不再画遮罩、补点数链接原地打开与修饰键行为、四处入口不再用跳转链接);钉住旧链接的 15 个前端测试和 `tests/test_session_management_entrypoints.py` 按原值、新值、原因更新。本地生产构建在报告页、合盘报告页(提问面板打开)、星盘页看过:弹窗 880×640 盖在面板之上,网址不变,Esc 关闭后焦点回到头像。首页因登录状态带不到本机没有在浏览器里看,靠测试覆盖。
|
||||
- 关联记录:BUG-554、BUG-698、BUG-970、BUG-2059、BUG-2070、BUG-2072、BUG-2086,TASK-self-edit-avatar-menu-20260928。
|
||||
- 修复版本:`claude/settings-anywhere-2127`。
|
||||
|
||||
@@ -5,6 +5,7 @@ import dynamic from "next/dynamic";
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
|
||||
import { AccountDeletionGate } from "@/components/account-deletion-gate";
|
||||
import { AccountDialogHost, AccountDialogProvider, useAccountDialogs } from "@/components/account-dialog-provider";
|
||||
import { AppSidebar } from "@/components/app-sidebar";
|
||||
import { LegalConsentGate } from "@/components/legal/legal-consent-gate";
|
||||
import { ReportReminderWatcher } from "@/components/report-reminder-watcher";
|
||||
@@ -48,11 +49,16 @@ function AppShell({ children }: { children: ReactNode }) {
|
||||
}, [router]);
|
||||
// The rows' menu, delete confirmation and drag sorting, on every page (issue #116).
|
||||
const sessionActions = useShellSessionActions(list, registration?.sessionHooks ?? null);
|
||||
// The account dialogs open where the reader is, on every page (BUG-2127).
|
||||
const accountDialogs = useAccountDialogs();
|
||||
const accountDialogOpen = accountDialogs.activeDialog !== null;
|
||||
|
||||
return (
|
||||
<SidebarProvider escapeBlocked={registration?.escapeBlocked ?? false}>
|
||||
<SidebarProvider escapeBlocked={(registration?.escapeBlocked ?? false) || accountDialogOpen}>
|
||||
<OnboardingJourneyProvider>
|
||||
<main className="chat-app">
|
||||
{/* First, so a `/?account=` deep link is read before a page rewrites its URL (BUG-2127). */}
|
||||
<AccountDialogHost />
|
||||
<ShellFrame
|
||||
sidebar={(
|
||||
<AppSidebar
|
||||
@@ -66,6 +72,10 @@ function AppShell({ children }: { children: ReactNode }) {
|
||||
rectificationEnabled={rectificationEnabled}
|
||||
controls={registration?.controls}
|
||||
sessionControls={sessionActions.controls}
|
||||
onOpenAccountDialog={(dialog, returnTarget) => {
|
||||
// Same source as the menu on `/` (use-home-shell-registration).
|
||||
accountDialogs.open(dialog, { returnTarget, source: dialog === "billing" ? "account-menu" : undefined });
|
||||
}}
|
||||
onOpenSession={(sessionId) => {
|
||||
navigateAppPath(sessionHref("", sessionId), router.push);
|
||||
}}
|
||||
@@ -101,7 +111,9 @@ function AppShell({ children }: { children: ReactNode }) {
|
||||
export default function AppLayout({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<SessionListProvider>
|
||||
<AppShell>{children}</AppShell>
|
||||
<AccountDialogProvider>
|
||||
<AppShell>{children}</AppShell>
|
||||
</AccountDialogProvider>
|
||||
</SessionListProvider>
|
||||
);
|
||||
}
|
||||
|
||||
+25
-111
@@ -1,19 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import dynamic from "next/dynamic";
|
||||
import { BillingBalance, BillingPagesWaiting } from "@/components/billing-balance";
|
||||
import { loadBillingPanel, prefetchBillingPanel, prefetchBillingPanelWhenIdle } from "@/lib/billing-panel-loader";
|
||||
import { prefetchBillingPanelWhenIdle } from "@/lib/billing-panel-loader";
|
||||
import type { BirthHistorySubject, ConsultationBirthHistory } from "@/lib/consultation-birth-history";
|
||||
import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
||||
import type { FormEvent, KeyboardEvent } from "react";
|
||||
import { AccountDialogOverlay, type AccountOverlayModel } from "@/components/account-dialog-overlay";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useAccountDialogs } from "@/components/account-dialog-provider";
|
||||
import { navigateInApp } from "@/lib/app-navigation";
|
||||
import { RECTIFICATION_PAGE_HREF } from "@/lib/chat-session-url";
|
||||
import { birthTimeNeedsRectification } from "@/lib/rectification-links";
|
||||
import { ProfilePanel } from "@/components/profile-panel";
|
||||
import { AccountDeletionSection } from "@/components/account-deletion-section";
|
||||
import { ThemePreferencePanel } from "@/components/theme-preference-menu";
|
||||
import type { BirthTimeAssessmentPhase } from "@/components/birth-time-assessment-overlay";
|
||||
import { OnboardingChecklistSlot } from "@/components/onboarding-checklist-slot";
|
||||
import { HomeBootstrapError } from "@/components/home-bootstrap-error";
|
||||
@@ -48,7 +42,7 @@ import { personRelationLabel } from "@/lib/person-relation";
|
||||
import { readStarterSignMap, readStarterSigns, subscribeStarterSigns } from "@/lib/starter-questions";
|
||||
import { OnboardingChartDot } from "@/components/onboarding-dot";
|
||||
import { OnboardingHomeBridge } from "@/components/onboarding-home-bridge";
|
||||
import { AccountDialogDeepLink, SynastryDeepLink } from "@/components/people-home-links";
|
||||
import { SynastryDeepLink } from "@/components/people-home-links";
|
||||
import { StarterGreeting } from "@/components/starter-home";
|
||||
import { StarterQuestions } from "@/components/starter-questions";
|
||||
import { type ConsultationEntrypoint } from "@/lib/consultation-entrypoint";
|
||||
@@ -67,7 +61,6 @@ import { useProfileOnboarding } from "@/hooks/use-profile-onboarding";
|
||||
import { useSessionManagement } from "@/hooks/use-session-management";
|
||||
import { showChatNotice as setComposerNotice } from "@/lib/chat-notice";
|
||||
import { chatReplyAnnouncement, type ChatReplyPhase } from "@/lib/chat-reply-announcement";
|
||||
import { keepFocusWithin } from "@/lib/focus-trap";
|
||||
import {
|
||||
BALANCE_SYNC_KEY,
|
||||
BALANCE_CHANGED_EVENT,
|
||||
@@ -108,8 +101,7 @@ import {
|
||||
type PublicLanguageModelCatalog,
|
||||
} from "@/lib/public-models";
|
||||
import {
|
||||
accountDialogClasses,
|
||||
accountDialogTitles,
|
||||
accountDialogOptions,
|
||||
pendingConsultationStorageKey,
|
||||
presetOnboardingMessage,
|
||||
type AccountDialog,
|
||||
@@ -167,12 +159,6 @@ import {
|
||||
|
||||
const EMPTY_SUBJECT_CATALOG: readonly ChartLibraryRecord[] = [];
|
||||
|
||||
const BillingPanel = dynamic(loadBillingPanel, {
|
||||
ssr: false,
|
||||
// BUG-2059: the tab line and bars of the real heights, never a sentence or a blank.
|
||||
loading: () => <BillingPagesWaiting />,
|
||||
});
|
||||
|
||||
|
||||
let nudgeComposerTimer: number | undefined;
|
||||
|
||||
@@ -213,11 +199,11 @@ export default function Home() {
|
||||
// it decides once per mount. Null means the unchanged cold bootstrap.
|
||||
const warmStart = () => takeHomeWarmStart(() => homeWarmStartInput(sessionList));
|
||||
const [accountMenuOpen, setAccountMenuOpen] = useState(false);
|
||||
const [activeAccountDialog, setActiveAccountDialog] = useState<AccountDialog | null>(null);
|
||||
// The account dialogs are the app shell's (BUG-2127): the same ones on every page.
|
||||
const accountDialogs = useAccountDialogs();
|
||||
const activeAccountDialog = accountDialogs.activeDialog;
|
||||
const [chartLibrary, setChartLibrary] = useState<ChartLibraryRecord[]>([]);
|
||||
const [billingPane, setBillingPane] = useState<OpenAccountDialogOptions>({});
|
||||
const [accountError, setAccountError] = useState("");
|
||||
const [signingOut, setSigningOut] = useState(false);
|
||||
const [modelCatalog, setModelCatalog] = useState<PublicLanguageModelCatalog | null>(() => {
|
||||
const warm = warmStart();
|
||||
useSessionStore.getState().mountHomeConversation(warm?.landing.activeSessionId ?? "");
|
||||
@@ -288,9 +274,6 @@ export default function Home() {
|
||||
const [presetMessageLength, setPresetMessageLength] = useState(0);
|
||||
const conversation = useRef<HTMLDivElement>(null);
|
||||
const accountTrigger = useRef<HTMLButtonElement>(null);
|
||||
const accountDialog = useRef<HTMLElement>(null);
|
||||
const dialogReturnTargetRef = useRef<HTMLButtonElement | null>(null);
|
||||
const closeButton = useRef<HTMLButtonElement>(null);
|
||||
const onboardingPaywallShown = useRef(false);
|
||||
const starterGreetingUnseen = useRef(true);
|
||||
const composerInput = useRef<HTMLTextAreaElement>(null);
|
||||
@@ -328,36 +311,42 @@ export default function Home() {
|
||||
profile,
|
||||
setProfile,
|
||||
setProfileDraft,
|
||||
profileNotice,
|
||||
setProfileNotice,
|
||||
avatarSaving,
|
||||
profileSaving,
|
||||
refreshAccount,
|
||||
openAccountDialog,
|
||||
closeAccountDialog,
|
||||
persistAvatar,
|
||||
saveOnboardingName,
|
||||
saveOnboardingBirth,
|
||||
saveOnboardingPlace,
|
||||
signOut,
|
||||
onboardingDraft,
|
||||
setOnboardingDraft,
|
||||
intakeTarget,
|
||||
chooseOnboardingSelf,
|
||||
chooseOnboardingOther,
|
||||
} = useProfileOnboarding({
|
||||
account, accountRefreshGuard, accountTrigger,
|
||||
dialogReturnTargetRef,
|
||||
setAccount, setAccountError, setAccountMenuOpen, setActiveAccountDialog,
|
||||
account, accountRefreshGuard,
|
||||
setAccount, setAccountError,
|
||||
setBirthTimeAssessmentPhase,
|
||||
setBillingPane, setDraft,
|
||||
setDraft,
|
||||
setOnboardingJustCompleted, setOnboardingStep, setPresetMessageLength,
|
||||
setSigningOut, setStartGreeting, signingOut, uiPreview,
|
||||
setStartGreeting, uiPreview,
|
||||
initialProfile: () => warmStart()?.profile ?? null,
|
||||
onOwnBirthPlaceSaved: birthSkyReveal.begin,
|
||||
chartLibrary: subjectCatalog,
|
||||
});
|
||||
|
||||
// Home's way into the shell's account dialogs: its own menu closes, and focus
|
||||
// goes back to the avatar unless the caller names another trigger.
|
||||
function openAccountDialog(
|
||||
dialog: AccountDialog,
|
||||
returnTargetOrOptions?: HTMLButtonElement | null | OpenAccountDialogOptions,
|
||||
) {
|
||||
const options = accountDialogOptions(returnTargetOrOptions);
|
||||
setAccountMenuOpen(false);
|
||||
setAccountError("");
|
||||
if (dialog === "profile") setProfileNotice("");
|
||||
accountDialogs.open(dialog, { ...options, returnTarget: options.returnTarget ?? accountTrigger.current });
|
||||
}
|
||||
|
||||
const activeSession = sessions.find((session) => session.id === activeSessionId)
|
||||
?? pendingWarmLandingSession(activeSessionId)
|
||||
?? sessions.find((session) => !isRetiredRectificationSession(session) && sessionMatchesSubject(session, readCurrentSubjectId()));
|
||||
@@ -833,35 +822,10 @@ export default function Home() {
|
||||
}, [startNewChat]);
|
||||
|
||||
// BUG-2057: the 账户与点数 panel is downloaded while the home page is idle,
|
||||
// and at the latest when any settings section opens.
|
||||
// and at the latest when any settings section opens (the shell's account dialogs).
|
||||
useEffect(() => {
|
||||
if (accountId && hydrated) prefetchBillingPanelWhenIdle();
|
||||
}, [accountId, hydrated]);
|
||||
useEffect(() => {
|
||||
if (activeAccountDialog !== null) prefetchBillingPanel();
|
||||
}, [activeAccountDialog]);
|
||||
|
||||
useEffect(() => {
|
||||
if (activeAccountDialog === null) return;
|
||||
window.requestAnimationFrame(() => {
|
||||
if (signingOut) return;
|
||||
closeButton.current?.focus();
|
||||
});
|
||||
const closeOnEscape = (event: globalThis.KeyboardEvent) => {
|
||||
if (event.key === "Escape") {
|
||||
if (signingOut) return;
|
||||
setActiveAccountDialog(null);
|
||||
const returnTarget = dialogReturnTargetRef.current;
|
||||
window.requestAnimationFrame(() => returnTarget?.focus());
|
||||
return;
|
||||
}
|
||||
const container = accountDialog.current;
|
||||
if (container) keepFocusWithin(event, container);
|
||||
};
|
||||
window.addEventListener("keydown", closeOnEscape);
|
||||
return () => window.removeEventListener("keydown", closeOnEscape);
|
||||
}, [activeAccountDialog, signingOut]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!accountId || !hydrated) return;
|
||||
const onBalanceStorage = (event: StorageEvent) => {
|
||||
@@ -1065,50 +1029,6 @@ export default function Home() {
|
||||
);
|
||||
}
|
||||
|
||||
const accountOverlayModel: AccountOverlayModel | null = activeAccountDialog === null ? null : {
|
||||
title: activeAccountDialog ? accountDialogTitles[activeAccountDialog] : "",
|
||||
dialogClass: activeAccountDialog ? accountDialogClasses[activeAccountDialog] : "",
|
||||
signingOut,
|
||||
close: closeAccountDialog,
|
||||
navigate: (dialog) => openAccountDialog(dialog, dialogReturnTargetRef.current),
|
||||
overlayRef: accountDialog,
|
||||
closeButtonRef: closeButton,
|
||||
renderProfile: () => (
|
||||
<ProfilePanel
|
||||
account={account}
|
||||
profile={profile}
|
||||
avatarSaving={avatarSaving}
|
||||
persistAvatar={persistAvatar}
|
||||
onAvatarImageChange={(version) => setAccount((current) => current ? { ...current, avatarImage: version === null ? null : { version } } : current)}
|
||||
/>
|
||||
),
|
||||
renderChartLibrary() {
|
||||
return null;
|
||||
},
|
||||
renderBilling: () => (
|
||||
<div className="billing-panel">
|
||||
{/* BUG-2059: the balance is drawn here, not in the lazy panel, so it is on screen at once. */}
|
||||
<BillingBalance credits={account.credits} />
|
||||
<BillingPanel account={account} highlightedPlan={billingPane.plan ?? null} initialTab={billingPane.tab} onNavigate={closeAccountDialog} />
|
||||
</div>
|
||||
),
|
||||
|
||||
renderGeneral() {
|
||||
return <><ThemePreferencePanel /><AccountDeletionSection /></>;
|
||||
},
|
||||
renderLogout() {
|
||||
return (
|
||||
<>
|
||||
<p className="logout-copy">退出后,需要重新登录才能继续查看对话。</p>
|
||||
<div className="dialog-actions">
|
||||
<Button variant="outline" type="button" onClick={closeAccountDialog} disabled={signingOut}>取消</Button>
|
||||
<Button variant="destructive" type="button" onClick={() => void signOut()} disabled={signingOut}>{signingOut ? "正在退出" : "确认退出"}</Button>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
// One person switcher, in the top bar only (2026-11-02; issue #150 had a second one above the chart panel).
|
||||
const subjectPicker = activeSession?.sessionType === "consultation" || activeSession?.sessionType === "synastry_report" ? (
|
||||
<ChatProfilePicker
|
||||
@@ -1133,7 +1053,6 @@ export default function Home() {
|
||||
profile={profile}
|
||||
/>
|
||||
<SynastryDeepLink />
|
||||
<AccountDialogDeepLink ready={hydrated && Boolean(account)} open={openAccountDialog} />
|
||||
<span className="sr-only" role="status" aria-live="polite" aria-atomic="true">{replyAnnouncement}</span>
|
||||
<header className="chat-header">
|
||||
<span className="onboarding-menu-anchor">
|
||||
@@ -1258,11 +1177,6 @@ export default function Home() {
|
||||
: null}
|
||||
|
||||
<BirthSkyReveal cover={birthSkyReveal.cover} onClose={birthSkyReveal.close} />
|
||||
<AccountDialogOverlay
|
||||
open={activeAccountDialog !== null}
|
||||
dialog={activeAccountDialog}
|
||||
model={accountOverlayModel}
|
||||
/>
|
||||
{onboardingPaywallOpen && account && (
|
||||
<OnboardingRedeemPaywall
|
||||
credits={account.credits}
|
||||
|
||||
@@ -0,0 +1,333 @@
|
||||
"use client";
|
||||
|
||||
import dynamic from "next/dynamic";
|
||||
import { usePathname } from "next/navigation";
|
||||
import {
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
type MouseEvent,
|
||||
type ReactNode,
|
||||
} from "react";
|
||||
|
||||
import { AccountDeletionSection } from "@/components/account-deletion-section";
|
||||
import { AccountDialogOverlay, type AccountOverlayModel } from "@/components/account-dialog-overlay";
|
||||
import { BillingBalance, BillingPagesWaiting } from "@/components/billing-balance";
|
||||
import { AccountDialogDeepLink } from "@/components/people-home-links";
|
||||
import { ProfilePanel } from "@/components/profile-panel";
|
||||
import { ThemePreferencePanel } from "@/components/theme-preference-menu";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useSessionList } from "@/hooks/use-session-list";
|
||||
import { accountDialogHref } from "@/lib/account-dialog-intent";
|
||||
import { beamAvatarSchema, type BeamAvatarPatch } from "@/lib/beam-avatar";
|
||||
import { loadBillingPanel, prefetchBillingPanel } from "@/lib/billing-panel-loader";
|
||||
import { clearBirthSkyMemory } from "@/lib/birth-sky/cover";
|
||||
import { keepFocusWithin } from "@/lib/focus-trap";
|
||||
import { friendlyError } from "@/lib/home-cloud-sync";
|
||||
import { readProfile } from "@/lib/home-profile";
|
||||
import {
|
||||
accountDialogClasses,
|
||||
accountDialogOptions,
|
||||
accountDialogTitles,
|
||||
type AccountDialog,
|
||||
type OpenAccountDialogOptions,
|
||||
} from "@/lib/home-types";
|
||||
import { clearHomeWarmSnapshot } from "@/lib/home-warm-snapshot";
|
||||
import { notifyError, notifySuccess } from "@/lib/notify";
|
||||
import { clearChartPageCache } from "@/lib/secondary-page-data";
|
||||
|
||||
/**
|
||||
* The account dialogs (个人资料 / 账户与点数 / 通用设置 / 退出登录) on every
|
||||
* page of the app shell (BUG-2127). They lived on `/` only, so the avatar menu
|
||||
* on any other page went to `/?account=<dialog>` and the reader landed on the
|
||||
* chat page. The state, the actions and the overlay are mounted once by
|
||||
* `(app)/layout.tsx`; Home and the sidebar call the same `open`.
|
||||
*
|
||||
* Nothing here reads the account: it is the layout's session-list account,
|
||||
* the one Home already uses, so no page loads it twice and no page waits for it.
|
||||
*/
|
||||
|
||||
const BillingPanel = dynamic(loadBillingPanel, {
|
||||
ssr: false,
|
||||
// BUG-2059: the tab line and bars of the real heights, never a sentence or a blank.
|
||||
loading: () => <BillingPagesWaiting />,
|
||||
});
|
||||
|
||||
export type AccountDialogsValue = Readonly<{
|
||||
activeDialog: AccountDialog | null;
|
||||
open: (dialog: AccountDialog, returnTargetOrOptions?: HTMLButtonElement | null | OpenAccountDialogOptions) => void;
|
||||
close: () => void;
|
||||
}>;
|
||||
|
||||
const AccountDialogContext = createContext<AccountDialogsValue | null>(null);
|
||||
|
||||
const INERT_ACCOUNT_DIALOGS: AccountDialogsValue = {
|
||||
activeDialog: null,
|
||||
open: () => undefined,
|
||||
close: () => undefined,
|
||||
};
|
||||
|
||||
/** The shell's account dialogs. Outside the provider (unit tests that mount a page alone): never open. */
|
||||
export function useAccountDialogs(): AccountDialogsValue {
|
||||
return useContext(AccountDialogContext) ?? INERT_ACCOUNT_DIALOGS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 「去补点数」 inside the app: 账户与点数 opens over the page the reader is on
|
||||
* (BUG-2127; these were links to `/?account=billing`, which went to the chat
|
||||
* page first). Still a real link to the deep link, so a new tab, a modified
|
||||
* click, or a render outside the shell lands on the same dialog.
|
||||
*/
|
||||
export function BillingDialogLink({ children, className }: { children: ReactNode; className?: string }) {
|
||||
const dialogs = useContext(AccountDialogContext);
|
||||
return (
|
||||
<a
|
||||
className={className}
|
||||
href={accountDialogHref("billing")}
|
||||
onClick={(event: MouseEvent<HTMLAnchorElement>) => {
|
||||
if (!dialogs || event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
|
||||
event.preventDefault();
|
||||
dialogs.open("billing", { source: "insufficient-credits" });
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
type AccountDialogState = Readonly<{
|
||||
activeDialog: AccountDialog | null;
|
||||
billingPane: OpenAccountDialogOptions;
|
||||
signingOut: boolean;
|
||||
avatarSaving: boolean;
|
||||
}>;
|
||||
|
||||
type AccountDialogInternals = Readonly<{
|
||||
state: AccountDialogState;
|
||||
signOut: () => Promise<void>;
|
||||
persistAvatar: (patch: BeamAvatarPatch) => Promise<void>;
|
||||
overlayRef: { current: HTMLElement | null };
|
||||
closeButtonRef: { current: HTMLButtonElement | null };
|
||||
returnTargetRef: { current: HTMLButtonElement | null };
|
||||
}>;
|
||||
|
||||
const AccountDialogStateContext = createContext<AccountDialogInternals | null>(null);
|
||||
|
||||
/** What the overlay draws from: the panes' state and their two writes (avatar, sign-out). */
|
||||
export function useAccountDialogInternals(): AccountDialogInternals | null {
|
||||
return useContext(AccountDialogStateContext);
|
||||
}
|
||||
|
||||
export function AccountDialogProvider({ children }: { children: ReactNode }) {
|
||||
const { account, setAccount } = useSessionList();
|
||||
const [activeDialog, setActiveDialog] = useState<AccountDialog | null>(null);
|
||||
const [billingPane, setBillingPane] = useState<OpenAccountDialogOptions>({});
|
||||
const [signingOut, setSigningOut] = useState(false);
|
||||
const [avatarSaving, setAvatarSaving] = useState(false);
|
||||
const overlayRef = useRef<HTMLElement | null>(null);
|
||||
const closeButtonRef = useRef<HTMLButtonElement | null>(null);
|
||||
const returnTargetRef = useRef<HTMLButtonElement | null>(null);
|
||||
const signingOutRef = useRef(false);
|
||||
const avatarSavingRef = useRef(false);
|
||||
const accountRef = useRef(account);
|
||||
useEffect(() => {
|
||||
signingOutRef.current = signingOut;
|
||||
avatarSavingRef.current = avatarSaving;
|
||||
accountRef.current = account;
|
||||
});
|
||||
|
||||
const open = useCallback((
|
||||
dialog: AccountDialog,
|
||||
returnTargetOrOptions?: HTMLButtonElement | null | OpenAccountDialogOptions,
|
||||
) => {
|
||||
const options = accountDialogOptions(returnTargetOrOptions);
|
||||
returnTargetRef.current = options.returnTarget ?? null;
|
||||
if (dialog === "chart-library") {
|
||||
window.location.assign("/people");
|
||||
return;
|
||||
}
|
||||
if (dialog === "billing") {
|
||||
setBillingPane({
|
||||
source: options.source,
|
||||
plan: options.plan,
|
||||
tab: options.tab,
|
||||
});
|
||||
}
|
||||
setActiveDialog(dialog);
|
||||
}, []);
|
||||
|
||||
const close = useCallback(() => {
|
||||
if (signingOutRef.current) return;
|
||||
setActiveDialog(null);
|
||||
const returnTarget = returnTargetRef.current;
|
||||
window.requestAnimationFrame(() => returnTarget?.focus());
|
||||
}, []);
|
||||
|
||||
const persistAvatar = useCallback(async (patch: BeamAvatarPatch) => {
|
||||
if (!accountRef.current?.avatar || avatarSavingRef.current) return;
|
||||
avatarSavingRef.current = true;
|
||||
setAvatarSaving(true);
|
||||
try {
|
||||
const response = await fetch("/api/account/avatar", {
|
||||
method: "PATCH",
|
||||
credentials: "same-origin",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify(patch),
|
||||
});
|
||||
const payload = await response.json().catch(() => null) as { avatar?: unknown; error?: string } | null;
|
||||
if (!response.ok) throw new Error(payload?.error || "头像暂时无法保存。");
|
||||
const avatar = beamAvatarSchema.parse(payload?.avatar);
|
||||
setAccount((current) => current ? { ...current, avatar } : current);
|
||||
notifySuccess(patch.action === "randomize" ? "已生成并保存新头像。" : "头像配色已保存。");
|
||||
} catch (caught) {
|
||||
notifyError(friendlyError(caught instanceof Error ? caught.message : "头像保存失败"));
|
||||
} finally {
|
||||
avatarSavingRef.current = false;
|
||||
setAvatarSaving(false);
|
||||
}
|
||||
}, [setAccount]);
|
||||
|
||||
const signOut = useCallback(async () => {
|
||||
if (signingOutRef.current) return;
|
||||
signingOutRef.current = true;
|
||||
setSigningOut(true);
|
||||
try {
|
||||
// The auth client is only needed here, so it is not in the first screen (issue #125).
|
||||
const { selfHostedOtpActions } = await import("@/modules/identity/client");
|
||||
// Signing out ends this account's warm return to `/` (BUG-1040); a
|
||||
// failed sign-out only costs one loading ring on the next return.
|
||||
// Nor does this account's chart stay in memory for the next one (BUG-1530).
|
||||
clearChartPageCache();
|
||||
clearBirthSkyMemory();
|
||||
clearHomeWarmSnapshot();
|
||||
await selfHostedOtpActions.signOut();
|
||||
window.location.assign("/login");
|
||||
} catch (caught) {
|
||||
const message = caught instanceof Error ? caught.message : "退出失败";
|
||||
notifyError(friendlyError(message));
|
||||
signingOutRef.current = false;
|
||||
setSigningOut(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// BUG-2057: the 账户与点数 panel is downloaded at the latest when any settings section opens.
|
||||
useEffect(() => {
|
||||
if (activeDialog !== null) prefetchBillingPanel();
|
||||
}, [activeDialog]);
|
||||
|
||||
useEffect(() => {
|
||||
if (activeDialog === null) return;
|
||||
window.requestAnimationFrame(() => {
|
||||
if (signingOut) return;
|
||||
closeButtonRef.current?.focus();
|
||||
});
|
||||
const closeOnEscape = (event: globalThis.KeyboardEvent) => {
|
||||
if (event.key === "Escape") {
|
||||
if (signingOut) return;
|
||||
setActiveDialog(null);
|
||||
const returnTarget = returnTargetRef.current;
|
||||
window.requestAnimationFrame(() => returnTarget?.focus());
|
||||
return;
|
||||
}
|
||||
const container = overlayRef.current;
|
||||
if (container) keepFocusWithin(event, container);
|
||||
};
|
||||
window.addEventListener("keydown", closeOnEscape);
|
||||
return () => window.removeEventListener("keydown", closeOnEscape);
|
||||
}, [activeDialog, signingOut]);
|
||||
|
||||
const value = useMemo<AccountDialogsValue>(() => ({ activeDialog, open, close }), [activeDialog, open, close]);
|
||||
const state = useMemo(() => ({
|
||||
state: { activeDialog, billingPane, signingOut, avatarSaving },
|
||||
signOut,
|
||||
persistAvatar,
|
||||
overlayRef,
|
||||
closeButtonRef,
|
||||
returnTargetRef,
|
||||
}), [activeDialog, avatarSaving, billingPane, persistAvatar, signOut, signingOut]);
|
||||
|
||||
return (
|
||||
<AccountDialogContext.Provider value={value}>
|
||||
<AccountDialogStateContext.Provider value={state}>
|
||||
{children}
|
||||
</AccountDialogStateContext.Provider>
|
||||
</AccountDialogContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The overlay itself, and the `/?account=<dialog>` deep link (external links,
|
||||
* the paywall, the redeem flows). Mounted once by the app layout. The deep
|
||||
* link is read again on every page entry, so a link to it from any page works.
|
||||
*/
|
||||
export function AccountDialogHost() {
|
||||
const holder = useAccountDialogInternals();
|
||||
const dialogs = useAccountDialogs();
|
||||
const { account, setAccount } = useSessionList();
|
||||
const pathname = usePathname() ?? "";
|
||||
const profile = useMemo(() => readProfile(account?.profile), [account?.profile]);
|
||||
const { open, close } = dialogs;
|
||||
const openFromLink = useCallback((dialog: AccountDialog, options?: OpenAccountDialogOptions) => {
|
||||
// Focus goes back to the avatar when the dialog closes, as from the menu.
|
||||
const trigger = document.querySelector<HTMLButtonElement>("button.sidebar-account-trigger");
|
||||
open(dialog, { ...options, returnTarget: trigger });
|
||||
}, [open]);
|
||||
if (!holder) return null;
|
||||
const { state, signOut, persistAvatar, overlayRef, closeButtonRef, returnTargetRef } = holder;
|
||||
const { activeDialog, billingPane, signingOut, avatarSaving } = state;
|
||||
|
||||
const model: AccountOverlayModel | null = activeDialog === null || !account ? null : {
|
||||
title: accountDialogTitles[activeDialog],
|
||||
dialogClass: accountDialogClasses[activeDialog],
|
||||
signingOut,
|
||||
close,
|
||||
navigate: (dialog) => open(dialog, returnTargetRef.current),
|
||||
overlayRef,
|
||||
closeButtonRef,
|
||||
renderProfile: () => (
|
||||
<ProfilePanel
|
||||
account={account}
|
||||
profile={profile}
|
||||
avatarSaving={avatarSaving}
|
||||
persistAvatar={persistAvatar}
|
||||
onAvatarImageChange={(version) => setAccount((current) => current ? { ...current, avatarImage: version === null ? null : { version } } : current)}
|
||||
/>
|
||||
),
|
||||
renderChartLibrary() {
|
||||
return null;
|
||||
},
|
||||
// BUG-2070: a ledger row that opens another page closes the dialog first, on every page.
|
||||
renderBilling: () => (
|
||||
<div className="billing-panel">
|
||||
{/* BUG-2059: the balance is drawn here, not in the lazy panel, so it is on screen at once. */}
|
||||
<BillingBalance credits={account.credits} />
|
||||
<BillingPanel account={account} highlightedPlan={billingPane.plan ?? null} initialTab={billingPane.tab} onNavigate={close} />
|
||||
</div>
|
||||
),
|
||||
renderGeneral() {
|
||||
return <><ThemePreferencePanel /><AccountDeletionSection /></>;
|
||||
},
|
||||
renderLogout() {
|
||||
return (
|
||||
<>
|
||||
<p className="logout-copy">退出后,需要重新登录才能继续查看对话。</p>
|
||||
<div className="dialog-actions">
|
||||
<Button variant="outline" type="button" onClick={close} disabled={signingOut}>取消</Button>
|
||||
<Button variant="destructive" type="button" onClick={() => void signOut()} disabled={signingOut}>{signingOut ? "正在退出" : "确认退出"}</Button>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<AccountDialogDeepLink key={pathname} ready={Boolean(account)} open={openFromLink} />
|
||||
<AccountDialogOverlay open={activeDialog !== null} dialog={activeDialog} model={model} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -29,7 +29,7 @@ import { REPORT_ASK_TEXT } from "@/lib/report-ask-client";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
|
||||
import { useVisibilityAwarePoll } from "@/hooks/use-visibility-aware-poll";
|
||||
import { accountDialogHref } from "@/lib/account-dialog-intent";
|
||||
import { BillingDialogLink } from "@/components/account-dialog-provider";
|
||||
import { reportPriceLine, reportStartErrorFor } from "@/lib/report-start-copy";
|
||||
import { notifyError } from "@/lib/notify";
|
||||
import { askNotificationPermissionOnce, reportStatusesSeen, watchStartedReport } from "@/lib/report-reminders";
|
||||
@@ -539,7 +539,7 @@ export function AnnualOverlay(props: Readonly<{
|
||||
{props.error ? (
|
||||
<p className="annual-error" role="alert">
|
||||
{props.error.message}
|
||||
{props.error.billing ? <> <a href={accountDialogHref("billing")}>去补点数</a></> : null}
|
||||
{props.error.billing ? <> <BillingDialogLink>去补点数</BillingDialogLink></> : null}
|
||||
</p>
|
||||
) : <p className="annual-price">{priceLine(overview.creditCost)}</p>}
|
||||
{overview.existing?.status === "ready" ? (
|
||||
|
||||
@@ -28,9 +28,8 @@ import {
|
||||
import { usePathname } from "next/navigation";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import type { MouseEvent, ReactNode, Ref } from "react";
|
||||
import { AppLink } from "@/components/app-link";
|
||||
import { OnboardingDot } from "@/components/onboarding-dot";
|
||||
import { accountDialogHref, type AccountDialogIntent } from "@/lib/account-dialog-intent";
|
||||
import type { AccountDialogIntent } from "@/lib/account-dialog-intent";
|
||||
import { newChatHref, sessionHref } from "@/lib/chat-session-url";
|
||||
import { useOnboardingJourneyOptional } from "@/lib/onboarding-journey";
|
||||
import { prefetchSecondaryPage } from "@/lib/secondary-page-data";
|
||||
@@ -78,9 +77,10 @@ export type SidebarAccount = {
|
||||
/**
|
||||
* Everything only `/` can supply: new chat in place, opening a row in place,
|
||||
* and the settings dialogs behind the account menu. Omit `controls` and new
|
||||
* chat is a link, a row opens `/?c=<id>`, and the account menu's dialog
|
||||
* entries become links to `/?account=<dialog>`
|
||||
* (TASK-self-edit-avatar-menu-20260928 S2).
|
||||
* chat is a link and a row opens `/?c=<id>`. The account menu's dialog
|
||||
* entries open in place on every page: through `controls` on `/`, through
|
||||
* `onOpenAccountDialog` (the shell's account dialogs) elsewhere (BUG-2127;
|
||||
* they were links to `/?account=<dialog>`, which took the reader to the chat).
|
||||
*
|
||||
* The rows' own menu (收藏、重命名、转发、删除) and drag sorting are not in
|
||||
* here: they come from the shell through `sessionControls` on every page
|
||||
@@ -125,6 +125,8 @@ export type AppSidebarProps = {
|
||||
sessionControls?: SidebarSessionControls | null;
|
||||
/** Opens a row off `/`: the shell routes it to `/?c=<id>`. `controls` wins on `/`. */
|
||||
onOpenSession?: (sessionId: string) => void;
|
||||
/** Off `/`: opens an account dialog in place, from the shell's account dialogs (BUG-2127). `controls` wins on `/`. */
|
||||
onOpenAccountDialog?: (dialog: AccountDialogIntent, returnTarget: HTMLButtonElement | null) => void;
|
||||
};
|
||||
|
||||
const NAV_PAGES = [
|
||||
@@ -148,6 +150,7 @@ export function AppSidebar({
|
||||
controls,
|
||||
sessionControls,
|
||||
onOpenSession,
|
||||
onOpenAccountDialog,
|
||||
}: AppSidebarProps) {
|
||||
const { isMobile, setOpen, setOpenMobile, state, viewport } = useSidebar();
|
||||
const showChartDot = useOnboardingJourneyOptional()?.showChartDot ?? false;
|
||||
@@ -180,6 +183,8 @@ export function AppSidebar({
|
||||
const onSelectSession = controlledSelectSession ?? onOpenSession;
|
||||
/* Off `/` nothing controls the account menu, so it keeps its own open state (S2). */
|
||||
const [ownMenuOpen, setOwnMenuOpen] = useState(false);
|
||||
/* Off `/` the avatar is where focus goes back when the dialog closes. */
|
||||
const ownTriggerRef = useRef<HTMLButtonElement>(null);
|
||||
/* 反馈与投诉 is the sidebar's own dialog, so it opens the same way on every page. */
|
||||
const [feedbackOpen, setFeedbackOpen] = useState(false);
|
||||
/* 「新建对话」 off `/` waiting for the home's warm snapshot (BUG-1509). */
|
||||
@@ -343,8 +348,9 @@ export function AppSidebar({
|
||||
);
|
||||
}
|
||||
|
||||
/* One entry of the account menu: on `/` the dialog opens in place; on
|
||||
another page the entry is a link to `/?account=<dialog>` (S2). */
|
||||
/* One entry of the account menu. The dialog opens in place on every page:
|
||||
on `/` through Home's controls, elsewhere through the shell (BUG-2127;
|
||||
off `/` the entry used to be a link to `/?account=<dialog>`). */
|
||||
function accountEntry(
|
||||
dialog: AccountDialogIntent,
|
||||
onOpen: (() => void) | undefined,
|
||||
@@ -352,17 +358,12 @@ export function AppSidebar({
|
||||
content: ReactNode,
|
||||
pointer: { onPointerEnter?: () => void; onPointerDown?: () => void } = {},
|
||||
) {
|
||||
return onOpen ? (
|
||||
<DropdownMenuItem className={className} onClick={onOpen} {...pointer}>{content}</DropdownMenuItem>
|
||||
) : (
|
||||
<DropdownMenuItem
|
||||
className={className}
|
||||
closeOnClick
|
||||
render={<AppLink href={accountDialogHref(dialog)} onClick={leaveChat} />}
|
||||
{...pointer}
|
||||
>
|
||||
{content}
|
||||
</DropdownMenuItem>
|
||||
const openInPlace = onOpen ?? (() => {
|
||||
setOwnMenuOpen(false);
|
||||
onOpenAccountDialog?.(dialog, ownTriggerRef.current);
|
||||
});
|
||||
return (
|
||||
<DropdownMenuItem className={className} onClick={openInPlace} {...pointer}>{content}</DropdownMenuItem>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -496,14 +497,13 @@ export function AppSidebar({
|
||||
) : null}
|
||||
<SidebarFooter className="sidebar-footer">
|
||||
{account ? (
|
||||
/* One account menu on every page. On `/` Home controls it and its
|
||||
entries open the dialogs in place; elsewhere it keeps its own open
|
||||
state and the dialog entries go to `/?account=<dialog>`, where Home
|
||||
opens that dialog (S2). Theme applies where the reader is. */
|
||||
/* One account menu on every page. On `/` Home controls it; elsewhere
|
||||
it keeps its own open state. Its entries open the dialogs in place
|
||||
everywhere (BUG-2127). Theme applies where the reader is. */
|
||||
<DropdownMenu open={accountMenuOpen} onOpenChange={onAccountMenuOpenChange} modal={false}>
|
||||
<DropdownMenuTrigger
|
||||
className="sidebar-account-trigger"
|
||||
ref={accountTriggerRef}
|
||||
ref={controls ? accountTriggerRef : ownTriggerRef}
|
||||
type="button"
|
||||
>
|
||||
{account.avatar
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
"use client";
|
||||
|
||||
import { accountDialogHref } from "@/lib/account-dialog-intent";
|
||||
import { BillingDialogLink } from "@/components/account-dialog-provider";
|
||||
import {
|
||||
PERSONAL_REPORT_START_ACTION,
|
||||
PERSONAL_REPORT_START_NOTES,
|
||||
@@ -84,7 +84,7 @@ export function PersonalReportStartCard(props: Readonly<{
|
||||
{error ? (
|
||||
<p className="annual-error" role="alert">
|
||||
{error.message}
|
||||
{props.error?.billing ? <> <a href={accountDialogHref("billing")}>去补点数</a></> : null}
|
||||
{props.error?.billing ? <> <BillingDialogLink>去补点数</BillingDialogLink></> : null}
|
||||
</p>
|
||||
) : (
|
||||
<p className="annual-price">{overview === null ? "正在读取价格…" : reportPriceLine(cost)}</p>
|
||||
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
type ChangeEvent, type FormEvent, type KeyboardEvent, type PointerEvent as ReactPointerEvent,
|
||||
} from "react";
|
||||
|
||||
import { AppLink } from "@/components/app-link";
|
||||
import { ChatComposer } from "@/components/chat-composer";
|
||||
import { ChatMessageActions, toggleChatMessageFeedback, type ChatMessageFeedback } from "@/components/chat-message-actions";
|
||||
import { ChatMessageRow } from "@/components/chat-message-row";
|
||||
@@ -16,7 +15,7 @@ import { Button } from "@/components/ui/button";
|
||||
import { Drawer, DrawerContent, DrawerTitle } from "@/components/ui/drawer";
|
||||
import type { ReportAskPending, ReportAskState } from "@/components/report-ask/use-report-ask";
|
||||
import { useReportAskWidth, useReportAskWidthProperty } from "@/components/report-ask/use-report-ask-width";
|
||||
import { accountDialogHref } from "@/lib/account-dialog-intent";
|
||||
import { BillingDialogLink } from "@/components/account-dialog-provider";
|
||||
import type { ChatMessageView } from "@/lib/chat-message-view";
|
||||
import { isWholeReportAnchor, type ReportAnchor } from "@/lib/report-ask-anchor";
|
||||
import { REPORT_ASK_MAX_QUESTION_CHARS, type ReportAskText } from "@/lib/report-ask-client";
|
||||
@@ -202,7 +201,7 @@ export function ReportAskBody({ state, text, draftAnchor, sectionTitle, onAsk, o
|
||||
{state.short ? (
|
||||
<p className="report-ask-short">
|
||||
{price !== null && balance !== null ? text.short(balance, price) : text.shortPlain}
|
||||
<AppLink href={accountDialogHref("billing")}>{text.toBilling}</AppLink>
|
||||
<BillingDialogLink>{text.toBilling}</BillingDialogLink>
|
||||
</p>
|
||||
) : null}
|
||||
<ChatComposer
|
||||
|
||||
@@ -6,7 +6,7 @@ import { HeartHandshake, Plus, X } from "lucide-react";
|
||||
|
||||
import { emptySynastryDraft, SynastryAddDialog } from "@/components/synastry/synastry-add-dialog";
|
||||
import { SecondaryHeader } from "@/components/secondary-header";
|
||||
import { accountDialogHref } from "@/lib/account-dialog-intent";
|
||||
import { useAccountDialogs } from "@/components/account-dialog-provider";
|
||||
import { ReportQuestionCount } from "@/components/report-ask/report-ask-entry";
|
||||
import { useReportQuestionCounts } from "@/components/report-ask/use-report-question-counts";
|
||||
import { effectiveBirthDate } from "@/lib/effective-birth-date";
|
||||
@@ -151,6 +151,8 @@ export function SynastryPicker() {
|
||||
// BUG-2073: 「提问 N」 on a report that has had questions.
|
||||
const questionCounts = useReportQuestionCounts(useMemo(() => earlier.map((report) => report.id), [earlier]));
|
||||
const [confirming, setConfirming] = useState(false);
|
||||
// 「去补点数」 opens 账户与点数 over this page (BUG-2127; it used to load `/?account=billing`).
|
||||
const accountDialogs = useAccountDialogs();
|
||||
const [compareRamanKuja, setCompareRamanKuja] = useState(false);
|
||||
// BUG-2083: a start the server refused for missing birth data widens the lines under the selectors.
|
||||
const [refused, setRefused] = useState(false);
|
||||
@@ -414,7 +416,7 @@ export function SynastryPicker() {
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||
{charge.short ? (
|
||||
<AlertDialogAction onClick={() => { window.location.assign(accountDialogHref("billing")); }}>去补点数</AlertDialogAction>
|
||||
<AlertDialogAction onClick={() => { setConfirming(false); accountDialogs.open("billing", { source: "insufficient-credits" }); }}>去补点数</AlertDialogAction>
|
||||
) : (
|
||||
<AlertDialogAction onClick={() => { setConfirming(false); void createReport(); }}>开始</AlertDialogAction>
|
||||
)}
|
||||
|
||||
@@ -2,10 +2,6 @@
|
||||
|
||||
import { useRef, useState, type Dispatch, FormEvent, MutableRefObject, SetStateAction } from "react";
|
||||
|
||||
import {
|
||||
beamAvatarSchema,
|
||||
type BeamAvatarPatch,
|
||||
} from "@/lib/beam-avatar";
|
||||
import {
|
||||
isBirthTimeDraftReady,
|
||||
} from "@/lib/birth-time-intake-model";
|
||||
@@ -22,10 +18,8 @@ import {
|
||||
import {
|
||||
accountChartPinStillCurrent,
|
||||
beginChartCacheAccountRead,
|
||||
clearChartPageCache,
|
||||
pinChartSnapshotIdentity,
|
||||
} from "@/lib/secondary-page-data";
|
||||
import { clearBirthSkyMemory } from "@/lib/birth-sky/cover";
|
||||
import {
|
||||
missingOtherProfileStep,
|
||||
missingProfileStep,
|
||||
@@ -42,19 +36,15 @@ import {
|
||||
} from "@/lib/onboarding-intake";
|
||||
import { saveOtherProfile } from "@/lib/other-profile-save";
|
||||
import type { PersonRelation } from "@/lib/person-relation";
|
||||
import { notifyError, notifySuccess } from "@/lib/notify";
|
||||
import { notifyError } from "@/lib/notify";
|
||||
import { extractOnboardingName, fallbackOnboardingName } from "@/lib/onboarding-name";
|
||||
import { saveSelfName, saveSelfProfile } from "@/lib/self-profile-save";
|
||||
import { createStartGreeting } from "@/lib/starter-greeting";
|
||||
import { clearHomeWarmSnapshot } from "@/lib/home-warm-snapshot";
|
||||
import {
|
||||
type Account,
|
||||
type AccountDialog,
|
||||
type ChartLibraryRecord,
|
||||
type OnboardingStep,
|
||||
type OpenAccountDialogOptions,
|
||||
type Profile,
|
||||
accountDialogOptions,
|
||||
emptyProfile,
|
||||
} from "@/lib/home-types";
|
||||
import { preserveShallowEqual } from "@/lib/preserve-shallow-equal";
|
||||
@@ -63,21 +53,14 @@ import type { BirthTimeAssessmentPhase } from "@/components/birth-time-assessmen
|
||||
export type ProfileOnboardingParams = {
|
||||
account: Account | null;
|
||||
accountRefreshGuard: MutableRefObject<LatestAccountRequestGuard>;
|
||||
accountTrigger: MutableRefObject<HTMLButtonElement | null>;
|
||||
dialogReturnTargetRef: MutableRefObject<HTMLButtonElement | null>;
|
||||
setAccount: Dispatch<SetStateAction<Account | null>>;
|
||||
setAccountError: Dispatch<SetStateAction<string>>;
|
||||
setAccountMenuOpen: Dispatch<SetStateAction<boolean>>;
|
||||
setActiveAccountDialog: Dispatch<SetStateAction<AccountDialog | null>>;
|
||||
setBirthTimeAssessmentPhase: Dispatch<SetStateAction<BirthTimeAssessmentPhase | null>>;
|
||||
setBillingPane: Dispatch<SetStateAction<OpenAccountDialogOptions>>;
|
||||
setDraft: (value: string) => void;
|
||||
setOnboardingJustCompleted: Dispatch<SetStateAction<boolean>>;
|
||||
setOnboardingStep: Dispatch<SetStateAction<OnboardingStep>>;
|
||||
setPresetMessageLength: Dispatch<SetStateAction<number>>;
|
||||
setSigningOut: Dispatch<SetStateAction<boolean>>;
|
||||
setStartGreeting: Dispatch<SetStateAction<string>>;
|
||||
signingOut: boolean;
|
||||
uiPreview: MutableRefObject<boolean>;
|
||||
/** Warm return to `/` (BUG-1040): the profile Home starts with instead of empty. */
|
||||
initialProfile?: () => Profile | null;
|
||||
@@ -91,21 +74,14 @@ export function useProfileOnboarding(params: ProfileOnboardingParams) {
|
||||
const {
|
||||
account,
|
||||
accountRefreshGuard,
|
||||
accountTrigger,
|
||||
dialogReturnTargetRef,
|
||||
setAccount,
|
||||
setAccountError,
|
||||
setAccountMenuOpen,
|
||||
setActiveAccountDialog,
|
||||
setBirthTimeAssessmentPhase,
|
||||
setBillingPane,
|
||||
setDraft,
|
||||
setOnboardingJustCompleted,
|
||||
setOnboardingStep,
|
||||
setPresetMessageLength,
|
||||
setSigningOut,
|
||||
setStartGreeting,
|
||||
signingOut,
|
||||
uiPreview,
|
||||
initialProfile,
|
||||
onOwnBirthPlaceSaved,
|
||||
@@ -117,7 +93,6 @@ export function useProfileOnboarding(params: ProfileOnboardingParams) {
|
||||
const [profile, setProfile] = useState<Profile>(() => initialProfile?.() ?? emptyProfile);
|
||||
const [profileDraft, setProfileDraft] = useState<Profile>(() => initialProfile?.() ?? emptyProfile);
|
||||
const [profileNotice, setProfileNotice] = useState("");
|
||||
const [avatarSaving, setAvatarSaving] = useState(false);
|
||||
const [profileSaving, setProfileSaving] = useState(false);
|
||||
const [intakeChoice, setIntakeChoice] = useState<"self" | "other" | null>(null);
|
||||
const [chosenOtherId, setChosenOtherId] = useState<string | null>(null);
|
||||
@@ -156,59 +131,8 @@ export function useProfileOnboarding(params: ProfileOnboardingParams) {
|
||||
}
|
||||
|
||||
|
||||
function openAccountDialog(
|
||||
dialog: AccountDialog,
|
||||
returnTargetOrOptions?: HTMLButtonElement | null | OpenAccountDialogOptions,
|
||||
) {
|
||||
const options = accountDialogOptions(returnTargetOrOptions);
|
||||
dialogReturnTargetRef.current = options.returnTarget ?? accountTrigger.current;
|
||||
setAccountMenuOpen(false);
|
||||
setAccountError("");
|
||||
if (dialog === "profile") {
|
||||
setProfileNotice("");
|
||||
}
|
||||
if (dialog === "chart-library") {
|
||||
window.location.assign("/people");
|
||||
return;
|
||||
}
|
||||
if (dialog === "billing") {
|
||||
setBillingPane({
|
||||
source: options.source,
|
||||
plan: options.plan,
|
||||
tab: options.tab,
|
||||
});
|
||||
}
|
||||
setActiveAccountDialog(dialog);
|
||||
}
|
||||
|
||||
function closeAccountDialog() {
|
||||
if (signingOut) return;
|
||||
setActiveAccountDialog(null);
|
||||
const returnTarget = dialogReturnTargetRef.current;
|
||||
window.requestAnimationFrame(() => returnTarget?.focus());
|
||||
}
|
||||
|
||||
async function persistAvatar(patch: BeamAvatarPatch) {
|
||||
if (!account?.avatar || avatarSaving) return;
|
||||
setAvatarSaving(true);
|
||||
try {
|
||||
const response = await fetch("/api/account/avatar", {
|
||||
method: "PATCH",
|
||||
credentials: "same-origin",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify(patch),
|
||||
});
|
||||
const payload = await response.json().catch(() => null) as { avatar?: unknown; error?: string } | null;
|
||||
if (!response.ok) throw new Error(payload?.error || "头像暂时无法保存。");
|
||||
const avatar = beamAvatarSchema.parse(payload?.avatar);
|
||||
setAccount((current) => current ? { ...current, avatar } : current);
|
||||
notifySuccess(patch.action === "randomize" ? "已生成并保存新头像。" : "头像配色已保存。");
|
||||
} catch (caught) {
|
||||
notifyError(friendlyError(caught instanceof Error ? caught.message : "头像保存失败"));
|
||||
} finally {
|
||||
setAvatarSaving(false);
|
||||
}
|
||||
}
|
||||
// The account dialogs, their avatar save and sign-out moved to the app
|
||||
// shell on 2026-11-21 (BUG-2127): components/account-dialog-provider.tsx.
|
||||
|
||||
async function persistProfile(nextProfile: Profile): Promise<Profile> {
|
||||
if (!account) throw new Error("账户尚未加载完成");
|
||||
@@ -390,28 +314,6 @@ export function useProfileOnboarding(params: ProfileOnboardingParams) {
|
||||
|
||||
const onboardingDraft = intakeTarget === "other" && otherDraft ? otherDraft : profileDraft;
|
||||
|
||||
async function signOut() {
|
||||
if (signingOut) return;
|
||||
setSigningOut(true);
|
||||
try {
|
||||
// The auth client is only needed here, so it is not in the first screen (issue #125).
|
||||
const { selfHostedOtpActions } = await import("@/modules/identity/client");
|
||||
// Signing out ends this account's warm return to `/` (BUG-1040); a
|
||||
// failed sign-out only costs one loading ring on the next return.
|
||||
// Nor does this account's chart stay in memory for the next one (BUG-1530).
|
||||
clearChartPageCache();
|
||||
clearBirthSkyMemory();
|
||||
clearHomeWarmSnapshot();
|
||||
await selfHostedOtpActions.signOut();
|
||||
window.location.assign("/login");
|
||||
} catch (caught) {
|
||||
const message = caught instanceof Error ? caught.message : "退出失败";
|
||||
notifyError(friendlyError(message));
|
||||
setSigningOut(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
profile,
|
||||
setProfile,
|
||||
@@ -424,16 +326,11 @@ export function useProfileOnboarding(params: ProfileOnboardingParams) {
|
||||
chooseOnboardingOther,
|
||||
profileNotice,
|
||||
setProfileNotice,
|
||||
avatarSaving,
|
||||
profileSaving,
|
||||
refreshAccount,
|
||||
openAccountDialog,
|
||||
closeAccountDialog,
|
||||
persistAvatar,
|
||||
persistProfile,
|
||||
saveOnboardingName,
|
||||
saveOnboardingBirth,
|
||||
saveOnboardingPlace,
|
||||
signOut,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,271 @@
|
||||
/**
|
||||
* BUG-2127. On any page that is not the chat page, choosing a settings entry in
|
||||
* the avatar menu went to the chat page first and opened the dialog there: the
|
||||
* dialogs were mounted by Home only, and off `/` the entries were links to
|
||||
* `/?account=<dialog>`. The dialogs now belong to the (app) shell and open in
|
||||
* place on every page; Home calls the same `open`.
|
||||
* Synthetic ids and profiles only.
|
||||
*/
|
||||
import "./install-test-document";
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import test from "node:test";
|
||||
import React, { createElement } from "react";
|
||||
|
||||
import { onboardingCatalogDecision, readProfile } from "../src/lib/home-profile.ts";
|
||||
import type { Account } from "../src/lib/home-types.ts";
|
||||
import { SessionListProvider, useSessionList } from "../src/lib/session-list-context.tsx";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import {
|
||||
AccountDialogHost,
|
||||
AccountDialogProvider,
|
||||
BillingDialogLink,
|
||||
useAccountDialogInternals,
|
||||
useAccountDialogs,
|
||||
} from "../src/components/account-dialog-provider.tsx";
|
||||
import { createClientLifecycleHarness } from "./react-client-lifecycle-test-support.ts";
|
||||
|
||||
Object.assign(globalThis, { React });
|
||||
|
||||
const read = (path: string) => readFileSync(new URL(`../src/${path}`, import.meta.url), "utf8");
|
||||
|
||||
const USER = "00000000-0000-4000-8000-000000002127";
|
||||
const finishedProfile = {
|
||||
name: "林遥", date: "1990-06-15", time: "12:30", reportedTime: "12:30", birthTimeSource: "hospital_record",
|
||||
birthTimePeriod: "", declaredWindowStart: "", declaredWindowEnd: "", birthTimeClue: "",
|
||||
birthTimeUncertaintyKnown: false, uncertaintyBeforeMinutes: null, uncertaintyAfterMinutes: null,
|
||||
birthTimeStatus: "accepted", rectificationCaseId: "", countryCode: "CN", birthPlaceLabel: "北京市",
|
||||
latitude: 39.9, longitude: 116.4, timezoneId: "Asia/Shanghai", timezoneOffset: 8, ayanamsa: "lahiri",
|
||||
};
|
||||
const account = {
|
||||
user: { id: USER, email: "fictional@example.test" },
|
||||
profile: finishedProfile,
|
||||
avatar: { seed: "22222222-2222-4222-8222-222222222222", palette: 1, rendererVersion: 1 },
|
||||
credits: 7,
|
||||
isAdmin: false, adminUrl: null, rectificationPriceCredits: 1, activeSubscription: null,
|
||||
hasConfirmedBirthTime: true, hasUsableBirthTime: true,
|
||||
} as unknown as Account;
|
||||
|
||||
type Harness = ReturnType<typeof createClientLifecycleHarness>;
|
||||
type HostNode = ReturnType<Harness["elements"]>[number];
|
||||
|
||||
function bodyNodes(h: Harness): HostNode[] {
|
||||
const walk = (node: HostNode): HostNode[] => [node, ...node.childNodes.flatMap((child) => walk(child))];
|
||||
return [...h.document.body.childNodes].flatMap((child) => walk(child as HostNode));
|
||||
}
|
||||
|
||||
function dialogTitle(h: Harness): string | null {
|
||||
return bodyNodes(h).find((node) => node.getAttribute("id") === "account-dialog-title")?.text ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The layout's providers on a page other than `/`, with the overlay host, and
|
||||
* a probe that reads the shell's dialogs as a page would.
|
||||
*/
|
||||
async function mountShell(page: { pathname: string; search: string }, run: (shell: {
|
||||
h: Harness;
|
||||
dialogs: () => ReturnType<typeof useAccountDialogs>;
|
||||
internals: () => NonNullable<ReturnType<typeof useAccountDialogInternals>>;
|
||||
list: () => ReturnType<typeof useSessionList>;
|
||||
assigned: string[];
|
||||
location: { pathname: string; search: string; hash: string };
|
||||
avatarPatches: unknown[];
|
||||
}) => Promise<void>) {
|
||||
const original = globalThis.fetch;
|
||||
const avatarPatches: unknown[] = [];
|
||||
const json = (body: unknown) => new Response(JSON.stringify(body), { status: 200, headers: { "content-type": "application/json" } });
|
||||
globalThis.fetch = (async (input: unknown, init?: RequestInit) => {
|
||||
const path = new URL(String(input), "http://localhost").pathname;
|
||||
if (path === "/api/account") return json(account);
|
||||
if (path === "/api/chart-profiles") return json({ profiles: [] });
|
||||
if (path === "/api/sessions") return json({ sessions: [], nextCursor: null });
|
||||
if (path === "/api/account/avatar" && init?.method === "PATCH") {
|
||||
avatarPatches.push(JSON.parse(String(init.body)));
|
||||
return json({ avatar: { seed: "33333333-3333-4333-8333-333333333333", palette: 1, rendererVersion: 1 } });
|
||||
}
|
||||
return new Response(JSON.stringify({ error: "not_mocked" }), { status: 404 });
|
||||
}) as typeof fetch;
|
||||
const { resetSubjectCatalogForTests } = await import("../src/lib/current-subject.ts");
|
||||
resetSubjectCatalogForTests();
|
||||
let dialogs: ReturnType<typeof useAccountDialogs> | null = null;
|
||||
let internals: ReturnType<typeof useAccountDialogInternals> = null;
|
||||
let list: ReturnType<typeof useSessionList> | null = null;
|
||||
function Probe() {
|
||||
dialogs = useAccountDialogs();
|
||||
return createElement(BillingDialogLink, null, "去补点数");
|
||||
}
|
||||
function ProbeState() {
|
||||
internals = useAccountDialogInternals();
|
||||
list = useSessionList();
|
||||
return null;
|
||||
}
|
||||
const h = createClientLifecycleHarness();
|
||||
const assigned: string[] = [];
|
||||
const location = {
|
||||
pathname: page.pathname, search: page.search, hash: "", origin: "http://localhost",
|
||||
get href() { return `http://localhost${this.pathname}${this.search}`; },
|
||||
assign(url: string) { assigned.push(url); },
|
||||
replace(url: string) { assigned.push(url); },
|
||||
};
|
||||
const win = globalThis.window as unknown as { location?: unknown; history?: unknown };
|
||||
const previousLocation = win.location;
|
||||
const previousHistory = win.history;
|
||||
win.location = location;
|
||||
win.history = {
|
||||
replaceState(_state: unknown, _title: string, url: string) {
|
||||
const next = new URL(url, "http://localhost");
|
||||
location.pathname = next.pathname;
|
||||
location.search = next.search;
|
||||
},
|
||||
pushState(_state: unknown, _title: string, url: string) { assigned.push(`push:${url}`); },
|
||||
};
|
||||
try {
|
||||
await h.render(createElement(SessionListProvider, null,
|
||||
createElement(AccountDialogProvider, null, createElement(AccountDialogHost), createElement(Probe), createElement(ProbeState))));
|
||||
for (let tick = 0; tick < 6; tick += 1) await h.idle();
|
||||
await run({
|
||||
h,
|
||||
dialogs: () => dialogs as unknown as ReturnType<typeof useAccountDialogs>,
|
||||
internals: () => internals as unknown as NonNullable<ReturnType<typeof useAccountDialogInternals>>,
|
||||
list: () => list as unknown as ReturnType<typeof useSessionList>,
|
||||
assigned,
|
||||
location,
|
||||
avatarPatches,
|
||||
});
|
||||
} finally {
|
||||
await h.close();
|
||||
win.location = previousLocation;
|
||||
win.history = previousHistory;
|
||||
globalThis.fetch = original;
|
||||
}
|
||||
}
|
||||
|
||||
test("on a page other than the chat page, a settings entry opens the dialog where the reader is", async () => {
|
||||
await mountShell({ pathname: "/chart", search: "" }, async ({ h, dialogs, assigned, location }) => {
|
||||
assert.ok(dialogs().activeDialog === null);
|
||||
assert.equal(dialogTitle(h), null);
|
||||
await h.update(() => dialogs().open("general", { returnTarget: null }));
|
||||
await h.idle();
|
||||
assert.equal(dialogs().activeDialog, "general");
|
||||
assert.equal(dialogTitle(h), "设置", "the settings dialog is on screen");
|
||||
assert.deepEqual(assigned, [], "no navigation, no document load");
|
||||
assert.equal(location.pathname, "/chart");
|
||||
// The tab line inside the dialog moves between panes in place too.
|
||||
await h.update(() => dialogs().open("profile", null));
|
||||
await h.idle();
|
||||
assert.equal(dialogs().activeDialog, "profile");
|
||||
assert.ok(bodyNodes(h).some((node) => node.text === "林遥"), "the profile pane shows the account's own name");
|
||||
await h.update(() => dialogs().close());
|
||||
await h.idle();
|
||||
assert.equal(dialogs().activeDialog, null);
|
||||
assert.equal(dialogTitle(h), null);
|
||||
assert.deepEqual(assigned, []);
|
||||
assert.deepEqual(h.errors, []);
|
||||
});
|
||||
});
|
||||
|
||||
test("the `/?account=` deep link still opens its dialog, on Home and on another page, and drops the parameter", async () => {
|
||||
for (const pathname of ["/", "/reports"]) {
|
||||
await mountShell({ pathname, search: "?account=billing&tab=redeem" }, async ({ h, dialogs, assigned, location }) => {
|
||||
assert.equal(dialogs().activeDialog, "billing", pathname);
|
||||
assert.equal(location.search, "?tab=redeem", "read once and removed, so a reload or Back never reopens it");
|
||||
assert.equal(location.pathname, pathname);
|
||||
assert.deepEqual(assigned, []);
|
||||
await h.update(() => dialogs().close());
|
||||
await h.idle();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test("BUG-2086: a profile write from the dialog on another page keeps the boot record current, so Home does not ask for the name again", async () => {
|
||||
await mountShell({ pathname: "/synastry", search: "" }, async ({ h, dialogs, internals, list, avatarPatches }) => {
|
||||
const bootAtOpen = list().boot();
|
||||
assert.ok(bootAtOpen?.account);
|
||||
await h.update(() => dialogs().open("profile", null));
|
||||
await h.update(() => void internals().persistAvatar({ action: "randomize" }));
|
||||
for (let tick = 0; tick < 4; tick += 1) await h.idle();
|
||||
assert.deepEqual(avatarPatches, [{ action: "randomize" }]);
|
||||
const bootOnReturn = list().boot();
|
||||
assert.equal(bootOnReturn, bootAtOpen, "the same record, as the warm snapshot compares it");
|
||||
assert.equal(bootOnReturn?.account?.avatar?.seed, "33333333-3333-4333-8333-333333333333", "the saved avatar reached the record Home cold-starts from");
|
||||
const profile = readProfile(bootOnReturn?.account?.profile);
|
||||
assert.equal(profile.name, "林遥");
|
||||
assert.equal(onboardingCatalogDecision(profile, []).step, null, "a finished profile is not sent back into onboarding");
|
||||
});
|
||||
});
|
||||
|
||||
test("the shell mounts the dialogs once; Home and the sidebar call the same open", () => {
|
||||
const layout = read("app/(app)/layout.tsx");
|
||||
const page = read("app/(app)/page.tsx");
|
||||
const sidebar = read("components/app-sidebar.tsx");
|
||||
const provider = read("components/account-dialog-provider.tsx");
|
||||
assert.match(layout, /<SessionListProvider>\s*<AccountDialogProvider>\s*<AppShell>\{children\}<\/AppShell>\s*<\/AccountDialogProvider>\s*<\/SessionListProvider>/);
|
||||
assert.equal(layout.match(/<AccountDialogHost \/>/g)?.length, 1);
|
||||
assert.match(layout, /onOpenAccountDialog=\{\(dialog, returnTarget\) => \{[\s\S]*?accountDialogs\.open\(dialog, \{ returnTarget, source: dialog === "billing" \? "account-menu" : undefined \}\);/);
|
||||
// BUG-2072's watcher keeps its place right after the consent gate, with the same condition.
|
||||
assert.match(layout, /<LegalConsentGate signedIn=\{Boolean\(account\) && !list\.signedOut\} \/>\s*\{\/\*[^*]*\*\/\}\s*<ReportReminderWatcher signedIn=\{Boolean\(account\) && !list\.signedOut\} \/>/);
|
||||
// Home draws no overlay of its own and does not read the account for it.
|
||||
assert.doesNotMatch(page, /<AccountDialogOverlay|<BillingPanel|<ProfilePanel|AccountDialogDeepLink/);
|
||||
assert.match(page, /accountDialogs\.open\(dialog, \{ \.\.\.options, returnTarget: options\.returnTarget \?\? accountTrigger\.current \}\);/);
|
||||
assert.doesNotMatch(provider, /fetchAccount|\/api\/account"/, "the dialogs use the shell's account, they do not load it");
|
||||
// The menu entries are buttons on every page; none is a link to `/?account=`.
|
||||
assert.doesNotMatch(sidebar, /accountDialogHref/);
|
||||
// BUG-2070: a ledger row closes the dialog first, on every page.
|
||||
assert.match(provider, /<BillingPanel [^>]*onNavigate=\{close\}/);
|
||||
// Focus back to the trigger, Esc, and the close button stay as they were on Home.
|
||||
assert.match(provider, /window\.requestAnimationFrame\(\(\) => returnTarget\?\.focus\(\)\);/);
|
||||
assert.match(provider, /if \(event\.key === "Escape"\)/);
|
||||
assert.match(provider, /closeButtonRef\.current\?\.focus\(\);/);
|
||||
});
|
||||
|
||||
test("「去补点数」 on a report or synastry page opens 账户与点数 over that page", async () => {
|
||||
await mountShell({ pathname: "/reports/annual", search: "" }, async ({ h, dialogs, assigned, location }) => {
|
||||
const link = h.elements().find((node) => node.tagName === "A" && node.text === "去补点数");
|
||||
assert.ok(link, "the 「去补点数」 link is rendered");
|
||||
// Still a real link to the deep link: a new tab or a render outside the shell lands on the same dialog.
|
||||
assert.equal(link.getAttribute("href"), "/?account=billing");
|
||||
const propsKey = Object.keys(link).find((key) => key.startsWith("__reactProps$"));
|
||||
assert.ok(propsKey);
|
||||
const onClick = (link as unknown as Record<string, { onClick: (event: unknown) => void }>)[propsKey].onClick;
|
||||
let prevented = false;
|
||||
const click = (extra: Record<string, unknown> = {}) => ({
|
||||
defaultPrevented: false, button: 0, metaKey: false, ctrlKey: false, shiftKey: false, altKey: false,
|
||||
preventDefault() { prevented = true; }, ...extra,
|
||||
});
|
||||
// A modified click keeps the browser's own link behaviour (new tab).
|
||||
await h.update(() => onClick(click({ metaKey: true })));
|
||||
assert.equal(prevented, false);
|
||||
assert.equal(dialogs().activeDialog, null);
|
||||
await h.update(() => onClick(click()));
|
||||
await h.idle();
|
||||
assert.equal(prevented, true, "the plain click does not navigate");
|
||||
assert.equal(dialogs().activeDialog, "billing");
|
||||
assert.equal(dialogTitle(h), "设置");
|
||||
assert.deepEqual(assigned, []);
|
||||
assert.equal(location.pathname, "/reports/annual");
|
||||
await h.update(() => dialogs().close());
|
||||
await h.idle();
|
||||
});
|
||||
// Outside the shell the same element is a plain link to the deep link.
|
||||
assert.equal(renderToStaticMarkup(createElement(BillingDialogLink, null, "去补点数")), '<a href="/?account=billing">去补点数</a>');
|
||||
});
|
||||
|
||||
test("every in-app 「去补点数」 uses the shell's dialog; only the deep-link reader and the link fallback name `/?account=`", () => {
|
||||
// 原值:年运卡、个人报告开始卡是 `<a href={accountDialogHref("billing")}>`,报告提问栏是 `<AppLink href={accountDialogHref("billing")}>`,
|
||||
// 合盘确认框是 `window.location.assign(accountDialogHref("billing"))`——都先跳到聊天页再开弹窗
|
||||
// 新值:前三处是 `<BillingDialogLink>`(普通点击原地打开,href 仍是深链),合盘确认框直接调外壳的 open("billing")
|
||||
// 原因:BUG-2127,账户弹窗搬到 (app) 外壳后每页原地打开;同类入口一并改
|
||||
for (const path of [
|
||||
"components/annual/annual-report-page.tsx",
|
||||
"components/personal-report/personal-report-start-dialog.tsx",
|
||||
"components/report-ask/report-ask-panel.tsx",
|
||||
]) {
|
||||
const source = read(path);
|
||||
assert.doesNotMatch(source, /accountDialogHref/, path);
|
||||
assert.match(source, /<BillingDialogLink>/, path);
|
||||
}
|
||||
const picker = read("components/synastry/synastry-picker.tsx");
|
||||
assert.doesNotMatch(picker, /accountDialogHref/);
|
||||
const provider = read("components/account-dialog-provider.tsx");
|
||||
assert.match(provider, /dialogs\.open\("billing", \{ source: "insufficient-credits" \}\);/);
|
||||
});
|
||||
@@ -57,17 +57,18 @@ test("the read-only sidebar renders the account menu's button, not a link home",
|
||||
assert.match(markup, /示例甲/);
|
||||
});
|
||||
|
||||
test("the four dialog entries open in place on `/` and link to `/?account=` elsewhere; theme stays in place", () => {
|
||||
test("the four dialog entries open in place on every page; theme stays in place", () => {
|
||||
assert.match(sidebar, /accountEntry\("profile", onOpenProfile,/);
|
||||
assert.match(sidebar, /accountEntry\("general", onOpenGeneral,/);
|
||||
assert.match(sidebar, /accountEntry\("billing", onOpenBilling,/);
|
||||
assert.match(sidebar, /accountEntry\("logout", onOpenLogout,/);
|
||||
const entry = sidebar.slice(sidebar.indexOf("function accountEntry("), sidebar.indexOf(" return (\n <Sidebar"));
|
||||
// 原值:`Menu.Item` / `Menu.LinkItem`
|
||||
// 新值:`DropdownMenuItem`,站外页仍是 `/?account=` 链接
|
||||
// 原因:K1 账户菜单改用组件库 DropdownMenu,打开方式和链接目标不变
|
||||
assert.match(entry, /return onOpen \? \(\s*<DropdownMenuItem className=\{className\} onClick=\{onOpen\}/);
|
||||
assert.match(entry, /<DropdownMenuItem[\s\S]*closeOnClick[\s\S]*render=\{<AppLink href=\{accountDialogHref\(dialog\)\} onClick=\{leaveChat\} \/>\}/);
|
||||
// 原值:`return onOpen ? (<DropdownMenuItem onClick={onOpen}>) : (<DropdownMenuItem closeOnClick render={<AppLink href={accountDialogHref(dialog)} …/>}>)`
|
||||
// 新值:只有一种 `DropdownMenuItem onClick={openInPlace}`:首页用 Home 的 controls,别的页用外壳的 onOpenAccountDialog
|
||||
// 原因:BUG-2127,站外页点设置会先跳到聊天页再开弹窗;弹窗搬到 (app) 外壳后每页原地打开,不再链到 `/?account=`
|
||||
assert.match(entry, /const openInPlace = onOpen \?\? \(\(\) => \{\s*setOwnMenuOpen\(false\);\s*onOpenAccountDialog\?\.\(dialog, ownTriggerRef\.current\);/);
|
||||
assert.match(entry, /<DropdownMenuItem className=\{className\} onClick=\{openInPlace\}/);
|
||||
assert.doesNotMatch(sidebar, /accountDialogHref|closeOnClick\s+render=\{<AppLink/);
|
||||
// Theme is not a dialog: the same ThemePreferenceMenu on every page.
|
||||
assert.equal(sidebar.match(/<ThemePreferenceMenu \/>/g)?.length, 1);
|
||||
// Off `/` the menu keeps its own open state; on `/` Home controls it.
|
||||
@@ -131,7 +132,12 @@ test("an unknown value is dropped from the URL and opens nothing", async () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("Home wires it in one line and does not grow", () => {
|
||||
assert.match(page, /import \{ AccountDialogDeepLink, SynastryDeepLink \} from "@\/components\/people-home-links";/);
|
||||
assert.equal(page.match(/<AccountDialogDeepLink ready=\{hydrated && Boolean\(account\)\} open=\{openAccountDialog\} \/>/g)?.length, 1);
|
||||
test("the app shell wires the deep link in one line; Home no longer carries it", () => {
|
||||
const provider = readFileSync(new URL("../src/components/account-dialog-provider.tsx", import.meta.url), "utf8");
|
||||
// 原值:page.tsx 里 `<AccountDialogDeepLink ready={hydrated && Boolean(account)} open={openAccountDialog} />`
|
||||
// 新值:外壳的 AccountDialogHost 里挂一次,按页面路径重读,账户一到就开
|
||||
// 原因:BUG-2127,弹窗搬进 (app) 外壳,`/?account=` 在任何页都能原地打开,首页不再单独挂
|
||||
assert.match(page, /import \{ SynastryDeepLink \} from "@\/components\/people-home-links";/);
|
||||
assert.doesNotMatch(page, /AccountDialogDeepLink/);
|
||||
assert.equal(provider.match(/<AccountDialogDeepLink key=\{pathname\} ready=\{Boolean\(account\)\} open=\{openFromLink\} \/>/g)?.length, 1);
|
||||
});
|
||||
|
||||
@@ -18,6 +18,7 @@ const avatarRoute = readProjectFile("src/app/api/account/avatar/route.ts");
|
||||
const avatarComponent = readProjectFile("src/components/user-avatar.tsx");
|
||||
const sidebar = readProjectFile("src/components/app-sidebar.tsx");
|
||||
const page = readProjectFile("src/app/(app)/page.tsx");
|
||||
const accountDialogs = readProjectFile("src/components/account-dialog-provider.tsx");
|
||||
const profilePanel = readProjectFile("src/components/profile-panel.tsx");
|
||||
const migration = readProjectFile("db/migrations/20260807010000_profile_beam_avatars.sql");
|
||||
|
||||
@@ -114,7 +115,10 @@ test("renders the persisted Beam avatar in the sidebar, account menu, and profil
|
||||
// 新值:配色格里画这套配色本身(paletteFill(palette.colors))
|
||||
// 原因:同一个 seed 的脸在八套配色里都是浅色,预览分不出配色(2026-11-03 设置改版复查)
|
||||
assert.match(profilePanel, /<span className="avatar-palette-colors" style=\{\{ background: paletteFill\(palette\.colors\) \}\} \/>/);
|
||||
assert.match(page, /<ProfilePanel[\s\S]*persistAvatar=\{persistAvatar\}/);
|
||||
// 原值:在 page.tsx 里找 `<ProfilePanel … persistAvatar={persistAvatar}`
|
||||
// 新值:在外壳的 account-dialog-provider.tsx 里找
|
||||
// 原因:BUG-2127,账户弹窗从首页搬到 (app) 外壳(components/account-dialog-provider.tsx),每页原地打开,内容不变
|
||||
assert.match(accountDialogs, /<ProfilePanel[\s\S]*persistAvatar=\{persistAvatar\}/);
|
||||
// 原值:必须出现「Beam 形象会在刷新和换设备后保持一致」
|
||||
// 新值:这句说明不再出现
|
||||
// 原因:D8 去掉重复解释布局的小字。配色、随机和侧栏头像尺寸仍在
|
||||
|
||||
@@ -13,6 +13,7 @@ const billingSource = `${hookSource}\n${panelSource}`;
|
||||
const membershipLib = readProjectFile("src/lib/membership.ts");
|
||||
const nextConfig = readProjectFile("next.config.ts");
|
||||
const pageSource = readProjectFile("src/app/(app)/page.tsx");
|
||||
const accountDialogsSource = readProjectFile("src/components/account-dialog-provider.tsx");
|
||||
const tabsSource = readProjectFile("src/components/ui/tabs.tsx");
|
||||
const packagesRouteSource = readProjectFile("src/app/api/payment/packages/route.ts");
|
||||
const billingLoaderSource = readProjectFile("src/lib/billing-panel-loader.ts");
|
||||
@@ -235,7 +236,10 @@ test("the section is the balance, one tab line and three pages", () => {
|
||||
// 原因: BUG-2059
|
||||
assert.doesNotMatch(panelSource, /<h1 className="membership-title">|billing-summary|membership-order-row|刷新|href="\/membership/);
|
||||
assert.match(panelSource, /aria-label="账户与点数"/);
|
||||
assert.match(pageSource, /<BillingBalance credits=\{account\.credits\} \/>/);
|
||||
// 原值:在 page.tsx 里找 `<BillingBalance credits={account.credits} />`
|
||||
// 新值:在外壳的 account-dialog-provider.tsx 里找
|
||||
// 原因:BUG-2127,账户弹窗从首页搬到 (app) 外壳(components/account-dialog-provider.tsx),每页原地打开,内容不变
|
||||
assert.match(accountDialogsSource, /<BillingBalance credits=\{account\.credits\} \/>/);
|
||||
assert.match(panelSource, /value="redeem"/);
|
||||
assert.match(panelSource, /value="ledger"/);
|
||||
assert.match(panelSource, /value="recharge"/);
|
||||
|
||||
@@ -691,7 +691,10 @@ test("the (app) layout mounts one sidebar for home and the four secondary routes
|
||||
// 原因:TASK-session-list-single-source T2,列表只拉一次、侧栏不卸载
|
||||
const layout = readFileSync(new URL("../src/app/(app)/layout.tsx", import.meta.url), "utf8");
|
||||
assert.match(layout, /<SessionListProvider>/);
|
||||
assert.match(layout, /<SidebarProvider escapeBlocked=\{registration\?\.escapeBlocked \?\? false\}>/);
|
||||
// 原值:/<SidebarProvider escapeBlocked=\{registration\?\.escapeBlocked \?\? false\}>/
|
||||
// 新值:再或上外壳的账户弹窗是否打开(accountDialogOpen)
|
||||
// 原因:BUG-2127,账户弹窗从首页搬到 (app) 外壳(components/account-dialog-provider.tsx),每页原地打开
|
||||
assert.match(layout, /<SidebarProvider escapeBlocked=\{\(registration\?\.escapeBlocked \?\? false\) \|\| accountDialogOpen\}>/);
|
||||
assert.match(layout, /<AppSidebar\b/);
|
||||
assert.equal(layout.match(/<SidebarProvider/g)?.length, 1);
|
||||
assert.match(layout, /controls=\{registration\?\.controls\}/);
|
||||
|
||||
@@ -258,8 +258,11 @@ test("BUG-1530: a sign-out clears the remembered chart", async () => scenario(as
|
||||
assert.ok(peekReusableChartPage());
|
||||
clearChartPageCache();
|
||||
assert.equal(peekChartPage(), null);
|
||||
const source = read("../src/hooks/use-profile-onboarding.ts");
|
||||
const signOut = source.slice(source.indexOf("async function signOut()"));
|
||||
// 原值:read("../src/hooks/use-profile-onboarding.ts"),找 `async function signOut()`
|
||||
// 新值:退出登录在外壳的 account-dialog-provider.tsx,`const signOut = useCallback(async () => {`
|
||||
// 原因:BUG-2127,账户弹窗从首页搬到 (app) 外壳(components/account-dialog-provider.tsx),每页原地打开
|
||||
const source = read("../src/components/account-dialog-provider.tsx");
|
||||
const signOut = source.slice(source.indexOf("const signOut = useCallback(async () => {"));
|
||||
assert.ok(signOut.indexOf("clearChartPageCache()") > 0 && signOut.indexOf("clearChartPageCache()") < signOut.indexOf("selfHostedOtpActions.signOut()"));
|
||||
assert.ok(signOut.indexOf("clearBirthSkyMemory()") > 0 && signOut.indexOf("clearBirthSkyMemory()") < signOut.indexOf("selfHostedOtpActions.signOut()"));
|
||||
}));
|
||||
|
||||
@@ -113,7 +113,11 @@ test("auth redirects stay hard document loads so stale session state cannot surv
|
||||
// 原因: 状态下沉第二批把六个 profile 状态搬进 use-profile-onboarding.ts,hook 的
|
||||
// return 现在以 profile 开头,refreshAccount 不再是第一个字段。切的还是
|
||||
// signOut 函数体,断言主语(退出后硬跳 /login)一字未改。
|
||||
const signOut = sourceBetween(pageSource, "async function signOut()", "return {\n profile,");
|
||||
// 原值: sourceBetween(pageSource, "async function signOut()", "return {\n profile,")
|
||||
// 新值: sourceBetween(pageSource, "const signOut = useCallback(async () => {", "}, []);")
|
||||
// 原因: BUG-2127,退出登录随账户弹窗搬到 (app) 外壳(account-dialog-provider.tsx),每页原地打开;
|
||||
// 切的仍是 signOut 函数体,断言主语(退出后硬跳 /login)一字未改。
|
||||
const signOut = sourceBetween(pageSource, "const signOut = useCallback(async () => {", "}, []);");
|
||||
assert.match(signOut, /await selfHostedOtpActions\.signOut\(\);\n\s*window\.location\.assign\("\/login"\)/);
|
||||
|
||||
// And: the billing pane keeps the same 401 precedent without a dedicated membership page.
|
||||
|
||||
@@ -399,7 +399,10 @@ test("BUG-2057: the 账户与点数 page shows the balance at once and asks for
|
||||
// 原值: 摘要句 billing-summary 和兑换页签不读套餐状态;套餐未知时用一行同高的 membership-empty 占位
|
||||
// 新值: 余额由首页画(BillingBalance),兑换码页和点数记录页不读套餐状态;充值页在套餐未知时画三张同样大小的卡片骨架
|
||||
// 原因: BUG-2059 把面板改成「余额 + 页签 + 三页」;BUG-2057 要守的事不变:余额和兑换不等套餐
|
||||
assert.match(page, /<BillingBalance credits=\{account\.credits\} \/>/);
|
||||
// 原值:在 page.tsx 里找 BillingBalance
|
||||
// 新值:在外壳的 account-dialog-provider.tsx 里找
|
||||
// 原因:BUG-2127,账户弹窗从首页搬到 (app) 外壳(components/account-dialog-provider.tsx),每页原地打开,内容不变
|
||||
assert.match(read("src/components/account-dialog-provider.tsx"), /<BillingBalance credits=\{account\.credits\} \/>/);
|
||||
const redeemTab = panel.slice(panel.indexOf('value="redeem">'), panel.indexOf('value="recharge">'));
|
||||
assert.ok(redeemTab.length > 500);
|
||||
assert.doesNotMatch(redeemTab, /packagesSettled|paymentEnabled/);
|
||||
@@ -411,10 +414,14 @@ test("BUG-2057: the 账户与点数 page shows the balance at once and asks for
|
||||
// 原因: BUG-2059,负责人:默认页签是兑换码,充值由后台开关控制、默认关
|
||||
assert.match(panel, /const pages = billingPages\(paymentOpen\);/);
|
||||
assert.match(panel, /\{pages\.includes\("recharge"\) && \(/);
|
||||
assert.match(page, /initialTab=\{billingPane\.tab\}/);
|
||||
// 原值:initialTab 和「打开设置时预取」都在 page.tsx(`if (activeAccountDialog !== null) prefetchBillingPanel();`)
|
||||
// 新值:这两处在外壳的 account-dialog-provider.tsx(`if (activeDialog !== null) prefetchBillingPanel();`);空闲预取仍在首页
|
||||
// 原因:BUG-2127,账户弹窗从首页搬到 (app) 外壳,每页原地打开
|
||||
const accountDialogs = read("src/components/account-dialog-provider.tsx");
|
||||
assert.match(accountDialogs, /initialTab=\{billingPane\.tab\}/);
|
||||
// The panel code is fetched while idle and when a settings section opens.
|
||||
assert.match(page, /if \(accountId && hydrated\) prefetchBillingPanelWhenIdle\(\);/);
|
||||
assert.match(page, /if \(activeAccountDialog !== null\) prefetchBillingPanel\(\);/);
|
||||
assert.match(accountDialogs, /if \(activeDialog !== null\) prefetchBillingPanel\(\);/);
|
||||
});
|
||||
|
||||
test("BUG-2057: the idle prefetch runs once and falls back to a timer", () => {
|
||||
|
||||
@@ -21,7 +21,10 @@ const read = (path: string) => readFileSync(new URL(path, import.meta.url), "utf
|
||||
|
||||
test("first-screen modules import none of the three click-only dependencies statically", () => {
|
||||
assert.doesNotMatch(read("../src/lib/birth-time-intake-model.ts"), /from "date-fns"/);
|
||||
for (const path of ["../src/hooks/use-profile-onboarding.ts", "../src/components/account-deletion-gate.tsx"]) {
|
||||
// 原值:["../src/hooks/use-profile-onboarding.ts", "../src/components/account-deletion-gate.tsx"]
|
||||
// 新值:退出登录从 use-profile-onboarding.ts 搬到外壳的 account-dialog-provider.tsx,查它
|
||||
// 原因:BUG-2127,账户弹窗从首页搬到 (app) 外壳(components/account-dialog-provider.tsx),每页原地打开
|
||||
for (const path of ["../src/components/account-dialog-provider.tsx", "../src/components/account-deletion-gate.tsx"]) {
|
||||
const source = read(path);
|
||||
assert.doesNotMatch(source, /^import .*"@\/modules\/identity\/client"/m, path);
|
||||
assert.match(source, /await import\("@\/modules\/identity\/client"\)/, path);
|
||||
|
||||
@@ -30,6 +30,8 @@ const optionalHomeHookFiles = [
|
||||
"../src/lib/home-bootstrap-run.ts",
|
||||
"../src/lib/consultation-recovery-poll.ts",
|
||||
"../src/lib/self-profile-save.ts",
|
||||
// BUG-2127:账户弹窗(个人资料/账户与点数/通用设置/退出)从首页搬到 (app) 外壳,每页原地打开。
|
||||
"../src/components/account-dialog-provider.tsx",
|
||||
] as const;
|
||||
|
||||
export const homeSurface = [
|
||||
|
||||
@@ -122,7 +122,10 @@ test("a 401 login redirect clears the snapshot", async () => {
|
||||
});
|
||||
|
||||
test("sign-out and the provider's signed-out and account-change branches clear the snapshot", () => {
|
||||
const onboarding = readFileSync(new URL("../src/hooks/use-profile-onboarding.ts", import.meta.url), "utf8");
|
||||
// 原值:读 ../src/hooks/use-profile-onboarding.ts
|
||||
// 新值:退出登录在外壳的 account-dialog-provider.tsx
|
||||
// 原因:BUG-2127,账户弹窗从首页搬到 (app) 外壳(components/account-dialog-provider.tsx),每页原地打开
|
||||
const onboarding = readFileSync(new URL("../src/components/account-dialog-provider.tsx", import.meta.url), "utf8");
|
||||
assert.match(onboarding, /clearHomeWarmSnapshot\(\);\n\s+await selfHostedOtpActions\.signOut\(\);\n\s+window\.location\.assign\("\/login"\);/);
|
||||
const provider = readFileSync(new URL("../src/lib/session-list-context.tsx", import.meta.url), "utf8");
|
||||
assert.match(provider, /accountResult\.status === 401\) \{\n\s+clearHomeWarmSnapshot\(\);/);
|
||||
|
||||
@@ -12,7 +12,10 @@ const sessionHook = readFileSync(new URL("../src/hooks/use-session-management.ts
|
||||
test("the app layout owns one SessionListProvider and one SidebarProvider", () => {
|
||||
assert.match(layout, /<SessionListProvider>/);
|
||||
assert.equal(layout.match(/<SessionListProvider>/g)?.length, 1);
|
||||
assert.match(layout, /<SidebarProvider escapeBlocked=\{registration\?\.escapeBlocked \?\? false\}>/);
|
||||
// 原值:/<SidebarProvider escapeBlocked=\{registration\?\.escapeBlocked \?\? false\}>/
|
||||
// 新值:再或上外壳的账户弹窗是否打开(accountDialogOpen)
|
||||
// 原因:BUG-2127,账户弹窗从首页搬到 (app) 外壳(components/account-dialog-provider.tsx),每页原地打开
|
||||
assert.match(layout, /<SidebarProvider escapeBlocked=\{\(registration\?\.escapeBlocked \?\? false\) \|\| accountDialogOpen\}>/);
|
||||
assert.equal(layout.match(/<SidebarProvider/g)?.length, 1);
|
||||
assert.match(layout, /<AppSidebar/);
|
||||
assert.doesNotMatch(page, /<SidebarProvider/);
|
||||
|
||||
@@ -42,7 +42,10 @@ const styles = read("../src/app/globals.css");
|
||||
const panel = read("../src/components/billing-panel.tsx");
|
||||
const hook = read("../src/hooks/use-billing-panel.ts");
|
||||
const ledgerHook = read("../src/hooks/use-credit-ledger.ts");
|
||||
const page = read("../src/app/(app)/page.tsx");
|
||||
// 原值:`const page = read("../src/app/(app)/page.tsx")`
|
||||
// 新值:读外壳的 account-dialog-provider.tsx,设置弹窗的各分区现在由它画
|
||||
// 原因:BUG-2127,账户弹窗从首页搬到 (app) 外壳,每页原地打开,内容不变
|
||||
const page = read("../src/components/account-dialog-provider.tsx");
|
||||
const sidebar = read("../src/components/app-sidebar.tsx");
|
||||
const avatarRow = read("../src/components/avatar-image-row.tsx");
|
||||
|
||||
|
||||
@@ -293,7 +293,11 @@ test("the same component renders read-only when `/` is not the one mounting it",
|
||||
assert.doesNotMatch(appSidebar, /<AppLink\n\s*className="sidebar-account-trigger"/);
|
||||
assert.equal(appSidebar.match(/<DropdownMenu /g)?.length, 1, "one account menu");
|
||||
assert.match(appSidebar, /\{account \? \(\s*(?:\/\*[\s\S]*?\*\/\s*)?<DropdownMenu open=\{accountMenuOpen\}/);
|
||||
assert.match(appSidebar, /render=\{<AppLink href=\{accountDialogHref\(dialog\)\}/);
|
||||
// 原值:/render=\{<AppLink href=\{accountDialogHref\(dialog\)\}/——只读页的弹窗项链到 `/?account=<dialog>`
|
||||
// 新值:没有这种链接;弹窗项在每页都是按钮,交给外壳的 onOpenAccountDialog 原地打开
|
||||
// 原因:BUG-2127,账户弹窗从首页搬到 (app) 外壳(components/account-dialog-provider.tsx),每页原地打开,站外页不再先跳回聊天页
|
||||
assert.doesNotMatch(appSidebar, /accountDialogHref/);
|
||||
assert.match(appSidebar, /onOpenAccountDialog\?\.\(dialog, ownTriggerRef\.current\)/);
|
||||
|
||||
// And nothing in read-only mode can write: the write callbacks only exist
|
||||
// inside `controls`, which the secondary layout never passes.
|
||||
@@ -400,7 +404,10 @@ test("composes the chat page with the app sidebar shell", () => {
|
||||
const shell = readProjectFile("src/hooks/use-home-shell-registration.ts");
|
||||
|
||||
assert.match(page, /const modalOpen = activeAccountDialog !== null \|\| onboardingPaywallOpen/);
|
||||
assert.match(layout, /<SidebarProvider escapeBlocked=\{registration\?\.escapeBlocked \?\? false\}>/);
|
||||
// 原值:/<SidebarProvider escapeBlocked=\{registration\?\.escapeBlocked \?\? false\}>/
|
||||
// 新值:再或上外壳的账户弹窗是否打开
|
||||
// 原因:BUG-2127,账户弹窗从首页搬到 (app) 外壳(components/account-dialog-provider.tsx),每页原地打开;别的页没有 Home 的登记,弹窗开着时手机抽屉也不能被 Esc 收起
|
||||
assert.match(layout, /<SidebarProvider escapeBlocked=\{\(registration\?\.escapeBlocked \?\? false\) \|\| accountDialogOpen\}>/);
|
||||
assert.match(layout, /<main className="chat-app">[\s\S]*<AppSidebar\b/);
|
||||
assert.match(layout, /insetClassName/);
|
||||
// 原值:chat-panel 带 is-rectification 新值:固定 "chat-panel" 原因:2026-11-06 会话式生时纠正下线
|
||||
@@ -424,7 +431,10 @@ test("blocks the provider mobile Escape action behind layered account UI", () =>
|
||||
const sidebar = readProjectFile("src/components/ui/sidebar.tsx");
|
||||
|
||||
assert.match(shell, /escapeBlocked: accountMenuOpen \|\| modalOpen/);
|
||||
assert.match(layout, /escapeBlocked=\{registration\?\.escapeBlocked \?\? false\}/);
|
||||
// 原值:/escapeBlocked=\{registration\?\.escapeBlocked \?\? false\}/
|
||||
// 新值:同上,再或上 accountDialogOpen
|
||||
// 原因:BUG-2127,账户弹窗从首页搬到 (app) 外壳(components/account-dialog-provider.tsx),每页原地打开
|
||||
assert.match(layout, /escapeBlocked=\{\(registration\?\.escapeBlocked \?\? false\) \|\| accountDialogOpen\}/);
|
||||
assert.match(sidebar, /event\.key === "Escape" && isMobile && openMobile && !escapeBlocked/);
|
||||
});
|
||||
|
||||
|
||||
@@ -92,7 +92,11 @@ test("routes account actions through a menu and focused dialogs", () => {
|
||||
// When: the page source is inspected for independent menu and dialog routes.
|
||||
// Then: profile and logout stay focused dialogs; billing opens in the settings pane.
|
||||
assert.match(pageSource, /const \[accountMenuOpen, setAccountMenuOpen\] = useState\(false\)/);
|
||||
assert.match(pageSource, /const \[activeAccountDialog, setActiveAccountDialog\] = useState<AccountDialog \| null>\(null\)/);
|
||||
// 原值:/const \[activeAccountDialog, setActiveAccountDialog\] = useState<AccountDialog \| null>\(null\)/(首页自己的状态)
|
||||
// 新值:状态在外壳 `const [activeDialog, setActiveDialog] = useState<AccountDialog | null>(null)`,首页读 `accountDialogs.activeDialog`
|
||||
// 原因:BUG-2127,账户弹窗从首页搬到 (app) 外壳(components/account-dialog-provider.tsx),每页原地打开
|
||||
assert.match(pageSource, /const \[activeDialog, setActiveDialog\] = useState<AccountDialog \| null>\(null\)/);
|
||||
assert.match(pageSource, /const activeAccountDialog = accountDialogs\.activeDialog;/);
|
||||
assert.match(pageSource, /openAccountDialog\("profile"/);
|
||||
assert.match(pageSource, /openAccountDialog\("logout"/);
|
||||
assert.doesNotMatch(pageSource, /type AccountDialog = "profile" \| "redeem" \| "logout"/);
|
||||
|
||||
@@ -211,7 +211,11 @@ test("the synastry page is a static shell and reads the flag in the browser", ()
|
||||
assert.match(picker, /会用掉 \$\{creditCost\} 点,余额 \$\{balance\} 点。/);
|
||||
assert.match(picker, /需要 \$\{creditCost\} 点,余额只有 \$\{balance\} 点。/);
|
||||
assert.match(picker, /去补点数/);
|
||||
assert.match(picker, /accountDialogHref\("billing"\)/);
|
||||
// 原值:/accountDialogHref\("billing"\)/——「去补点数」整页跳到 `/?account=billing`,落到聊天页再开弹窗
|
||||
// 新值:先关确认框,再用外壳的 open("billing", { source: "insufficient-credits" }) 在合盘页原地打开账户与点数
|
||||
// 原因:BUG-2127,账户弹窗搬到 (app) 外壳后每页原地打开;同类入口一并改
|
||||
assert.doesNotMatch(picker, /accountDialogHref/);
|
||||
assert.match(picker, /setConfirming\(false\); accountDialogs\.open\("billing", \{ source: "insufficient-credits" \}\);/);
|
||||
const again = renderToStaticMarkup(createElement(SynastryGoNotes, {
|
||||
creditCost: 19,
|
||||
pricingNote: "",
|
||||
|
||||
@@ -53,7 +53,11 @@ test("a contents pick moves the page to its target after the chapter is drawn",
|
||||
test("a ledger row that opens another page closes the settings dialog", () => {
|
||||
assert.match(panel, /className="billing-row billing-ledger-row is-link" href=\{href\} onClick=\{onNavigate\}/);
|
||||
assert.match(panel, /<LedgerRow entry=\{entry\} key=\{entry\.id\} onNavigate=\{onNavigate\} \/>/);
|
||||
assert.match(page, /<BillingPanel [^>]*onNavigate=\{closeAccountDialog\}/);
|
||||
// 原值:/<BillingPanel [^>]*onNavigate=\{closeAccountDialog\}/ 在 page.tsx
|
||||
// 新值:在外壳的 account-dialog-provider.tsx 里 `onNavigate={close}`(外壳的关弹窗,同一个函数也给首页用)
|
||||
// 原因:BUG-2127,账户弹窗从首页搬到 (app) 外壳(components/account-dialog-provider.tsx),每页原地打开;任何页上点点数记录行都先关弹窗再跳转
|
||||
assert.doesNotMatch(page, /<BillingPanel /);
|
||||
assert.match(read("../src/components/account-dialog-provider.tsx"), /<BillingPanel [^>]*onNavigate=\{close\}/);
|
||||
});
|
||||
|
||||
test("the last rows of a long contents rail scroll clear of the floating button", () => {
|
||||
|
||||
@@ -22,6 +22,8 @@ OPTIONAL_HOME_HOOKS = (
|
||||
_FRONTEND_SRC / "hooks" / "use-consultation-run.ts",
|
||||
_FRONTEND_SRC / "hooks" / "use-profile-onboarding.ts",
|
||||
_FRONTEND_SRC / "hooks" / "use-rectification-surface.ts",
|
||||
# BUG-2127:账户弹窗(含 Escape 关闭)从首页搬到 (app) 外壳,每页原地打开。
|
||||
_FRONTEND_SRC / "components" / "account-dialog-provider.tsx",
|
||||
)
|
||||
STYLES = Path("frontend/src/app/globals.css")
|
||||
SESSION_ROW = Path("frontend/src/components/sidebar-session-row.tsx")
|
||||
|
||||
Reference in New Issue
Block a user