Forma jurídica: comparar num dossier guarda sempre, e a página geral oferece retomar
Mapa de erros: uma comparação já feita não ficava guardada e o investidor tinha de recomeçar. No dossier, «Actualizar comparação» e «Guardar no dossier» passam a ser uma só acção, «Comparar e guardar no dossier» (também com Enter), que guarda sempre o resultado com o histórico existente. A página geral das formas jurídicas mostra as comparações já guardadas nos dossiers do investidor, com ligação para as retomar; outros utilizadores e visitantes não vêem nenhuma. O questionário único por temas (C07) não muda. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jM
This commit is contained in:
@@ -3,8 +3,10 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\CompanyComparison;
|
||||
use App\Services\InvestorPath;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
@@ -13,8 +15,14 @@ final class CompanyComparisonController extends Controller
|
||||
public function index(Request $request, CompanyComparison $service): Response|JsonResponse
|
||||
{
|
||||
$answers = $service->answers($request->all());
|
||||
// Comparisons already kept in the investor's own dossiers, to resume them from the general page.
|
||||
$contexts = $request->user() ? collect(app(InvestorPath::class)->contexts($request->user())) : collect();
|
||||
$kept = $contexts->isEmpty() ? collect() : DB::table('desk_events')->whereIn('case_id', $contexts->pluck('id'))
|
||||
->where('action', CompanyComparison::EVENT)->selectRaw('case_id, max(created_at) as at')->groupBy('case_id')->pluck('at', 'case_id');
|
||||
$data = ['definition' => $service->definition(), 'answers' => $answers, 'result' => $service->evaluate($answers),
|
||||
'case' => null, 'saved' => null, 'canWrite' => false, 'history' => [], 'historyNext' => null, 'historical' => false, 'workingCopy' => false];
|
||||
'case' => null, 'saved' => null, 'canWrite' => false, 'history' => [], 'historyNext' => null, 'historical' => false, 'workingCopy' => false,
|
||||
'savedCases' => $contexts->filter(fn (array $c) => $kept->has($c['id']))
|
||||
->map(fn (array $c) => ['id' => $c['id'], 'title' => $c['title'], 'at' => (string) $kept[$c['id']]])->values()->all()];
|
||||
|
||||
return $request->expectsJson() ? response()->json($data) : Inertia::render('investment/company-comparison', $data);
|
||||
}
|
||||
|
||||
@@ -56,6 +56,8 @@ type Props = {
|
||||
answers: CompanyAnswers;
|
||||
result: Result;
|
||||
saved: { revision: number; at: string; result: Result } | null;
|
||||
/** Dossiers of the investor that already keep a comparison (general page only). */
|
||||
savedCases?: { id: string; title: string; at: string }[];
|
||||
history: {
|
||||
id: string;
|
||||
revision: number;
|
||||
@@ -148,6 +150,25 @@ function Comparator(props: Props) {
|
||||
</p>
|
||||
)}
|
||||
<p>{comparisonIntroduction}</p>
|
||||
{!dossier && (props.savedCases?.length ?? 0) > 0 && (
|
||||
<section className={card} aria-label="Comparações guardadas">
|
||||
<h2 className="font-semibold">
|
||||
Comparações guardadas nos seus dossiers
|
||||
</h2>
|
||||
<ul className="list-disc pl-5">
|
||||
{props.savedCases!.map((item) => (
|
||||
<li key={item.id}>
|
||||
<Link
|
||||
className="underline"
|
||||
href={`/investimentos/${item.id}/forma-juridica`}
|
||||
>
|
||||
Retomar a comparação de «{item.title}»
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
)}
|
||||
{saved && (
|
||||
<p>
|
||||
{historical
|
||||
@@ -183,7 +204,18 @@ function Comparator(props: Props) {
|
||||
</Link>
|
||||
</section>
|
||||
) : (
|
||||
<form ref={formRef} action={base} method="get" className={card}>
|
||||
<form
|
||||
ref={formRef}
|
||||
action={base}
|
||||
method="get"
|
||||
className={card}
|
||||
onSubmit={(event) => {
|
||||
// In a dossier the comparison is always kept: comparing also saves.
|
||||
if (!dossier || !props.canWrite) return;
|
||||
event.preventDefault();
|
||||
void save();
|
||||
}}
|
||||
>
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
{Object.entries(definition.questions).map(
|
||||
([key, question]) =>
|
||||
@@ -239,21 +271,23 @@ function Comparator(props: Props) {
|
||||
)}
|
||||
</div>
|
||||
<div className="mt-4 flex flex-wrap gap-3">
|
||||
<button className={button} disabled={busy}>
|
||||
Actualizar comparação
|
||||
</button>
|
||||
{dossier ? (
|
||||
props.canWrite && (
|
||||
<button
|
||||
type="button"
|
||||
className={button}
|
||||
disabled={busy}
|
||||
onClick={() => void save()}
|
||||
>
|
||||
{busy ? 'A guardar…' : 'Guardar no dossier'}
|
||||
</button>
|
||||
)
|
||||
{dossier && props.canWrite ? (
|
||||
<button
|
||||
type="button"
|
||||
className={button}
|
||||
disabled={busy}
|
||||
onClick={() => void save()}
|
||||
>
|
||||
{busy
|
||||
? 'A guardar…'
|
||||
: 'Comparar e guardar no dossier'}
|
||||
</button>
|
||||
) : (
|
||||
<button className={button} disabled={busy}>
|
||||
Actualizar comparação
|
||||
</button>
|
||||
)}
|
||||
{dossier ? null : (
|
||||
<button
|
||||
type="button"
|
||||
className={button}
|
||||
@@ -273,8 +307,9 @@ function Comparator(props: Props) {
|
||||
</div>
|
||||
{dirty && (
|
||||
<p role="status">
|
||||
Actualize a comparação para reflectir as alterações.
|
||||
Guardar utiliza as respostas actuais.
|
||||
{dossier && props.canWrite
|
||||
? 'Compare e guarde para reflectir as alterações no dossier.'
|
||||
: 'Actualize a comparação para reflectir as alterações.'}
|
||||
</p>
|
||||
)}
|
||||
{dossier && !props.canWrite && (
|
||||
|
||||
@@ -108,6 +108,19 @@ final class CompanyComparisonTest extends TestCase
|
||||
$this->postJson($url, [...$input, 'operation_key' => (string) Str::uuid()])->assertConflict();
|
||||
}
|
||||
|
||||
public function test_a_comparison_kept_in_a_dossier_is_offered_for_resumption_from_the_general_page(): void
|
||||
{
|
||||
// Mapa de erros, forma jurídica: the investor returns from the menu and finds the comparison already made.
|
||||
$id = $this->dossier();
|
||||
$this->getJson('/formas-juridicas')->assertOk()->assertJsonPath('savedCases', []);
|
||||
$case = DB::table('desk_cases')->where('id', $id)->first();
|
||||
$this->postJson('/investimentos/'.$id.'/forma-juridica', ['version' => $case->version, 'operation_key' => (string) Str::uuid(),
|
||||
'answers' => ['participants' => 'one', 'preferred' => 'quotas']])->assertOk();
|
||||
$this->getJson('/formas-juridicas')->assertOk()->assertJsonPath('savedCases.0.id', $id)
|
||||
->assertJsonPath('savedCases.0.title', 'SYNTHETIC company preparation');
|
||||
$this->actingAs(User::factory()->create())->getJson('/formas-juridicas')->assertOk()->assertJsonPath('savedCases', []);
|
||||
}
|
||||
|
||||
public function test_historical_answers_sources_and_results_do_not_follow_future_engine_changes(): void
|
||||
{
|
||||
$id = $this->dossier();
|
||||
|
||||
@@ -238,7 +238,7 @@ await test('a failed save keeps actual field values and context, and never navig
|
||||
}
|
||||
};
|
||||
try {
|
||||
await button(tree, 'Guardar no dossier').props.onClick();
|
||||
await button(tree, 'Comparar e guardar no dossier').props.onClick();
|
||||
} finally {
|
||||
globalThis.FormData = old;
|
||||
}
|
||||
@@ -323,7 +323,7 @@ await test('successful save recovers the saved dossier edition and history links
|
||||
}
|
||||
};
|
||||
try {
|
||||
await button(tree, 'Guardar no dossier').props.onClick();
|
||||
await button(tree, 'Comparar e guardar no dossier').props.onClick();
|
||||
} finally {
|
||||
globalThis.FormData = old;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user