Enhance pricing validation and update related components
- 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:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user