diff --git a/src/client/components/ResultPage/TotalRisk.tsx b/src/client/components/ResultPage/TotalRisk.tsx index e59c341..cfef64d 100644 --- a/src/client/components/ResultPage/TotalRisk.tsx +++ b/src/client/components/ResultPage/TotalRisk.tsx @@ -56,7 +56,7 @@ const TotalRisk = ({ { id: 'country', text: t('risks:countryRiskLevel'), - riskLevel: countryRisk(country), + riskLevel: countryRisk({ country, resultData }), }, { id: 'university', diff --git a/src/client/util/risks.ts b/src/client/util/risks.ts index 6636cb2..1e823e8 100644 --- a/src/client/util/risks.ts +++ b/src/client/util/risks.ts @@ -1,6 +1,12 @@ -import { CountryData } from '@frontend/types' - -export const countryRisk = (country: CountryData | undefined) => { +import { CountryData, FormValues } from '@frontend/types' + +export const countryRisk = ({ + country, + resultData, +}: { + country: CountryData | undefined + resultData: FormValues +}) => { if (!country) return null const { code, universities, safetyLevel, ...riskValues } = country @@ -13,11 +19,15 @@ export const countryRisk = (country: CountryData | undefined) => { ['Poistu välittömästi maasta', 3], ] + const sanctionsRisk = country.sanctions ? 2 : 1 + const sanctionsMultiplier = + sanctionsRisk === 2 && resultData['11'].research ? 1.5 : 1 + const safetyLevelRisk = safetyLevels.find((level) => level[0] === safetyLevel)?.[1] || null const filteredRiskValues = Object.values(riskValues) - .concat(safetyLevelRisk as number) + .concat(safetyLevelRisk as number, sanctionsRisk * sanctionsMultiplier) .filter((value) => value != null && typeof value === 'number') const totalCountryRiskLevel = Math.round(