Enhance pricing validation and update related components
CI / Backend (build + test) (push) Successful in 1m21s
CI / Frontend (lint + typecheck + build) (push) Successful in 34s

- Added validation logic in `UpdatePricingSettingsCommandValidator` to ensure the annual price does not fall below the equivalent quarterly price, preventing potential pricing discrepancies.
- Updated `PricingSettings` model documentation to clarify that both pricing fields represent monthly rates, with calculations for total costs based on the number of months.
- Modified frontend components to reflect the new validation, including error messages when the annual price is cheaper than the quarterly price.
- Adjusted API documentation to accurately describe the pricing structure and validation rules for the pricing endpoints.
This commit is contained in:
Leonid Pershin
2026-07-18 19:56:21 +03:00
parent ae379f8e0f
commit 6dfd51ae7c
7 changed files with 70 additions and 22 deletions
@@ -19,6 +19,13 @@ export function PricingSettingsEditor({ settings }: { settings: PricingSettingsD
settings.pricePerConfigPerYear != null ? String(settings.pricePerConfigPerYear) : '',
)
// Обе ставки — цена за конфиг в месяц; итог за год (ставка×12) не должен быть дешевле итога за
// квартал (ставка×3), иначе выгоднее купить "год" и не продлевать, чем платить за квартал.
const isYearCheaperThanQuarter =
pricePerConfigPerQuarter !== '' &&
pricePerConfigPerYear !== '' &&
Number(pricePerConfigPerYear) * 12 < Number(pricePerConfigPerQuarter) * 3
const mutation = useMutation({
mutationFn: () =>
updatePricingSettings(
@@ -61,9 +68,12 @@ export function PricingSettingsEditor({ settings }: { settings: PricingSettingsD
onChange={(e) => setPricePerConfigPerYear(e.target.value)}
/>
<p className="text-xs text-muted-foreground">{t('admin.pricing.pricePerConfigPerYearHint')}</p>
{isYearCheaperThanQuarter && (
<p className="text-xs text-red-600">{t('admin.pricing.yearCheaperThanQuarter')}</p>
)}
</div>
<div>
<Button type="submit" disabled={mutation.isPending}>
<Button type="submit" disabled={mutation.isPending || isYearCheaperThanQuarter}>
{t('admin.roles.save')}
</Button>
</div>