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

@@ -787,6 +787,13 @@
"not_yet_valid": "Promo code is not yet active",
"used": "Promo code has already been used",
"already_used_by_user": "You have already used this promo code",
"active_discount_exists": "You already have an active discount. Deactivate it first.",
"no_subscription_for_days": "This promo code requires an active or expired subscription",
"subscription_not_found": "Subscription not found",
"not_first_purchase": "This promo code is only available for your first purchase",
"daily_limit": "Too many promo code activations today",
"trial_subscription_exists": "You already have a subscription, so this trial code can't be applied",
"trial_provisioning_failed": "Couldn't provision the trial right now, please try again later",
"user_not_found": "User not found",
"server_error": "Server error"
},