Разработка админ-панели EventHubFrontAdmin v1.0 #1

This commit is contained in:
2026-05-23 20:43:21 +03:00
parent 36c95b71a4
commit f5961c5529
68 changed files with 10374 additions and 3 deletions
+2
View File
@@ -0,0 +1,2 @@
export const ACCESS_TOKEN_KEY = 'access_token';
export const REFRESH_TOKEN_KEY = 'refresh_token';
+48
View File
@@ -0,0 +1,48 @@
/**
* Заменяет все "некрасивые" значения в объекте или массиве на дефис.
* - null
* - "undefined" (строка)
* - undefined
* - пустая строка ""
*/
import dayjs from 'dayjs';
const isDateKey = (key: string): boolean => {
// Покрываем: _at, _date, _time, _seen, timestamp, last_login, date, time и т.д.
const datePatterns = /_(at|date|time|seen)$|^(date|time|timestamp|last_login)$/;
return datePatterns.test(key);
};
const formatDateValue = (value: unknown): string => {
if (typeof value !== 'string' || value === '-' || value === '') return value as string;
const d = dayjs(value);
if (!d.isValid()) return value;
if (value.includes('T') || value.length > 10) {
return d.format('DD.MM.YYYY HH:mm');
}
return d.format('DD.MM.YYYY');
};
export const normalizeData = <T>(data: T): T => {
if (data === null || data === undefined || data === 'undefined' || data === '') {
return '-' as unknown as T;
}
if (Array.isArray(data)) {
return data.map(item => normalizeData(item)) as unknown as T;
}
if (typeof data === 'object' && data !== null) {
const result: Record<string, any> = {};
for (const [key, value] of Object.entries(data)) {
let normalized = normalizeData(value);
if (isDateKey(key) && typeof normalized === 'string' && normalized !== '-') {
normalized = formatDateValue(normalized);
}
result[key] = normalized;
}
return result as T;
}
return data;
};