fix(promocode): correct activation UX, error mapping and validity dates

Map promocode errors by stable backend code (detail.code) instead of brittle English
substring matching, so previously-unmapped codes (active_discount_exists, daily_limit,
no_subscription_for_days, trial_*, etc.) show the right message instead of 'server error';
added the missing keys to all 4 locales.

valid_until now anchors to end-of-day in the admin's LOCAL timezone on both create AND
edit read-back, so codes no longer expire at the start of the day and editing no longer
drifts the date forward for negative-offset admins.

Allow 0-hour discount ('until first purchase'). Route user-facing discount deactivation
to the endpoint that rolls back promocode usage when the discount came from a promocode,
and parse the structured {code,message} error.
This commit is contained in:
c0mrade
2026-06-08 00:23:31 +03:00
parent 1a3236f650
commit 35428cc27d
7 changed files with 97 additions and 24 deletions

View File

@@ -816,6 +816,13 @@
"not_yet_valid": "Промокод ещё не начал действовать",
"used": "Промокод уже использован",
"already_used_by_user": "Вы уже использовали этот промокод",
"active_discount_exists": "У вас уже есть активная скидка. Сначала отключите её.",
"no_subscription_for_days": "Для этого промокода нужна активная или истёкшая подписка",
"subscription_not_found": "Подписка не найдена",
"not_first_purchase": "Промокод доступен только для первой покупки",
"daily_limit": "Слишком много активаций промокодов за сегодня",
"trial_subscription_exists": "У вас уже есть подписка, поэтому триал-промокод применить нельзя",
"trial_provisioning_failed": "Не удалось выдать триал прямо сейчас, попробуйте позже",
"user_not_found": "Пользователь не найден",
"server_error": "Ошибка сервера"
},