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' &&
+7
View File
@@ -2,6 +2,7 @@ export type NavigationFocus = {
case_id: string;
step_code: string | null;
version: number;
opportunity?: string | null;
};
const key = (actor: number) => `investmoz-navigation-focus:${actor}`;
/** A per-tab hint, never authority to access a dossier. Recheck the server listing. */
@@ -27,6 +28,12 @@ export function readNavigationFocus(
case_id: value.case_id,
step_code: value.step_code,
version: value.version,
...(value.opportunity === null ||
(typeof value.opportunity === 'string' &&
value.opportunity.length > 0 &&
value.opportunity.length <= 100)
? { opportunity: value.opportunity }
: {}),
};
} catch {
return null;
+17 -1
View File
@@ -90,6 +90,9 @@ function Index({
});
const applied = useRef(JSON.stringify(form.data));
const criteriaChanged = JSON.stringify(form.data) !== applied.current;
const searchReady = Boolean(
form.data.need && (form.data.territory || form.data.province_id),
);
const typeAllowed = (category: string, type: string) =>
!category ||
category === 'other' ||
@@ -115,6 +118,7 @@ function Index({
className={`${card} flex flex-wrap gap-4 [&_select]:w-full [&_select]:max-w-full [&_select]:min-w-0 [&>label]:w-full [&>label]:max-w-full [&>label]:min-w-0 sm:[&>label]:w-auto`}
onSubmit={(e) => {
e.preventDefault();
if (!searchReady) return;
form.get('/fundos');
}}
>
@@ -406,7 +410,19 @@ function Index({
))}
</select>
</label>
<button className={button} disabled={form.processing}>
{!searchReady && (
<p id="funding-search-minimum" role="status">
Escolha a localização a pesquisar e a necessidade do
processo antes de pesquisar.
</p>
)}
<button
className={button}
disabled={form.processing || !searchReady}
aria-describedby={
!searchReady ? 'funding-search-minimum' : undefined
}
>
Pesquisar
</button>
</form>