7aca927937
- Password Complexity: Added 4-level complexity selector (Simple/Moderate/Strong/Very Strong) in admin security settings with dynamic backend validation - Gallery Security: Removed event date from login page (security risk), replaced with event type badge - Analytics Config: Fixed "Not Configured" detection logic to check both admin settings and env variables - Analytics Accuracy: Aligned calculation logic between dashboard and analytics endpoints, added totals verification - Translations: Added missing activity keys (analytics_settings_updated, cms_page_updated, security_settings_updated, password_reset, admin_logout, system_activity) - UI Fixes: Fixed German text overflow in CMS page selector with proper CSS truncation - Date Format: Event creation now respects admin-configured date format instead of browser locale - Chrome Compatibility: Replaced emoji flags with SVG components for Windows Chrome support All changes maintain backward compatibility and production stability. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
import { useTranslation } from 'react-i18next';
|
|
import { format as dateFnsFormat, formatDistanceToNow as dateFnsFormatDistanceToNow } from 'date-fns';
|
|
import { de, enUS } from 'date-fns/locale';
|
|
import { useQuery } from '@tanstack/react-query';
|
|
import { settingsService } from '../services/settings.service';
|
|
|
|
export const useLocalizedDate = () => {
|
|
const { i18n } = useTranslation();
|
|
|
|
// Fetch admin settings to get the date format
|
|
const { data: settings } = useQuery({
|
|
queryKey: ['admin-settings-general'],
|
|
queryFn: () => settingsService.getSettingsByType('general'),
|
|
staleTime: 5 * 60 * 1000, // Cache for 5 minutes
|
|
});
|
|
|
|
const getLocale = () => {
|
|
return i18n.language === 'de' ? de : enUS;
|
|
};
|
|
|
|
const format = (date: Date | string, formatStr?: string) => {
|
|
const dateObj = typeof date === 'string' ? new Date(date) : date;
|
|
// Use admin-configured date format if available and no format string provided
|
|
const dateFormat = formatStr || settings?.general_date_format || 'PPP';
|
|
return dateFnsFormat(dateObj, dateFormat, { locale: getLocale() });
|
|
};
|
|
|
|
const formatDistanceToNow = (date: Date | string, options?: { addSuffix?: boolean }) => {
|
|
const dateObj = typeof date === 'string' ? new Date(date) : date;
|
|
return dateFnsFormatDistanceToNow(dateObj, { ...options, locale: getLocale() });
|
|
};
|
|
|
|
return {
|
|
format,
|
|
formatDistanceToNow,
|
|
locale: getLocale(),
|
|
dateFormat: settings?.general_date_format || 'PPP'
|
|
};
|
|
}; |