@@ -148,23 +148,39 @@ export function SimulationBusinessPlan({
|
||||
const importPlanFile = async (file: File | undefined) => {
|
||||
if (!file) return;
|
||||
if (file.size > MAX_BUSINESS_PLAN_SNAPSHOT_LENGTH) {
|
||||
setSnapshotError('O ficheiro excede 60 KB. Seleccione um plano JSON exportado pelo InvestMoz dentro deste limite.');
|
||||
setSnapshotError(
|
||||
'O ficheiro excede 60 KB. Seleccione um plano JSON exportado pelo InvestMoz dentro deste limite.',
|
||||
);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const source = await file.text();
|
||||
const imported = restoreBusinessPlanSnapshot(source);
|
||||
if (!imported) throw new Error('O ficheiro não contém um plano JSON reconhecido pelo InvestMoz.');
|
||||
if (!imported)
|
||||
throw new Error(
|
||||
'O ficheiro não contém um plano JSON reconhecido pelo InvestMoz.',
|
||||
);
|
||||
savePlan(imported);
|
||||
setSnapshotError('');
|
||||
} catch (cause) {
|
||||
setSnapshotError(cause instanceof Error ? cause.message : 'Não foi possível importar este plano.');
|
||||
setSnapshotError(
|
||||
cause instanceof Error
|
||||
? cause.message
|
||||
: 'Não foi possível importar este plano.',
|
||||
);
|
||||
}
|
||||
};
|
||||
const exportPlanJson = () => {
|
||||
try {
|
||||
const snapshotJson = serializeBusinessPlanSnapshot({ ...plan, currency });
|
||||
const url = URL.createObjectURL(new Blob([snapshotJson], { type: 'application/json;charset=utf-8' }));
|
||||
const snapshotJson = serializeBusinessPlanSnapshot({
|
||||
...plan,
|
||||
currency,
|
||||
});
|
||||
const url = URL.createObjectURL(
|
||||
new Blob([snapshotJson], {
|
||||
type: 'application/json;charset=utf-8',
|
||||
}),
|
||||
);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = 'plano-financeiro-investmoz.json';
|
||||
@@ -173,7 +189,11 @@ export function SimulationBusinessPlan({
|
||||
window.setTimeout(() => URL.revokeObjectURL(url), 1000);
|
||||
setSnapshotError('');
|
||||
} catch (cause) {
|
||||
setSnapshotError(cause instanceof Error ? cause.message : 'Não foi possível exportar este plano.');
|
||||
setSnapshotError(
|
||||
cause instanceof Error
|
||||
? cause.message
|
||||
: 'Não foi possível exportar este plano.',
|
||||
);
|
||||
}
|
||||
};
|
||||
type ProductScheduleKey =
|
||||
@@ -856,10 +876,27 @@ export function SimulationBusinessPlan({
|
||||
<div className="my-3 flex flex-wrap items-end gap-3 rounded border p-3">
|
||||
<label className="grid gap-1 text-sm">
|
||||
Importar plano financeiro InvestMoz (.json, até 60 KB)
|
||||
<input type="file" accept="application/json,.json" onChange={(event) => { void importPlanFile(event.currentTarget.files?.[0]); event.currentTarget.value = ''; }} />
|
||||
<input
|
||||
type="file"
|
||||
accept="application/json,.json"
|
||||
onChange={(event) => {
|
||||
void importPlanFile(event.currentTarget.files?.[0]);
|
||||
event.currentTarget.value = '';
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
<button type="button" className="rounded border px-3 py-2 text-sm" onClick={exportPlanJson}>Exportar plano JSON</button>
|
||||
<span className="text-xs text-slate-600">O ficheiro é lido localmente. A importação substitui os pressupostos editáveis deste plano após validação do formato.</span>
|
||||
<button
|
||||
type="button"
|
||||
className="rounded border px-3 py-2 text-sm"
|
||||
onClick={exportPlanJson}
|
||||
>
|
||||
Exportar plano JSON
|
||||
</button>
|
||||
<span className="text-xs text-slate-600">
|
||||
O ficheiro é lido localmente. A importação substitui os
|
||||
pressupostos editáveis deste plano após validação do
|
||||
formato.
|
||||
</span>
|
||||
</div>
|
||||
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
|
||||
<label className="block text-sm font-medium">
|
||||
|
||||
Reference in New Issue
Block a user