Adapt land status to saved investment land need
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
export type LandPreparation = { need: 'yes' | 'no' | 'unknown'; reason: string };
|
||||
|
||||
/** Preparation decision from the same saved dossier, never evidence of a land right. */
|
||||
export function investmentLandPreparation(raw: unknown): LandPreparation {
|
||||
try {
|
||||
const snapshot = JSON.parse(String(raw ?? ''));
|
||||
if (snapshot.version !== 1) return { need: 'unknown', reason: '' };
|
||||
const decision = snapshot.land_preparation;
|
||||
if (decision && ['yes', 'no', 'unknown'].includes(decision.need))
|
||||
return { need: decision.need, reason: typeof decision.reason === 'string' ? decision.reason : '' };
|
||||
// Existing snapshots already carry S10 applicability; no reimport is required.
|
||||
const step = Array.isArray(snapshot.path?.steps) ? snapshot.path.steps.find((row: { code?: string } | null) => row?.code === 'S10') : null;
|
||||
return { need: step?.applicability === 'not_needed_for_preparation' ? 'no' : step?.applicability === 'applicable' ? 'yes' : 'unknown', reason: typeof step?.reason === 'string' ? step.reason : '' };
|
||||
} catch { return { need: 'unknown', reason: '' }; }
|
||||
}
|
||||
|
||||
export function landStatusVisible(draft: Record<string, unknown>): boolean {
|
||||
return !draft.context_applicability_snapshot || investmentLandPreparation(draft.context_applicability_snapshot).need === 'yes';
|
||||
}
|
||||
Reference in New Issue
Block a user