fix(licensing): simplify S08 and reveal linked stage without losing context

This commit is contained in:
2026-11-10 11:00:56 +02:00
parent 95def7f75e
commit 6734441855
3 changed files with 315 additions and 18 deletions
+15
View File
@@ -0,0 +1,15 @@
/** Reveal an existing stage without navigation, remounting fields or changing context. */
export function revealPathStage(root: HTMLElement, hash: string, codes: string[]): boolean {
const code = hash.startsWith("#") ? hash.slice(1) : "";
if (!codes.includes(code)) return false;
const target = root.ownerDocument.getElementById(code);
if (!target || !root.contains(target)) return false;
let current: HTMLElement | null = target;
while (current && current !== root) {
if (current.tagName === "DETAILS") (current as HTMLDetailsElement).open = true;
current = current.parentElement;
}
target.scrollIntoView({ block: "start" });
target.focus({ preventScroll: true });
return true;
}
+45 -18
View File
@@ -16,7 +16,8 @@ import FintechInvestment, {
} from '@/components/fintech-investment';
import { createOperationKey } from '@/lib/operation-key';
import { Head, Link, router, useForm, usePage } from '@inertiajs/react';
import { useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import { revealPathStage } from '@/lib/investor-path-stage';
import {
pathStates,
recoverPathResult,
@@ -177,16 +178,26 @@ function Stage({ step, path }: { step: Step; path: Path }) {
'expired',
];
const states = path.canWrite ? ownerStates : reviewStates;
const licensing = step.code === 'S08';
const Container = licensing ? 'section' : 'details';
const Heading = licensing ? 'h3' : 'summary';
const Reference = licensing ? 'div' : 'details';
const ReferenceHeading = licensing ? 'h4' : 'summary';
const Record = licensing ? 'section' : 'details';
const RecordHeading = licensing ? 'h4' : 'summary';
return (
<details
<Container
id={step.code}
open={path.next?.code === step.code}
className="space-y-3 rounded-xl border p-4"
tabIndex={-1}
open={licensing ? undefined : path.next?.code === step.code}
className={`space-y-3 rounded-xl border p-4 ${licensing ? 'md:col-span-2' : ''}`}
>
<summary className="cursor-pointer font-semibold">
<Heading
className={licensing ? 'text-lg font-semibold' : 'cursor-pointer font-semibold'}
>
{step.title} · {pathStates[step.state]}
</summary>
<p>{pathStates[step.state]}</p>
</Heading>
{!licensing && <p>{pathStates[step.state]}</p>}
{step.context_review_required && (
<label className="block rounded border border-amber-600 bg-amber-50 p-3">
<input
@@ -258,10 +269,10 @@ function Stage({ step, path }: { step: Step; path: Path }) {
. Pode continuar a preparar.
</p>
))}
<details className="text-xs">
<summary className="cursor-pointer underline">
<Reference className="text-xs">
<ReferenceHeading className={licensing ? 'font-semibold' : 'cursor-pointer underline'}>
Fonte e referência desta etapa
</summary>
</ReferenceHeading>
<p>
Referência interna {step.code}. Documento original,
parágrafo {step.source_paragraph}.{' '}
@@ -271,12 +282,14 @@ function Stage({ step, path }: { step: Step; path: Path }) {
? 'Acto externo registado a partir de documento.'
: 'Preparação declarada pelo promotor.'}
</p>
</details>
</Reference>
{step.preparation_allowed && (path.canWrite || path.canReview) && (
<details>
<summary className="cursor-pointer underline">
<Record
aria-label={licensing ? 'Registar licenciamento' : undefined}
>
<RecordHeading className={licensing ? 'font-semibold' : 'cursor-pointer underline'}>
Registar avanço ou pendência
</summary>
</RecordHeading>
<form
className="mt-3 grid gap-3"
onSubmit={(event) => {
@@ -424,18 +437,32 @@ function Stage({ step, path }: { step: Step; path: Path }) {
))}
<button
disabled={form.processing}
className="rounded border p-2"
className={licensing
? 'rounded bg-emerald-800 px-4 py-3 font-semibold text-white disabled:opacity-50'
: 'rounded border p-2'}
>
Guardar registo
</button>
</form>
</details>
</Record>
)}
</details>
</Container>
);
}
export default function InvestmentPath(path: Path) {
const root = useRef<HTMLElement>(null);
const stageCodes = path.steps.map((step) => step.code).join(',');
useEffect(() => {
const reveal = () => {
if (root.current) {
revealPathStage(root.current, window.location.hash, stageCodes.split(','));
}
};
reveal();
window.addEventListener('hashchange', reveal);
return () => window.removeEventListener('hashchange', reveal);
}, [path.case.id, path.context_opportunity, stageCodes]);
const { auth, flash } = usePage<{
auth: { user: { id: number } };
flash: { success?: string };
@@ -471,7 +498,7 @@ export default function InvestmentPath(path: Path) {
);
}
return (
<main className="mx-auto max-w-6xl min-w-0 space-y-6 p-4 [overflow-wrap:anywhere] md:p-8 [&_input]:max-w-full [&_input]:min-w-0 [&_label]:min-w-0 [&_select]:max-w-full [&_select]:min-w-0">
<main ref={root} className="mx-auto max-w-6xl min-w-0 space-y-6 p-4 [overflow-wrap:anywhere] md:p-8 [&_input]:max-w-full [&_input]:min-w-0 [&_label]:min-w-0 [&_select]:max-w-full [&_select]:min-w-0">
<Head title={path.case.title} />
<Link className="underline" href="/investimentos">
Os meus investimentos