initial commit (frontend)

This commit is contained in:
2026-09-20 15:08:32 +03:00
commit 04cc53e66d
84 changed files with 36264 additions and 0 deletions
+621
View File
@@ -0,0 +1,621 @@
import { useState, useEffect, useCallback } from 'react';
import { useLanguage } from '../i18n/LanguageContext';
import { radius } from '../styles/theme';
import { getAdminDashboard, getSentryErrors } from '../api';
import ContentEditorMenu from './ContentEditorMenu';
import WordsEditor from './WordsEditor';
import TextsEditor from './TextsEditor';
import LessonsEditor from './LessonsEditor';
import LessonEditorModal from './LessonEditorModal';
interface AdminDashboardModalProps {
isOpen: boolean;
onClose: () => void;
}
interface DashboardData {
total_users: number;
new_today: number;
online_now: number;
active_24h: number;
level_counts: Record<string, number>;
}
interface SentryError {
id: string;
short_id: string;
title: string;
culprit: string;
level: string;
count: number;
user_count: number;
first_seen: string;
last_seen: string;
permalink: string;
priority: string;
}
const AdminDashboardModal: React.FC<AdminDashboardModalProps> = ({ isOpen, onClose }) => {
const { language } = useLanguage();
const [dashboard, setDashboard] = useState<DashboardData | null>(null);
const [errors, setErrors] = useState<SentryError[]>([]);
const [errorsLoading, setErrorsLoading] = useState(false);
const [errorsError, setErrorsError] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(true);
const [lastUpdate, setLastUpdate] = useState<Date>(new Date());
// 🔧 НОВОЕ (19.09.2026): контент-менеджер
const [showContentEditor, setShowContentEditor] = useState(false);
const [showWordsEditor, setShowWordsEditor] = useState(false);
const [showTextsEditor, setShowTextsEditor] = useState(false);
const [showLessonsEditor, setShowLessonsEditor] = useState(false);
// 🔧 НОВОЕ (19.09.2026): модалка урока (WYSIWYG)
const [editingLessonId, setEditingLessonId] = useState<string | null>(null);
const [editingTopicPath, setEditingTopicPath] = useState<{
levelCode: string;
topicOrder: number;
topicName: string;
} | null>(null);
const brandColor = '#2ECC71';
const dashColor = '#E8B93F';
const errorColor = '#E74C3C';
const textColor = '#1A1A2E';
const subColor = '#6B7280';
const cardBg = 'rgba(255,255,255,0.55)';
const glass = (extra: React.CSSProperties = {}): React.CSSProperties => ({
background: cardBg,
backdropFilter: 'blur(24px) saturate(180%)',
WebkitBackdropFilter: 'blur(24px) saturate(180%)',
border: '1px solid rgba(255,255,255,0.7)',
boxShadow: '0 8px 32px rgba(31,38,73,0.10), inset 0 1px 0 rgba(255,255,255,0.85)',
...extra,
});
const getLabel = (pl: string, ru: string, uk: string, en: string): string => {
const labels: Record<string, string> = { pl, ru, uk, en };
return labels[language] || labels.en;
};
const loadData = useCallback(async () => {
setIsLoading(true);
setErrorsLoading(true);
setErrorsError(null);
getAdminDashboard()
.then((data: DashboardData) => {
setDashboard(data);
setLastUpdate(new Date());
})
.catch((e) => {
console.error('Dashboard error:', e);
})
.finally(() => setIsLoading(false));
getSentryErrors()
.then((data: any) => {
setErrors(data.errors || []);
if (data.error) {
setErrorsError(data.error);
}
})
.catch((e) => {
console.error('Sentry errors error:', e);
setErrorsError('Failed to load errors');
})
.finally(() => setErrorsLoading(false));
}, []);
useEffect(() => {
if (isOpen) {
loadData();
}
}, [isOpen, loadData]);
const formatDate = (isoStr: string): string => {
try {
const date = new Date(isoStr);
const now = new Date();
const diffMs = now.getTime() - date.getTime();
const diffMin = Math.floor(diffMs / 60000);
const diffHr = Math.floor(diffMin / 60);
const diffDay = Math.floor(diffHr / 24);
if (diffMin < 1) return getLabel('teraz', 'только что', 'щойно', 'just now');
if (diffMin < 60) return `${diffMin} ${getLabel('min temu', 'мин назад', 'хв тому', 'min ago')}`;
if (diffHr < 24) return `${diffHr} ${getLabel('godz. temu', 'ч назад', 'год тому', 'h ago')}`;
if (diffDay < 30) return `${diffDay} ${getLabel('dni temu', 'дн назад', 'дн тому', 'd ago')}`;
return date.toLocaleDateString();
} catch {
return isoStr;
}
};
const getLevelColor = (level: string): string => {
const colors: Record<string, string> = {
A1: '#2ECC71',
A2: '#27AE60',
B1: '#F39C12',
B2: '#E67E22',
C1: '#E74C3C',
C2: '#C0392B',
};
return colors[level] || brandColor;
};
const maxLevelCount = dashboard
? Math.max(...Object.values(dashboard.level_counts), 1)
: 1;
if (!isOpen) return null;
return (
<>
<div
style={{
position: 'fixed', top: 0, left: 0, right: 0, bottom: 0,
background: 'rgba(20,22,35,0.35)', zIndex: 1000,
display: 'flex', alignItems: 'center', justifyContent: 'center',
animation: 'modalFadeIn 0.2s ease', padding: '20px',
backdropFilter: 'blur(6px)', WebkitBackdropFilter: 'blur(6px)',
}}
onClick={(e) => { if (e.target === e.currentTarget) onClose(); }}
>
<style>{`
@keyframes modalFadeIn {
0% { opacity: 0; }
100% { opacity: 1; }
}
@keyframes modalSlideUp {
0% { transform: translateY(20px); opacity: 0; }
100% { transform: translateY(0); opacity: 1; }
}
@keyframes fadeInUp {
0% { transform: translateY(8px); opacity: 0; }
100% { transform: translateY(0); opacity: 1; }
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
`}</style>
<div
style={{
...glass({
borderRadius: radius.lg,
padding: '20px',
width: '100%',
maxWidth: '440px',
maxHeight: '90vh',
overflowY: 'auto',
boxShadow: '0 24px 60px rgba(31,38,73,0.25), inset 0 1px 0 rgba(255,255,255,0.85)',
}),
animation: 'modalSlideUp 0.3s ease',
}}
onClick={(e) => e.stopPropagation()}
>
{/* Заголовок */}
<div style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
marginBottom: '16px',
paddingBottom: '12px',
borderBottom: '1px solid rgba(0,0,0,0.06)',
}}>
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
<span style={{ fontSize: '24px' }}>📊</span>
<h3 style={{
margin: 0,
fontSize: '18px',
fontWeight: 800,
color: textColor,
}}>
{getLabel('Panel admina', 'Админ-панель', 'Адмін-панель', 'Admin Panel')}
</h3>
</div>
<div style={{ display: 'flex', gap: '6px' }}>
<button
onClick={loadData}
disabled={isLoading}
style={{
...glass({ padding: '8px 12px', borderRadius: radius.sm }),
color: textColor,
fontSize: '14px',
cursor: isLoading ? 'wait' : 'pointer',
opacity: isLoading ? 0.5 : 1,
animation: isLoading ? 'pulse 1s ease infinite' : 'none',
}}
>
🔄
</button>
<button
onClick={onClose}
style={{
...glass({ padding: '8px 14px', borderRadius: radius.sm }),
color: textColor,
fontSize: '14px',
fontWeight: 600,
cursor: 'pointer',
}}
>
✕
</button>
</div>
</div>
{isLoading && !dashboard ? (
<div style={{
textAlign: 'center',
padding: '40px 20px',
color: subColor,
fontSize: '14px',
}}>
{getLabel('Ładowanie...', 'Загрузка...', 'Завантаження...', 'Loading...')}
</div>
) : (
<>
{/* 🔧 НОВОЕ (19.09.2026): кнопка Контент-менеджер — сверху, зелёная */}
<div style={{ marginBottom: '20px' }}>
<button
onClick={() => setShowContentEditor(true)}
style={{
width: '100%',
padding: '14px 16px',
borderRadius: radius.md,
border: 'none',
background: brandColor,
color: '#FFFFFF',
fontSize: '14px',
fontWeight: 800,
cursor: 'pointer',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
gap: '8px',
transition: 'all 0.2s ease',
boxShadow: `0 4px 12px ${brandColor}40`,
}}
>
✏️ {getLabel('Edytor treści', 'Контент-менеджер', 'Контент-менеджер', 'Content Editor')}
</button>
</div>
{/* ============ СЕКЦИЯ 1: СТАТИСТИКА ============ */}
<div style={{ marginBottom: '20px' }}>
<div style={{
fontSize: '12px',
fontWeight: 700,
color: dashColor,
marginBottom: '10px',
letterSpacing: '0.5px',
textTransform: 'uppercase',
}}>
👥 {getLabel('Statystyki', 'Статистика', 'Статистика', 'Statistics')}
</div>
<div style={{
display: 'grid',
gridTemplateColumns: '1fr 1fr',
gap: '8px',
}}>
<div style={{
...glass({ padding: '14px', borderRadius: radius.md }),
border: `1px solid ${brandColor}30`,
}}>
<div style={{ fontSize: '11px', color: subColor, marginBottom: '4px', fontWeight: 600 }}>
{getLabel('Wszyscy', 'Всего', 'Всього', 'Total')}
</div>
<div style={{ fontSize: '26px', fontWeight: 900, color: textColor, lineHeight: 1 }}>
{dashboard?.total_users ?? 0}
</div>
</div>
<div style={{
...glass({ padding: '14px', borderRadius: radius.md }),
border: `1px solid ${brandColor}30`,
}}>
<div style={{ fontSize: '11px', color: subColor, marginBottom: '4px', fontWeight: 600 }}>
🆕 {getLabel('Nowi dziś', 'Новых сегодня', 'Нових сьогодні', 'New today')}
</div>
<div style={{ fontSize: '26px', fontWeight: 900, color: dashboard?.new_today ? brandColor : textColor, lineHeight: 1 }}>
{dashboard?.new_today ?? 0}
</div>
</div>
<div style={{
...glass({ padding: '14px', borderRadius: radius.md }),
border: `1px solid ${brandColor}30`,
}}>
<div style={{ fontSize: '11px', color: subColor, marginBottom: '4px', fontWeight: 600 }}>
🟢 {getLabel('Online', 'Онлайн', 'Онлайн', 'Online')}
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: '6px' }}>
<div style={{
width: '8px',
height: '8px',
borderRadius: '50%',
background: dashboard?.online_now ? '#2ECC71' : '#BDBDBD',
boxShadow: dashboard?.online_now ? '0 0 8px #2ECC71' : 'none',
}} />
<div style={{ fontSize: '26px', fontWeight: 900, color: textColor, lineHeight: 1 }}>
{dashboard?.online_now ?? 0}
</div>
</div>
</div>
<div style={{
...glass({ padding: '14px', borderRadius: radius.md }),
border: `1px solid ${brandColor}30`,
}}>
<div style={{ fontSize: '11px', color: subColor, marginBottom: '4px', fontWeight: 600 }}>
📈 {getLabel('Aktywni 24h', 'Активных 24ч', 'Активних 24г', 'Active 24h')}
</div>
<div style={{ fontSize: '26px', fontWeight: 900, color: textColor, lineHeight: 1 }}>
{dashboard?.active_24h ?? 0}
</div>
</div>
</div>
</div>
{/* ============ СЕКЦИЯ 2: ПО УРОВНЯМ ============ */}
<div style={{ marginBottom: '20px' }}>
<div style={{
fontSize: '12px',
fontWeight: 700,
color: dashColor,
marginBottom: '10px',
letterSpacing: '0.5px',
textTransform: 'uppercase',
}}>
🎯 {getLabel('Poziomy', 'Уровни', 'Рівні', 'Levels')}
</div>
<div style={{
...glass({ padding: '14px', borderRadius: radius.md }),
}}>
{dashboard && Object.entries(dashboard.level_counts).map(([level, count]) => {
const percent = count > 0 ? (count / maxLevelCount) * 100 : 0;
return (
<div key={level} style={{ marginBottom: '10px' }}>
<div style={{
display: 'flex',
justifyContent: 'space-between',
marginBottom: '4px',
fontSize: '12px',
fontWeight: 600,
}}>
<span style={{ color: getLevelColor(level) }}>{level}</span>
<span style={{ color: count > 0 ? textColor : subColor }}>{count}</span>
</div>
<div style={{
width: '100%',
height: '6px',
background: 'rgba(0,0,0,0.05)',
borderRadius: '3px',
overflow: 'hidden',
}}>
<div style={{
width: `${percent}%`,
height: '100%',
background: getLevelColor(level),
borderRadius: '3px',
transition: 'width 0.5s ease',
}} />
</div>
</div>
);
})}
</div>
</div>
{/* ============ СЕКЦИЯ 3: ОШИБКИ SENTRY ============ */}
<div>
<div style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: '10px',
}}>
<div style={{
fontSize: '12px',
fontWeight: 700,
color: errors.length > 0 ? errorColor : dashColor,
letterSpacing: '0.5px',
textTransform: 'uppercase',
}}>
⚠️ {getLabel('Błędy', 'Ошибки', 'Помилки', 'Errors')} ({errors.length})
</div>
<a
href="https://drobysh.sentry.io/issues/?project=4512063274090576"
target="_blank"
rel="noopener noreferrer"
style={{
fontSize: '11px',
color: dashColor,
textDecoration: 'none',
fontWeight: 600,
}}
>
{getLabel('Otwórz Sentry', 'Открыть Sentry', 'Відкрити Sentry', 'Open Sentry')} ↗
</a>
</div>
{errorsLoading ? (
<div style={{
...glass({ padding: '20px', borderRadius: radius.md }),
textAlign: 'center',
color: subColor,
fontSize: '13px',
}}>
{getLabel('Ładowanie...', 'Загрузка...', 'Завантаження...', 'Loading...')}
</div>
) : errorsError ? (
<div style={{
...glass({ padding: '16px', borderRadius: radius.md }),
background: `${errorColor}10`,
border: `1px solid ${errorColor}30`,
color: errorColor,
fontSize: '12px',
textAlign: 'center',
}}>
{errorsError}
</div>
) : errors.length === 0 ? (
<div style={{
...glass({ padding: '20px', borderRadius: radius.md }),
background: `${brandColor}10`,
border: `1px solid ${brandColor}30`,
textAlign: 'center',
color: brandColor,
fontSize: '13px',
fontWeight: 600,
}}>
✅ {getLabel('Brak błędów', 'Ошибок нет', 'Помилок немає', 'No errors')}
</div>
) : (
<div style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
{errors.slice(0, 5).map((err, index) => (
<a
key={err.id}
href={err.permalink}
target="_blank"
rel="noopener noreferrer"
style={{
...glass({
padding: '12px 14px',
borderRadius: radius.md,
textDecoration: 'none',
display: 'block',
}),
border: `1px solid ${errorColor}30`,
background: `${errorColor}08`,
animation: `fadeInUp 0.3s ease ${index * 0.05}s both`,
}}
>
<div style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'flex-start',
gap: '8px',
marginBottom: '4px',
}}>
<div style={{
fontSize: '13px',
fontWeight: 700,
color: textColor,
flex: 1,
wordBreak: 'break-word',
}}>
{err.title}
</div>
<span style={{
fontSize: '10px',
padding: '2px 6px',
background: errorColor,
color: '#FFFFFF',
borderRadius: '8px',
fontWeight: 700,
flexShrink: 0,
}}>
{err.count}×
</span>
</div>
<div style={{
fontSize: '11px',
color: subColor,
display: 'flex',
gap: '8px',
flexWrap: 'wrap',
}}>
<span>🕐 {formatDate(err.last_seen)}</span>
{err.user_count > 0 && (
<span>👤 {err.user_count}</span>
)}
<span>📍 {err.culprit}</span>
</div>
</a>
))}
</div>
)}
</div>
{/* Футер */}
<div style={{
marginTop: '16px',
paddingTop: '12px',
borderTop: '1px solid rgba(0,0,0,0.06)',
textAlign: 'center',
fontSize: '11px',
color: subColor,
}}>
{getLabel('Aktualizacja', 'Обновлено', 'Оновлено', 'Updated')}: {lastUpdate.toLocaleTimeString()}
</div>
</>
)}
</div>
</div>
{/* 🔧 НОВОЕ (19.09.2026): модалка контент-менеджера */}
<ContentEditorMenu
isOpen={showContentEditor}
onClose={() => setShowContentEditor(false)}
onNavigate={(section) => {
setShowContentEditor(false);
if (section === 'words') {
setShowWordsEditor(true);
} else if (section === 'texts') {
setShowTextsEditor(true);
} else if (section === 'lessons') {
setShowLessonsEditor(true);
}
}}
/>
<WordsEditor
isOpen={showWordsEditor}
onClose={() => setShowWordsEditor(false)}
/>
<TextsEditor
isOpen={showTextsEditor}
onClose={() => setShowTextsEditor(false)}
/>
{/* 🔧 НОВОЕ (19.09.2026): Уроки — иерархия */}
<LessonsEditor
isOpen={showLessonsEditor}
onClose={() => {
setShowLessonsEditor(false);
setEditingLessonId(null);
setEditingTopicPath(null);
}}
onOpenLesson={(lessonId, topicPath) => {
setEditingLessonId(lessonId);
setEditingTopicPath(topicPath);
}}
/>
{/* 🔧 НОВОЕ (19.09.2026): WYSIWYG-модалка урока */}
<LessonEditorModal
isOpen={!!editingLessonId}
lessonId={editingLessonId}
topicPath={editingTopicPath}
onClose={() => {
setEditingLessonId(null);
setEditingTopicPath(null);
}}
onSaved={() => {
setEditingLessonId(null);
setEditingTopicPath(null);
}}
/>
</>
);
};
export default AdminDashboardModal;