fix: reject stale context previews and protect pending edits

This commit is contained in:
2026-10-29 23:01:36 +02:00
parent a10dd83d8d
commit 26f6a0d348
5 changed files with 265 additions and 0 deletions
@@ -372,6 +372,8 @@ export default function ContextEditor({
};
async function preview() {
setBusy(true);
setPlan(null);
setRequestBody(null);
setError('');
setMessage('');
const body = {
@@ -403,6 +405,11 @@ export default function ContextEditor({
`/investimentos/${view.case.id}/contexto/previa`,
body,
);
if (latestDraft.current !== draftBody) {
throw new Error(
'Os dados mudaram durante a comparação. Reveja novamente antes de guardar.',
);
}
setRequestBody(body);
setPlan(result);
setPreparation(
@@ -656,6 +663,7 @@ export default function ContextEditor({
<select
className={input}
value=""
disabled={busy}
onChange={(e) => {
const o = options.opportunities.find(
(o) => o.key === e.target.value,
@@ -955,6 +963,7 @@ export default function ContextEditor({
{Array.isArray(choices) ? (
<select
className={input}
disabled={busy}
value={
declarations[String(key)] ??
view.context.fields[String(key)] ??
@@ -978,6 +987,7 @@ export default function ContextEditor({
) : (
<input
className={input}
disabled={busy}
type={
key === 'expected_start_date'
? 'date'
@@ -1041,6 +1051,7 @@ export default function ContextEditor({
<label className="block" key={k}>
<input
type="checkbox"
disabled={busy}
checked={replace.includes(k)}
onChange={(e) => {
setReplace(