function validateChoice()

in client/components/mma/accountoverview/updateAmount/SupporterPlusUpdateAmountForm.tsx [70:101]


function validateChoice(
	currentAmount: number,
	chosenAmount: number | null,
	minAmount: number,
	maxAmount: number,
	isOtherAmountSelected: boolean,
	mainPlan: PaidSubscriptionPlan,
): string | null {
	const chosenOptionNum = Number(chosenAmount);
	const monthlyOrAnnual = getBillingPeriodAdjective(
		mainPlan.billingPeriod,
	).toLocaleLowerCase();

	if (!chosenAmount && !isOtherAmountSelected) {
		return 'Please make a selection';
	} else if (chosenOptionNum === currentAmount) {
		return 'You have selected the same amount as you currently pay';
	} else if (!chosenAmount || isNaN(chosenOptionNum)) {
		return 'There is a problem with the amount you have selected, please make sure it is a valid amount';
	} else if (!isNaN(chosenOptionNum) && chosenOptionNum < minAmount) {
		return `${mainPlan.currency}${minAmount} per ${
			mainPlan.billingPeriod
		} is the ${
			currentAmount < minAmount ? 'new ' : ''
		}minimum payment to receive this subscription. Please call our customer service team to lower your ${monthlyOrAnnual} amount below ${
			mainPlan.currency
		}${minAmount} via the Help Centre`;
	} else if (!isNaN(chosenOptionNum) && chosenOptionNum > maxAmount) {
		return `There is a maximum ${mainPlan.billingPeriod}ly amount of ${mainPlan.currency}${maxAmount} ${mainPlan.currencyISO}`;
	}
	return null;
}