fix(miniapp): refresh billing state and clean up controls

This commit is contained in:
2026-03-12 04:27:46 +04:00
parent 9afa9fc845
commit 6e49cd1dfd
9 changed files with 166 additions and 30 deletions

View File

@@ -0,0 +1,38 @@
import type { Locale } from '../i18n'
function localeTag(locale: Locale): string {
return locale === 'ru' ? 'ru-RU' : 'en-US'
}
export function formatFriendlyDate(value: string, locale: Locale): string {
const date = new Date(value)
if (Number.isNaN(date.getTime())) {
return value
}
const includeYear = date.getUTCFullYear() !== new Date().getUTCFullYear()
return new Intl.DateTimeFormat(localeTag(locale), {
month: 'long',
day: 'numeric',
...(includeYear ? { year: 'numeric' } : {})
}).format(date)
}
export function formatCyclePeriod(period: string, locale: Locale): string {
const [yearValue, monthValue] = period.split('-')
const year = Number.parseInt(yearValue ?? '', 10)
const month = Number.parseInt(monthValue ?? '', 10)
if (!Number.isInteger(year) || !Number.isInteger(month) || month < 1 || month > 12) {
return period
}
const date = new Date(Date.UTC(year, month - 1, 1))
const includeYear = year !== new Date().getUTCFullYear()
return new Intl.DateTimeFormat(localeTag(locale), {
month: 'long',
...(includeYear ? { year: 'numeric' } : {})
}).format(date)
}