fix(admin): UX Control Center — даты Inbox, bulk, фильтры событий, палитра по ID
CI / test (push) Successful in 1m52s
CI / push-image (push) Successful in 6m57s
CI / ci-done (push) Successful in 0s

Refs EventHub/EventHubFrontAdmin#32

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-14 20:53:58 +03:00
parent 3251c76478
commit b7d572ea8e
17 changed files with 398 additions and 105 deletions
+52
View File
@@ -0,0 +1,52 @@
import dayjs from 'dayjs';
import i18n from '@/i18n';
/**
* Formats dates for UI. Tolerates ISO and values already shaped by normalizeData
* (`DD.MM.YYYY HH:mm`), so dayjs().format() is not applied twice.
*/
export function formatDateTime(
value: string | null | undefined,
pattern: 'DD.MM.YYYY HH:mm' | 'DD.MM HH:mm' = 'DD.MM.YYYY HH:mm'
): string {
if (!value || value === '-') return '-';
const localized = value.match(/^(\d{2})\.(\d{2})\.(\d{4})(?:\s+(\d{2}):(\d{2}))?/);
if (localized) {
const [, dd, mm, yyyy, hh, min] = localized;
if (pattern === 'DD.MM HH:mm') {
return hh != null ? `${dd}.${mm} ${hh}:${min}` : `${dd}.${mm}`;
}
return hh != null ? `${dd}.${mm}.${yyyy} ${hh}:${min}` : `${dd}.${mm}.${yyyy}`;
}
const d = dayjs(value);
if (!d.isValid()) return value;
return d.format(pattern);
}
/** Relative age for inbox queues (works with ISO or normalizeData-local strings). */
export function formatRelativeAge(value: string | null | undefined): string {
if (!value || value === '-') return '-';
let d = dayjs(value);
if (!d.isValid()) {
const m = value.match(/^(\d{2})\.(\d{2})\.(\d{4})(?:\s+(\d{2}):(\d{2}))?/);
if (m) {
const [, dd, mm, yyyy, hh = '00', min = '00'] = m;
d = dayjs(`${yyyy}-${mm}-${dd}T${hh}:${min}:00`);
}
}
if (!d.isValid()) return formatDateTime(value, 'DD.MM HH:mm');
const now = dayjs();
const mins = now.diff(d, 'minute');
if (mins < 1) return i18n.t('common.ageJustNow');
if (mins < 60) return i18n.t('common.ageMinutes', { count: mins });
const hours = now.diff(d, 'hour');
if (hours < 24) return i18n.t('common.ageHours', { count: hours });
const days = now.diff(d, 'day');
if (days === 1) return i18n.t('common.ageYesterday');
if (days < 7) return i18n.t('common.ageDays', { count: days });
return formatDateTime(value, 'DD.MM HH:mm');
}