init
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { authApi, familyApi } from '../api/client';
|
||||
import { useStore } from '../store/useStore';
|
||||
import {
|
||||
@@ -14,6 +15,7 @@ import {
|
||||
} from 'lucide-react';
|
||||
|
||||
export default function AdminPanel() {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const { user, logout: storeLogout } = useStore();
|
||||
|
||||
@@ -46,7 +48,7 @@ export default function AdminPanel() {
|
||||
|
||||
const handleCreateFamily = async () => {
|
||||
if (!newFamilyName.trim() || !newFamilyPassword.trim()) {
|
||||
alert('Заполните название и пароль семьи');
|
||||
alert(t('admin.fillNameAndPassword'));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -56,19 +58,19 @@ export default function AdminPanel() {
|
||||
setNewFamilyPassword('');
|
||||
loadFamilies();
|
||||
} catch (err) {
|
||||
alert('Ошибка создания семьи');
|
||||
alert(t('admin.createError'));
|
||||
console.error(err);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDeleteFamily = async (id: number) => {
|
||||
if (!confirm('Удалить семью?')) return;
|
||||
if (!confirm(t('admin.deleteConfirm'))) return;
|
||||
|
||||
try {
|
||||
await familyApi.delete(id);
|
||||
loadFamilies();
|
||||
} catch (err) {
|
||||
alert('Ошибка удаления семьи');
|
||||
alert(t('admin.deleteError'));
|
||||
console.error(err);
|
||||
}
|
||||
};
|
||||
@@ -84,17 +86,17 @@ export default function AdminPanel() {
|
||||
</div>
|
||||
</div>
|
||||
<h1 className="text-2xl sm:text-3xl font-bold text-gray-900 mb-2">
|
||||
Доступ запрещен
|
||||
{t('admin.accessDenied')}
|
||||
</h1>
|
||||
<p className="text-gray-600 mb-6 text-sm sm:text-base">
|
||||
Требуются права администратора
|
||||
{t('admin.requiresAdmin')}
|
||||
</p>
|
||||
<button
|
||||
onClick={() => navigate('/')}
|
||||
className="w-full flex items-center justify-center gap-2 px-4 py-3 bg-gray-200 hover:bg-gray-300 text-gray-700 rounded-xl transition-all duration-300 font-medium"
|
||||
>
|
||||
<ArrowLeft className="w-5 h-5" />
|
||||
Назад
|
||||
{t('common.back')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -110,10 +112,10 @@ export default function AdminPanel() {
|
||||
<Shield className="w-12 h-12 text-white" />
|
||||
</div>
|
||||
<h1 className="text-4xl sm:text-5xl font-bold text-white mb-2">
|
||||
Админ панель
|
||||
{t('admin.title')}
|
||||
</h1>
|
||||
<p className="text-purple-100 text-base sm:text-lg mb-6">
|
||||
Управление семьями
|
||||
{t('admin.subtitle')}
|
||||
</p>
|
||||
<div className="flex justify-center gap-3">
|
||||
<button
|
||||
@@ -121,14 +123,14 @@ export default function AdminPanel() {
|
||||
className="inline-flex items-center gap-2 px-5 py-3 bg-red-500/80 hover:bg-red-600 text-white rounded-2xl backdrop-blur-md transition-all duration-300 hover:shadow-lg font-medium"
|
||||
>
|
||||
<LogOut className="w-5 h-5" />
|
||||
Выход
|
||||
{t('common.exit')}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => navigate('/')}
|
||||
className="inline-flex items-center gap-2 px-5 py-3 bg-white/20 hover:bg-white/30 text-white rounded-2xl backdrop-blur-md transition-all duration-300 hover:shadow-lg font-medium"
|
||||
>
|
||||
<Home className="w-5 h-5" />
|
||||
На главную
|
||||
{t('common.toHome')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -139,7 +141,7 @@ export default function AdminPanel() {
|
||||
<Plus className="w-8 h-8 text-white" />
|
||||
</div>
|
||||
<h2 className="text-2xl sm:text-3xl font-bold text-gray-800">
|
||||
Создать новую семью
|
||||
{t('admin.createFamily')}
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
@@ -147,11 +149,11 @@ export default function AdminPanel() {
|
||||
<div>
|
||||
<label className="flex items-center justify-center gap-2 text-sm font-semibold text-gray-700 mb-3">
|
||||
<Users className="w-5 h-5 text-purple-600" />
|
||||
Название семьи
|
||||
{t('admin.familyName')}
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Например: Семья Ивановых"
|
||||
placeholder={t('admin.familyNamePlaceholder')}
|
||||
value={newFamilyName}
|
||||
onChange={(e) => setNewFamilyName(e.target.value)}
|
||||
className="w-full px-5 py-4 border-2 border-gray-300 rounded-2xl focus:ring-2 focus:ring-purple-500 focus:border-purple-500 transition-all font-medium text-center"
|
||||
@@ -160,11 +162,11 @@ export default function AdminPanel() {
|
||||
<div>
|
||||
<label className="flex items-center justify-center gap-2 text-sm font-semibold text-gray-700 mb-3">
|
||||
<Lock className="w-5 h-5 text-purple-600" />
|
||||
Пароль семьи
|
||||
{t('admin.familyPassword')}
|
||||
</label>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="Защитите семью паролем"
|
||||
placeholder={t('admin.familyPasswordPlaceholder')}
|
||||
value={newFamilyPassword}
|
||||
onChange={(e) => setNewFamilyPassword(e.target.value)}
|
||||
className="w-full px-5 py-4 border-2 border-gray-300 rounded-2xl focus:ring-2 focus:ring-purple-500 focus:border-purple-500 transition-all font-medium text-center"
|
||||
@@ -175,7 +177,7 @@ export default function AdminPanel() {
|
||||
className="w-full flex items-center justify-center gap-2 px-6 py-4 bg-linear-to-r from-green-500 to-green-600 text-white rounded-2xl hover:shadow-xl transition-all duration-300 font-semibold text-lg"
|
||||
>
|
||||
<Plus className="w-6 h-6" />
|
||||
Создать семью
|
||||
{t('admin.createButton')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -186,7 +188,7 @@ export default function AdminPanel() {
|
||||
<Users className="w-8 h-8 text-white" />
|
||||
</div>
|
||||
<h2 className="text-2xl sm:text-3xl font-bold text-gray-800">
|
||||
Список семей
|
||||
{t('admin.familyList')}
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
@@ -196,10 +198,10 @@ export default function AdminPanel() {
|
||||
<Users className="w-20 h-20 text-purple-400" />
|
||||
</div>
|
||||
<p className="text-gray-600 text-lg sm:text-xl mb-2 font-semibold">
|
||||
Семьи не найдены
|
||||
{t('admin.noFamilies')}
|
||||
</p>
|
||||
<p className="text-gray-500 text-sm sm:text-base">
|
||||
Создайте первую семью
|
||||
{t('admin.createFirst')}
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
@@ -222,7 +224,7 @@ export default function AdminPanel() {
|
||||
className="w-full sm:w-auto flex items-center justify-center gap-2 px-5 py-3 bg-red-500 hover:bg-red-600 text-white rounded-xl transition-all font-semibold shadow-md hover:shadow-lg"
|
||||
>
|
||||
<Trash2 className="w-5 h-5" />
|
||||
Удалить
|
||||
{t('common.delete')}
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
|
||||
Reference in New Issue
Block a user