Criar Hotel: a escolha do dossier mostra a actividade de cada um

Vindo da página de um sector, os dossiers do mesmo sector aparecem primeiro,
cada um com a sua actividade, e escolher um dossier de outra actividade
avisa que o novo sector fica só como proposta.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jM
This commit is contained in:
Claude
2026-12-04 21:11:45 +02:00
committed by nala
parent a3f2d2d7ca
commit b7ec4578dd
4 changed files with 76 additions and 4 deletions
+13 -2
View File
@@ -352,8 +352,19 @@ final class InvestorPath
$contexts = DB::table('desk_cases as c')->join('investor_journeys as j', 'j.id', '=', 'c.journey_id')->whereNotNull('j.path_definition_id')
->whereNull('j.deleted_at')->whereNull('c.closed_at')->where(fn ($q) => $q->where(fn ($p) => $p->where('c.user_id', $actor->id)->whereNull('c.organization_id'))->orWhereIn('c.organization_id', $organizations))
->orderByDesc('c.updated_at')->get(['c.id', 'c.title', 'c.version', 'c.updated_at'])
->map(fn ($row) => ['id' => $row->id, 'title' => $row->title, 'version' => $row->version, 'updated_at' => $row->updated_at])->all();
->orderByDesc('c.updated_at')->get(['c.id', 'c.title', 'c.version', 'c.updated_at', 'c.payload'])
->map(function ($row) {
// The dossier's primary activity, so a new reference never lands in the wrong initiative unseen.
try {
$fields = $this->desk->decode($row->payload)['investor_path']['context']['fields'] ?? [];
} catch (\Throwable) {
$fields = [];
}
return ['id' => $row->id, 'title' => $row->title, 'version' => $row->version, 'updated_at' => $row->updated_at,
'sector_id' => isset($fields['sector_id']) && $fields['sector_id'] !== '' ? (string) $fields['sector_id'] : null,
'sector' => isset($fields['sector']) && $fields['sector'] !== '' ? (string) $fields['sector'] : null];
})->all();
return array_values($contexts);
}
@@ -22,7 +22,13 @@ export default function ContextStart({
entryComplements = [],
entrySubmission = null,
}: {
contexts: { id: string; title: string; version: number }[];
contexts: {
id: string;
title: string;
version: number;
sector_id?: string | null;
sector?: string | null;
}[];
source: ContextReference | null;
opportunityChoices?: OpportunityChoice[];
step?: string | null;
@@ -31,6 +37,23 @@ export default function ContextStart({
entrySubmission?: { id: string; version: number } | null;
}) {
const [chosen, setChosen] = useState('');
// The investor's first choice leads: dossiers of the same sector come
// first, and a different sector is only ever proposed, never swapped in.
const sourceSector =
source?.kind === 'sector' ? (source.fields.sector_id ?? null) : null;
const ordered = sourceSector
? [
...contexts.filter((c) => c.sector_id === sourceSector),
...contexts.filter((c) => c.sector_id !== sourceSector),
]
: contexts;
const chosenContext = contexts.find((c) => c.id === chosen);
const otherActivity =
sourceSector &&
chosenContext?.sector_id &&
chosenContext.sector_id !== sourceSector
? chosenContext
: null;
const [title, setTitle] = useState(
entryComplements[0]?.kind === 'need'
? `Preparação de ${entryComplements[0].title} — ${entryComplements[0].origin.title}`.slice(
@@ -174,13 +197,26 @@ export default function ContextStart({
onChange={(e) => setChosen(e.target.value)}
>
<option value="">Selecionar dossier autorizado</option>
{contexts.map((c) => (
{ordered.map((c) => (
<option key={c.id} value={c.id}>
{c.title}
{c.sector ? ` — ${c.sector}` : ''}
</option>
))}
</select>
</label>
{otherActivity && (
<p
role="note"
className="rounded border border-amber-300 bg-amber-50 p-3"
>
O dossier «{otherActivity.title}» é de{' '}
{otherActivity.sector}. Se continuar nele, {source?.title}{' '}
fica apenas como proposta e a actividade do dossier
mantém-se. Para preparar uma ideia em {source?.title},
crie uma nova ideia abaixo.
</p>
)}
{chosen && entrySubmission && (
<button
className={button}
@@ -127,6 +127,9 @@ class InvestmentContextContinuityTest extends TestCase
$apply(['sector' => null]);
$this->getJson('/investimentos/'.$id.'/contexto')->assertJsonPath('context.fields.sector_id', (string) $tourism->id);
// The dossier choice shows each dossier's activity.
$listed = collect(app(\App\Services\InvestorPath::class)->contexts($owner))->firstWhere('id', $id);
$this->assertSame([(string) $tourism->id, $tourism->name], [$listed['sector_id'], $listed['sector']]);
$apply(['sector' => 'sector:'.$agro->id], ['sector_id', 'sector']);
$this->getJson('/investimentos/'.$id.'/contexto')->assertJsonPath('context.fields.sector_id', (string) $agro->id)->assertJsonPath('context.fields.sector', $agro->name);
@@ -158,3 +158,25 @@ test("the education page reads the population by age groups and says the trainin
/ainda não está disponível no portal público[\s\S]*Pedir apoio da equipa para esta localização/,
);
});
test('choosing a dossier from a sector page shows each dossier activity, same sector first (Criar Hotel)', () => {
const { default: ContextStart } = load('pages/investor-path/context-start.tsx');
const html = renderToStaticMarkup(
React.createElement(ContextStart, {
contexts: [
{ id: 'a', title: 'Criar Hotel', version: 1, sector_id: '7', sector: 'Turismo' },
{ id: 'b', title: 'Machamba', version: 1, sector_id: '1', sector: 'Agronegócio' },
{ id: 'c', title: 'Sem sector', version: 1 },
],
source: { key: 'sector:1', kind: 'sector', id: '1', title: 'Agronegócio', href: '/sectores/agronegocio', version: null, sha256: '', fields: { sector_id: '1', sector: 'Agronegócio' } },
opportunityChoices: [],
entryQuery: {},
}),
);
const options = [...html.matchAll(/<option value="([a-z]*)">([^<]*)<\/option>/g)].map((m) => m[2]);
assert.deepEqual(options, [
'Machamba — Agronegócio',
'Criar Hotel — Turismo',
'Sem sector',
]);
});