fix(qa): verify private investor continuity across dossiers

This commit is contained in:
2026-11-20 19:20:03 +02:00
parent e299afdae4
commit 15e15d0bfd
13 changed files with 563 additions and 16 deletions
@@ -12,6 +12,7 @@ import {
rememberNavigationFocus,
} from '@/lib/navigation-focus';
export type NavigationView = {
context_opportunity?: string | null;
case: { id: string; title: string; version: number };
phases: Record<string, string>;
steps: {
@@ -105,7 +106,19 @@ export function NavigationContextProvider({
useEffect(() => {
setHash(window.location.hash);
}, [url]);
const current = loaded?.actor === actor ? loaded : null;
const pageLocation = new URL(url, 'https://context.invalid');
const requestedCase =
url.match(/^\/investimentos\/([a-f0-9-]{36})(?:[/?#]|$)/i)?.[1] ??
pageLocation.searchParams.get('context');
const requestedOpportunity = pageLocation.searchParams.get('opportunity');
// Never label the new page with the previous dossier while its request is pending.
const current =
loaded?.actor === actor &&
(!requestedCase || loaded?.focus?.case_id === requestedCase) &&
(!requestedOpportunity ||
loaded?.view?.context_opportunity === requestedOpportunity)
? loaded
: null;
const active = current?.focus?.case_id ?? '';
useEffect(() => {
if (!actor || !props.investorPathEnabled) return;
@@ -163,13 +176,31 @@ export function NavigationContextProvider({
)
).focus;
}
// An explicit URL without an opportunity opens the whole dossier.
// A general menu preserves this tab's last server-confirmed scope.
const opportunity = direct
? new URL(url, 'https://context.invalid').searchParams.get(
'opportunity',
)
: localFocus?.opportunity;
if (direct && !listing.contexts.some((c) => c.id === direct)) {
focus = null;
}
const view = focus
? await contextApi<NavigationView>(
`/investimentos/${focus.case_id}${direct === focus.case_id && new URL(url, 'https://context.invalid').searchParams.get('opportunity') ? '?opportunity=' + encodeURIComponent(new URL(url, 'https://context.invalid').searchParams.get('opportunity')!) : ''}`,
`/investimentos/${focus.case_id}${opportunity && (!direct || direct === focus.case_id) ? '?opportunity=' + encodeURIComponent(opportunity) : ''}`,
)
: null;
if (!stopped) {
rememberNavigationFocus(actor, focus);
rememberNavigationFocus(
actor,
focus
? {
...focus,
opportunity: view?.context_opportunity ?? null,
}
: null,
);
setLoaded({ actor, cases: listing.contexts, focus, view });
if (pref.message) setError(pref.message);
}
@@ -210,8 +241,13 @@ export function NavigationContextProvider({
),
)
.then(({ focus }) => {
rememberNavigationFocus(actor, focus);
const target = `/investimentos/${id}${step ? '#' + step : ''}`;
const opportunity =
id === active ? current.view?.context_opportunity : null;
rememberNavigationFocus(actor, {
...focus,
opportunity: opportunity ?? null,
});
const target = `/investimentos/${id}${opportunity ? '?opportunity=' + encodeURIComponent(opportunity) : ''}${step ? '#' + step : ''}`;
if (url !== target) router.visit(target);
else setReload((x) => x + 1);
})
@@ -255,7 +291,9 @@ export function NavigationContextSummary() {
const ref = saved?.selection;
const params = new URLSearchParams(url.split('?')[1] ?? '');
const scopedChoice = saved?.opportunity_choices?.find(
(c) => c.opportunity.key === params.get('opportunity'),
(c) =>
c.opportunity.key ===
(params.get('opportunity') ?? view?.context_opportunity),
);
const multiple = (saved?.opportunity_choices?.length ?? 0) > 1;
const currentStep = view?.steps.find((s) => s.code === step);
@@ -449,7 +487,7 @@ export function NavigationContextSummary() {
{view.investment_context && (
<Link
className="block underline"
href={`/investimentos/${active}/contexto/editar`}
href={`/investimentos/${active}/contexto/editar${scopedChoice ? '?opportunity=' + encodeURIComponent(scopedChoice.opportunity.key) : ''}`}
>
Comparar e guardar oportunidade,
sector ou localização
@@ -41,6 +41,7 @@ export function InvestmentHelpGuide({
const [active, setActive] = useState<string | null>(null);
const [automatic, setAutomatic] = useState(true);
const paused = useRef(false);
const pointerFocus = useRef(false);
const key = helpPreferenceKey(user, flow);
const firstCode = steps.some((step) => step.code === initialCode)
? initialCode
@@ -151,8 +152,24 @@ export function InvestmentHelpGuide({
<div
ref={root}
className="space-y-5"
onFocusCapture={(event) => orient(event.target)}
onClickCapture={(event) => orient(event.target)}
onPointerDownCapture={() => {
pointerFocus.current = true;
}}
onPointerUpCapture={() => {
pointerFocus.current = false;
}}
onPointerCancelCapture={() => {
pointerFocus.current = false;
}}
onFocusCapture={(event) => {
// Opening inline help during pointer focus can move the
// target between pointerdown and click, losing the action.
if (!pointerFocus.current) orient(event.target);
}}
onClickCapture={(event) => {
pointerFocus.current = false;
orient(event.target);
}}
onKeyDown={(event) => {
if (
event.key === 'Escape' &&