This commit is contained in:
root 2026-02-23 15:44:27 +03:00
parent d9121fe6ef
commit 9382eab7b2
35 changed files with 3967 additions and 3612 deletions

View File

@ -479,6 +479,106 @@ def send_telegram_notification(notification):
raise
def _format_lesson_datetime_ru(dt, user_timezone='UTC'):
"""Форматирует дату/время для русского языка: «23 февраля 2026, 14:30»."""
if dt is None:
return ''
from apps.users.utils import convert_to_user_timezone
local_dt = convert_to_user_timezone(dt, user_timezone)
months_ru = (
'января', 'февраля', 'марта', 'апреля', 'мая', 'июня',
'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'
)
day = local_dt.day
month = months_ru[local_dt.month - 1]
year = local_dt.year
time_str = local_dt.strftime('%H:%M')
return f'{day} {month} {year}, {time_str}'
@shared_task
def send_lesson_completion_confirmation_telegram(lesson_id):
"""
Отправить ментору в Telegram сообщение о завершённом по времени занятии
с кнопками «Занятие состоялось» / «Занятие отменилось».
Вызывается при авто-завершении занятия Celery-задачей.
"""
import asyncio
from apps.schedule.models import Lesson
from apps.video.models import VideoRoom
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from .telegram_bot import send_telegram_message_with_buttons
try:
lesson = Lesson.objects.select_related('mentor', 'client', 'client__user').get(id=lesson_id)
except Lesson.DoesNotExist:
logger.warning(f'Lesson {lesson_id} not found for completion confirmation')
return
mentor = lesson.mentor
if not mentor or not mentor.telegram_id:
return
tz = mentor.timezone or 'UTC'
student_name = ''
if lesson.client and lesson.client.user:
student_name = lesson.client.user.get_full_name() or lesson.client.user.email or 'Ученик'
else:
student_name = 'Ученик'
start_str = _format_lesson_datetime_ru(lesson.start_time, tz)
end_str = _format_lesson_datetime_ru(lesson.end_time, tz)
# Подключения: из Lesson или VideoRoom
mentor_connected = lesson.mentor_connected_at is not None
client_connected = lesson.client_connected_at is not None
if not mentor_connected and not client_connected:
try:
vr = VideoRoom.objects.filter(lesson=lesson).first()
if vr:
mentor_connected = vr.mentor_joined_at is not None
client_connected = vr.client_joined_at is not None
except Exception:
pass
mentor_status = '✅ Подключился' if mentor_connected else 'Не подключался'
client_status = '✅ Подключился' if client_connected else 'Не подключался'
message = (
f"⏱ <b>Занятие завершилось по времени</b>\n\n"
f"📚 <b>{lesson.title}</b>\n"
f"👤 {student_name}\n\n"
f"🕐 <b>Время:</b> {start_str}{end_str}\n\n"
f"📡 <b>Подключения:</b>\n"
f" • Ментор: {mentor_status}\n"
f" • Ученик: {client_status}\n\n"
f"Подтвердите, пожалуйста:"
)
keyboard = [
[
InlineKeyboardButton("✅ Занятие состоялось", callback_data=f"lesson_confirm_{lesson_id}"),
InlineKeyboardButton("❌ Занятие отменилось", callback_data=f"lesson_cancel_{lesson_id}"),
]
]
reply_markup = InlineKeyboardMarkup(keyboard)
try:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
success = loop.run_until_complete(
send_telegram_message_with_buttons(
mentor.telegram_id, message, reply_markup, parse_mode='HTML'
)
)
loop.close()
if success:
logger.info(f'Lesson {lesson_id} completion confirmation sent to mentor {mentor.id}')
except Exception as e:
logger.error(f'Error sending lesson completion confirmation to mentor: {e}', exc_info=True)
@shared_task
def send_bulk_notifications(notification_ids):
"""

View File

@ -1611,6 +1611,50 @@ class TelegramBot:
await query.answer("❌ Ошибка", show_alert=True)
return
# Обработка подтверждения занятия (Занятие состоялось / Занятие отменилось)
if query.data.startswith('lesson_confirm_') or query.data.startswith('lesson_cancel_'):
try:
lesson_id = int(query.data.split('_')[-1])
is_confirmed = query.data.startswith('lesson_confirm_')
from apps.schedule.models import Lesson
from django.utils import timezone
lesson = await sync_to_async(
Lesson.objects.select_related('client', 'client__user', 'mentor').get
)(id=lesson_id)
user = update.effective_user
telegram_id = user.id
# Только ментор может подтверждать
if not lesson.mentor or lesson.mentor.telegram_id != telegram_id:
await query.answer("❌ Только ментор занятия может подтвердить.", show_alert=True)
return
if is_confirmed:
# Занятие состоялось — оставляем completed
await query.edit_message_text(
f"✅ <b>Подтверждено</b>\n\n"
f"Занятие «{lesson.title}» состоялось."
)
else:
# Занятие отменилось — меняем статус
lesson.status = 'cancelled'
lesson.cancelled_at = timezone.now()
await sync_to_async(lesson.save)(update_fields=['status', 'cancelled_at'])
await query.edit_message_text(
f"❌ <b>Отменено</b>\n\n"
f"Занятие «{lesson.title}» отмечено как отменённое."
)
await query.answer()
except Lesson.DoesNotExist:
await query.answer("❌ Занятие не найдено", show_alert=True)
except Exception as e:
logger.error(f"Error handling lesson confirmation: {e}", exc_info=True)
await query.answer("❌ Ошибка обработки", show_alert=True)
return
# Обработка подтверждения присутствия
if query.data.startswith('attendance_yes_') or query.data.startswith('attendance_no_'):
try:

View File

@ -0,0 +1,32 @@
# Generated manually
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("schedule", "0010_lesson_livekit_access_token_lesson_livekit_room_name_and_more"),
]
operations = [
migrations.AddField(
model_name="lesson",
name="mentor_connected_at",
field=models.DateTimeField(
blank=True,
help_text="Время подключения ментора к видеокомнате",
null=True,
verbose_name="Ментор подключился",
),
),
migrations.AddField(
model_name="lesson",
name="client_connected_at",
field=models.DateTimeField(
blank=True,
help_text="Время подключения студента к видеокомнате",
null=True,
verbose_name="Студент подключился",
),
),
]

View File

@ -364,6 +364,20 @@ class Lesson(models.Model):
# verbose_name='Время отправки напоминания'
# )
# Метрики подключения к видеокомнате (заполняются при подключении ментора/студента)
mentor_connected_at = models.DateTimeField(
null=True,
blank=True,
verbose_name='Ментор подключился',
help_text='Время подключения ментора к видеокомнате'
)
client_connected_at = models.DateTimeField(
null=True,
blank=True,
verbose_name='Студент подключился',
help_text='Время подключения студента к видеокомнате'
)
# Фактическое время завершения (если занятие завершено досрочно)
completed_at = models.DateTimeField(
null=True,

View File

@ -102,7 +102,7 @@ class LessonSerializer(serializers.ModelSerializer):
'livekit_room_name'
]
read_only_fields = [
'id', 'end_time', 'status', 'reminder_sent',
'id', 'end_time', 'reminder_sent',
'created_at', 'updated_at', 'livekit_room_name'
]
@ -114,6 +114,16 @@ class LessonSerializer(serializers.ModelSerializer):
def validate(self, attrs):
"""Валидация данных занятия."""
# Для завершённых занятий разрешаем менять только price и status
if self.instance and self.instance.status == 'completed':
allowed = {'price', 'status'}
attrs = {k: v for k, v in attrs.items() if k in allowed}
if 'status' in attrs and attrs['status'] not in ('completed', 'cancelled'):
raise serializers.ValidationError({
'status': 'Для завершённого занятия можно только оставить "Завершено" или пометить как "Отменено"'
})
return attrs
# Нормализуем meeting_url - пустая строка становится None
if 'meeting_url' in attrs and attrs['meeting_url'] == '':
attrs['meeting_url'] = None
@ -121,10 +131,12 @@ class LessonSerializer(serializers.ModelSerializer):
start_time = attrs.get('start_time')
duration = attrs.get('duration', 60)
# Проверка что занятие в будущем
if start_time and start_time <= timezone.now():
# Проверка: допускаем создание занятий до 30 минут в прошлом
now = timezone.now()
tolerance = timedelta(minutes=30)
if start_time and start_time < now - tolerance:
raise serializers.ValidationError({
'start_time': 'Занятие должно быть запланировано в будущем'
'start_time': 'Нельзя создать занятие, время начала которого было более 30 минут назад'
})
# Проверка конфликтов (только при создании или изменении времени)
@ -368,8 +380,7 @@ class LessonCreateSerializer(serializers.ModelSerializer):
attrs['mentor_subject'] = mentor_subject
attrs['subject_name'] = mentor_subject.name
# Проверка что занятие в будущем
# Убеждаемся, что start_time в UTC и aware
# Проверка: допускаем создание занятий до 30 минут в прошлом
if start_time:
if not django_timezone.is_aware(start_time):
start_time = pytz.UTC.localize(start_time)
@ -377,9 +388,10 @@ class LessonCreateSerializer(serializers.ModelSerializer):
start_time = start_time.astimezone(pytz.UTC)
now = django_timezone.now()
if start_time <= now:
tolerance = timedelta(minutes=30)
if start_time < now - tolerance:
raise serializers.ValidationError({
'start_time': f'Занятие должно быть запланировано в будущем. Текущее время: {now.isoformat()}, указанное время: {start_time.isoformat()}'
'start_time': 'Нельзя создать занятие, время начала которого было более 30 минут назад'
})
# Рассчитываем время окончания

View File

@ -43,7 +43,11 @@ def lesson_saved(sender, instance, created, **kwargs):
)
if instance.tracker.has_changed('status'):
# Статус изменился
# Статус изменился — не уведомляем, если занятие уже в прошлом
# (коррекция статуса/стоимости после факта, например отмена задним числом)
ref_time = instance.end_time or instance.start_time
if ref_time and ref_time < timezone.now():
return # Занятие уже прошло — уведомления не отправляем
if instance.status == 'cancelled':
send_lesson_notification.delay(
lesson_id=instance.id,

View File

@ -438,6 +438,13 @@ def start_lessons_automatically():
except Exception as e:
logger.error(f'Ошибка закрытия LiveKit комнаты для урока {lesson.id}: {str(e)}', exc_info=True)
# Отправить ментору в Telegram сообщение с кнопками подтверждения
try:
from apps.notifications.tasks import send_lesson_completion_confirmation_telegram
send_lesson_completion_confirmation_telegram.delay(lesson.id)
except Exception as e:
logger.warning(f'Не удалось отправить подтверждение занятия в Telegram: {e}')
if started_count > 0 or completed_count > 0:
logger.info(f'[start_lessons_automatically] Начато: {started_count}, Завершено: {completed_count}')

View File

@ -19,7 +19,26 @@
{ "country_code": "RU", "country_name": "Россия", "city": "Тюмень", "timezone": "Asia/Yekaterinburg" },
{ "country_code": "RU", "country_name": "Россия", "city": "Иркутск", "timezone": "Asia/Irkutsk" },
{ "country_code": "RU", "country_name": "Россия", "city": "Владивосток", "timezone": "Asia/Vladivostok" },
{ "country_code": "RU", "country_name": "Россия", "city": "Ульяновск", "timezone": "Europe/Samara" }
{ "country_code": "RU", "country_name": "Россия", "city": "Ульяновск", "timezone": "Europe/Samara" },
{ "country_code": "RU", "country_name": "Россия", "city": "Улан-Удэ", "timezone": "Asia/Irkutsk" },
{ "country_code": "RU", "country_name": "Россия", "city": "Чита", "timezone": "Asia/Chita" },
{ "country_code": "RU", "country_name": "Россия", "city": "Хабаровск", "timezone": "Asia/Vladivostok" },
{ "country_code": "RU", "country_name": "Россия", "city": "Барнаул", "timezone": "Asia/Barnaul" },
{ "country_code": "RU", "country_name": "Россия", "city": "Томск", "timezone": "Asia/Tomsk" },
{ "country_code": "RU", "country_name": "Россия", "city": "Кемерово", "timezone": "Asia/Novokuznetsk" },
{ "country_code": "RU", "country_name": "Россия", "city": "Новокузнецк", "timezone": "Asia/Novokuznetsk" },
{ "country_code": "RU", "country_name": "Россия", "city": "Якутск", "timezone": "Asia/Yakutsk" },
{ "country_code": "RU", "country_name": "Россия", "city": "Магадан", "timezone": "Asia/Magadan" },
{ "country_code": "RU", "country_name": "Россия", "city": "Петропавловск-Камчатский", "timezone": "Asia/Kamchatka" },
{ "country_code": "RU", "country_name": "Россия", "city": "Южно-Сахалинск", "timezone": "Asia/Sakhalin" },
{ "country_code": "RU", "country_name": "Россия", "city": "Ижевск", "timezone": "Europe/Samara" },
{ "country_code": "RU", "country_name": "Россия", "city": "Оренбург", "timezone": "Asia/Yekaterinburg" },
{ "country_code": "RU", "country_name": "Россия", "city": "Рязань", "timezone": "Europe/Moscow" },
{ "country_code": "RU", "country_name": "Россия", "city": "Пенза", "timezone": "Europe/Moscow" },
{ "country_code": "RU", "country_name": "Россия", "city": "Липецк", "timezone": "Europe/Moscow" },
{ "country_code": "RU", "country_name": "Россия", "city": "Астрахань", "timezone": "Europe/Astrakhan" },
{ "country_code": "RU", "country_name": "Россия", "city": "Сочи", "timezone": "Europe/Moscow" },
{ "country_code": "RU", "country_name": "Россия", "city": "Калининград", "timezone": "Europe/Kaliningrad" }
]

View File

@ -36,6 +36,22 @@ POPULAR_CITIES = [
{"country_code": "RU", "country_name": "Россия", "city": "Самара", "timezone": "Europe/Samara"},
{"country_code": "RU", "country_name": "Россия", "city": "Красноярск", "timezone": "Asia/Krasnoyarsk"},
{"country_code": "RU", "country_name": "Россия", "city": "Владивосток", "timezone": "Asia/Vladivostok"},
{"country_code": "RU", "country_name": "Россия", "city": "Улан-Удэ", "timezone": "Asia/Irkutsk"},
{"country_code": "RU", "country_name": "Россия", "city": "Иркутск", "timezone": "Asia/Irkutsk"},
{"country_code": "RU", "country_name": "Россия", "city": "Чита", "timezone": "Asia/Chita"},
{"country_code": "RU", "country_name": "Россия", "city": "Хабаровск", "timezone": "Asia/Vladivostok"},
{"country_code": "RU", "country_name": "Россия", "city": "Омск", "timezone": "Asia/Omsk"},
{"country_code": "RU", "country_name": "Россия", "city": "Челябинск", "timezone": "Asia/Yekaterinburg"},
{"country_code": "RU", "country_name": "Россия", "city": "Уфа", "timezone": "Asia/Yekaterinburg"},
{"country_code": "RU", "country_name": "Россия", "city": "Ростов-на-Дону", "timezone": "Europe/Moscow"},
{"country_code": "RU", "country_name": "Россия", "city": "Пермь", "timezone": "Asia/Yekaterinburg"},
{"country_code": "RU", "country_name": "Россия", "city": "Воронеж", "timezone": "Europe/Moscow"},
{"country_code": "RU", "country_name": "Россия", "city": "Волгоград", "timezone": "Europe/Moscow"},
{"country_code": "RU", "country_name": "Россия", "city": "Краснодар", "timezone": "Europe/Moscow"},
{"country_code": "RU", "country_name": "Россия", "city": "Барнаул", "timezone": "Asia/Barnaul"},
{"country_code": "RU", "country_name": "Россия", "city": "Томск", "timezone": "Asia/Tomsk"},
{"country_code": "RU", "country_name": "Россия", "city": "Якутск", "timezone": "Asia/Yakutsk"},
{"country_code": "RU", "country_name": "Россия", "city": "Калининград", "timezone": "Europe/Kaliningrad"},
# Казахстан
{"country_code": "KZ", "country_name": "Казахстан", "city": "Алматы", "timezone": "Asia/Almaty"},
{"country_code": "KZ", "country_name": "Казахстан", "city": "Астана", "timezone": "Asia/Almaty"},
@ -43,7 +59,6 @@ POPULAR_CITIES = [
{"country_code": "BY", "country_name": "Беларусь", "city": "Минск", "timezone": "Europe/Minsk"},
# Украина
{"country_code": "UA", "country_name": "Украина", "city": "Киев", "timezone": "Europe/Kyiv"},
# Другие крупные города СНГ можно добавлять по мере необходимости
]

View File

@ -275,6 +275,60 @@ def delete_livekit_room_by_lesson(request, lesson_id):
)
@api_view(['POST'])
@permission_classes([IsAuthenticated])
def participant_connected(request):
"""
Отметить подключение участника к видеокомнате (для метрик).
Вызывается фронтендом при успешном подключении к LiveKit комнате.
POST /api/video/livekit/participant-connected/
Body: { "room_name": "uuid" }
"""
room_name = request.data.get('room_name')
if not room_name:
return Response(
{'error': 'room_name обязателен'},
status=status.HTTP_400_BAD_REQUEST
)
try:
import uuid as uuid_module
room_uuid = uuid_module.UUID(str(room_name))
video_room = VideoRoom.objects.get(room_id=room_uuid)
except (ValueError, VideoRoom.DoesNotExist):
return Response(
{'error': 'Видеокомната не найдена'},
status=status.HTTP_404_NOT_FOUND
)
user = request.user
client_user = video_room.client.user if hasattr(video_room.client, 'user') else video_room.client
if user != video_room.mentor and user != client_user:
return Response(
{'error': 'Нет доступа к этой видеокомнате'},
status=status.HTTP_403_FORBIDDEN
)
from .models import VideoParticipant
participant, _ = VideoParticipant.objects.get_or_create(
room=video_room,
user=user,
defaults={
'is_connected': True,
'is_audio_enabled': True,
'is_video_enabled': True,
}
)
if not participant.is_connected:
participant.is_connected = True
participant.save(update_fields=['is_connected'])
video_room.mark_participant_joined(user)
return Response({'success': True}, status=status.HTTP_200_OK)
@api_view(['POST'])
@permission_classes([IsAuthenticated])
def update_livekit_participant_media_state(request):
@ -336,6 +390,8 @@ def update_livekit_participant_media_state(request):
'is_video_enabled': video_enabled if video_enabled is not None else True,
}
)
# Фиксируем подключение ментора/студента для метрик
video_room.mark_participant_joined(user)
if not created:
# Обновляем существующего участника

View File

@ -1,4 +1,4 @@
"""
"""
Модели для видеоконференций.
"""
from django.db import models
@ -219,13 +219,26 @@ class VideoRoom(models.Model):
self.save()
def mark_participant_joined(self, user):
"""Отметить что участник подключился."""
"""Отметить что участник подключился (также обновляет Lesson для метрик)."""
now = timezone.now()
update_fields = []
if user == self.mentor:
self.mentor_joined_at = timezone.now()
self.mentor_joined_at = now
update_fields.append('mentor_joined_at')
elif user == self.client:
self.client_joined_at = timezone.now()
self.client_joined_at = now
update_fields.append('client_joined_at')
self.save(update_fields=['mentor_joined_at', 'client_joined_at'])
if update_fields:
self.save(update_fields=update_fields)
# Синхронизируем метрики на занятие для аналитики
lesson = self.lesson
if user == self.mentor and not lesson.mentor_connected_at:
lesson.mentor_connected_at = now
lesson.save(update_fields=['mentor_connected_at'])
elif user == self.client and not lesson.client_connected_at:
lesson.client_connected_at = now
lesson.save(update_fields=['client_connected_at'])
@property
def is_active(self):

View File

@ -1,4 +1,4 @@
"""
"""
URL routing для видео API.
"""
from django.urls import path, include
@ -11,7 +11,7 @@ from .views import (
)
from .janus_views import JanusVideoRoomViewSet
from .token_views import VideoRoomTokenViewSet
from .livekit_views import create_livekit_room, get_livekit_config, delete_livekit_room_by_lesson, update_livekit_participant_media_state
from .livekit_views import create_livekit_room, get_livekit_config, delete_livekit_room_by_lesson, update_livekit_participant_media_state, participant_connected
router = DefaultRouter()
router.register(r'rooms', VideoRoomViewSet, basename='videoroom')
@ -32,4 +32,5 @@ urlpatterns = [
path('livekit/config/', get_livekit_config, name='livekit-config'),
path('livekit/rooms/lesson/<int:lesson_id>/', delete_livekit_room_by_lesson, name='livekit-delete-room-by-lesson'),
path('livekit/update-media-state/', update_livekit_participant_media_state, name='livekit-update-media-state'),
path('livekit/participant-connected/', participant_connected, name='livekit-participant-connected'),
]

View File

@ -2,8 +2,8 @@
# Docker Compose PROD (порты не пересекаются с dev на одном хосте)
# ==============================================
# Порты на хосте (prod): db 5434, redis 6381, web 8123, nginx 8084,
# front_material 3010, yjs 1236, excalidraw 3004, whiteboard 8083,
# livekit 7880/7881, celery/beat — без портов (внутренние)
# front_material 3010, yjs 1236, excalidraw 3004, livekit 7880/7881,
# celery/beat — без портов (внутренние)
# Dev использует: 5433, 6380, 8124, 8081, 3002, 1235, 3003, 8082, livekit 7890/7891
#
# ВАЖНО: PROD использует отдельную сеть (prod_network) и именованные volumes
@ -273,17 +273,6 @@ services:
networks:
- prod_network
whiteboard:
build:
context: ./whiteboard-server
dockerfile: Dockerfile
container_name: platform_prod_whiteboard
restart: unless-stopped
ports:
- "8083:8080"
networks:
- prod_network
volumes:
# ВАЖНО: Эти volumes содержат данные БД и Redis
# НЕ используйте docker compose down --volumes без бэкапа!

View File

@ -91,12 +91,6 @@ http {
keepalive 32;
}
upstream whiteboard {
least_conn;
server whiteboard:8080 max_fails=3 fail_timeout=30s;
keepalive 32;
}
upstream livekit {
server livekit:7880 max_fails=3 fail_timeout=30s;
keepalive 4;

View File

@ -0,0 +1,13 @@
{
"builder": {
"gc": {
"defaultKeepStorage": "10GB",
"enabled": true
}
},
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}

View File

@ -5,6 +5,7 @@ node_modules
*.md
.env*.local
.env
.env.*
.DS_Store
*.log
npm-debug.log*
@ -15,3 +16,10 @@ coverage
.nyc_output
.vscode
.idea
docs
.cursor
agent-transcripts
__pycache__
*.pyc
.pytest_cache
.mypy_cache

View File

@ -50,3 +50,10 @@ export async function getLiveKitConfig(): Promise<LiveKitConfig> {
const res = await apiClient.get<LiveKitConfig>('/video/livekit/config/');
return res.data;
}
/**
* Отметить подключение участника к видеокомнате (для метрик)
*/
export async function participantConnected(roomName: string): Promise<void> {
await apiClient.post('/video/livekit/participant-connected/', { room_name: roomName });
}

View File

@ -147,6 +147,8 @@ export interface UpdateLessonData {
start_time?: string;
duration?: number;
price?: number;
/** Для завершённых занятий — можно изменить статус (cancelled и т.д.) */
status?: 'scheduled' | 'in_progress' | 'completed' | 'cancelled';
}
/**

View File

@ -3,6 +3,7 @@
import { useState, useEffect } from 'react';
import { useRouter } from 'next/navigation';
import { requestPasswordReset } from '@/api/auth';
import { getErrorMessage } from '@/lib/error-utils';
const loadMaterialComponents = async () => {
await Promise.all([
@ -39,7 +40,7 @@ export default function ForgotPasswordPage() {
await requestPasswordReset({ email });
setSuccess(true);
} catch (err: any) {
setError(err.response?.data?.detail || 'Ошибка при отправке запроса. Проверьте email.');
setError(getErrorMessage(err, 'Ошибка при отправке запроса. Проверьте email.'));
} finally {
setLoading(false);
}

View File

@ -5,6 +5,7 @@ import { useRouter, useSearchParams } from 'next/navigation';
import { register } from '@/api/auth';
import { REFERRAL_STORAGE_KEY } from '@/api/referrals';
import { searchCitiesFromCSV, type CityOption } from '@/api/profile';
import { getErrorMessage } from '@/lib/error-utils';
const loadMaterialComponents = async () => {
await Promise.all([
@ -144,14 +145,7 @@ export default function RegisterPage() {
setRegistrationSuccess(true);
return;
} catch (err: any) {
setError(
err.response?.data?.detail ||
(Array.isArray(err.response?.data?.email)
? err.response.data.email[0]
: err.response?.data?.email) ||
err.response?.data?.message ||
'Ошибка регистрации. Проверьте данные.'
);
setError(getErrorMessage(err, 'Ошибка регистрации. Проверьте данные.'));
} finally {
setLoading(false);
}

View File

@ -3,6 +3,7 @@
import { useState, useEffect, Suspense } from 'react';
import { useRouter, useSearchParams } from 'next/navigation';
import { confirmPasswordReset } from '@/api/auth';
import { getErrorMessage } from '@/lib/error-utils';
const loadMaterialComponents = async () => {
await Promise.all([
@ -43,11 +44,7 @@ function ResetPasswordContent() {
await confirmPasswordReset(token, password, confirmPassword);
setSuccess(true);
} catch (err: any) {
setError(
err.response?.data?.error?.message ||
err.response?.data?.detail ||
'Не удалось сменить пароль. Ссылка могла устареть — запросите новую.'
);
setError(getErrorMessage(err, 'Не удалось сменить пароль. Ссылка могла устареть — запросите новую.'));
} finally {
setLoading(false);
}

View File

@ -3,6 +3,7 @@
import { useState, useEffect, Suspense } from 'react';
import { useRouter, useSearchParams } from 'next/navigation';
import { verifyEmail } from '@/api/auth';
import { getErrorMessage } from '@/lib/error-utils';
const loadMaterialComponents = async () => {
await Promise.all([
@ -47,11 +48,7 @@ function VerifyEmailContent() {
.catch((err: any) => {
if (cancelled) return;
setStatus('error');
const msg =
err.response?.data?.error?.message ||
err.response?.data?.detail ||
'Неверная или устаревшая ссылка. Запросите новое письмо с подтверждением.';
setMessage(msg);
setMessage(getErrorMessage(err, 'Неверная или устаревшая ссылка. Запросите новое письмо с подтверждением.'));
});
return () => {

View File

@ -24,6 +24,7 @@ import { getSubjects, getMentorSubjects } from '@/api/subjects';
import { loadComponent } from '@/lib/material-components';
import { LoadingSpinner } from '@/components/common/LoadingSpinner';
import { ErrorDisplay } from '@/components/common/ErrorDisplay';
import { getErrorMessage } from '@/lib/error-utils';
import type { CalendarLesson } from '@/components/calendar/calendar';
import type { CheckLessonFormData, CheckLessonProps } from '@/components/checklesson/checklesson';
import type { LessonPreview } from '@/api/dashboard';
@ -61,6 +62,7 @@ export default function SchedulePage() {
const [selectedSubjectId, setSelectedSubjectId] = useState<number | null>(null);
const [selectedMentorSubjectId, setSelectedMentorSubjectId] = useState<number | null>(null);
const [editingLessonId, setEditingLessonId] = useState<string | null>(null);
const [editingLessonStatus, setEditingLessonStatus] = useState<string | null>(null);
// Компоненты Material Web
const [buttonComponentsLoaded, setButtonComponentsLoaded] = useState(false);
@ -264,7 +266,9 @@ export default function SchedulePage() {
duration,
price: typeof details.price === 'number' ? details.price : undefined,
is_recurring: !!(details as any).is_recurring,
status: (details as any).status ?? 'completed',
});
setEditingLessonStatus((details as any).status ?? null);
// пробуем выставить предмет по названию
const subjName = (details as any).subject_name || (details as any).subject || '';
@ -329,6 +333,8 @@ export default function SchedulePage() {
setFormError(null);
try {
const isCompleted = editingLessonStatus === 'completed';
if (!isCompleted) {
if (!formData.client) {
setFormError('Выберите ученика');
setFormLoading(false);
@ -344,21 +350,25 @@ export default function SchedulePage() {
setFormLoading(false);
return;
}
}
if (formData.price == null || formData.price < 0) {
setFormError('Укажите стоимость занятия');
setFormLoading(false);
return;
}
// Конвертируем время из timezone пользователя в UTC
const startUtc = createDateTimeInUserTimezone(
formData.start_date,
formData.start_time,
user?.timezone
);
const startUtc = !isCompleted
? createDateTimeInUserTimezone(formData.start_date, formData.start_time, user?.timezone)
: '';
const title = generateTitle();
if (isEditingMode && editingLessonId) {
if (editingLessonStatus === 'completed') {
await updateLesson(editingLessonId, {
price: formData.price,
status: formData.status ?? 'completed',
});
} else {
await updateLesson(editingLessonId, {
title,
description: formData.description,
@ -366,6 +376,7 @@ export default function SchedulePage() {
duration: formData.duration,
price: formData.price,
});
}
} else {
const payload: any = {
client: formData.client,
@ -384,16 +395,10 @@ export default function SchedulePage() {
setIsFormVisible(false);
setEditingLessonId(null);
setEditingLessonStatus(null);
loadLessons();
} catch (err: any) {
const msg = err?.response?.data
? typeof err.response.data === 'object'
? Object.entries(err.response.data)
.map(([k, v]) => `${k}: ${Array.isArray(v) ? v.join(', ') : v}`)
.join('\n')
: String(err.response.data)
: err?.message || 'Ошибка сохранения занятия';
setFormError(msg);
setFormError(getErrorMessage(err, 'Не удалось сохранить занятие. Проверьте данные.'));
} finally {
setFormLoading(false);
}
@ -407,9 +412,10 @@ export default function SchedulePage() {
await deleteLesson(editingLessonId, deleteAllFuture);
setIsFormVisible(false);
setEditingLessonId(null);
setEditingLessonStatus(null);
loadLessons();
} catch (err: any) {
setFormError(err?.message || 'Ошибка удаления занятия');
setFormError(getErrorMessage(err, 'Не удалось удалить занятие.'));
} finally {
setFormLoading(false);
}
@ -420,6 +426,7 @@ export default function SchedulePage() {
setIsEditingMode(false);
setFormError(null);
setEditingLessonId(null);
setEditingLessonStatus(null);
};
return (
@ -476,6 +483,7 @@ export default function SchedulePage() {
onSubmit={handleSubmit}
onCancel={handleCancel}
onDelete={isEditingMode ? handleDelete : undefined}
isCompletedLesson={editingLessonStatus === 'completed'}
/>
</div>
</div>

View File

@ -237,6 +237,7 @@ export function ChatWindow({
setLoadingMore(false);
setPage(1);
setHasMore(false);
(async () => {
try {
const pageSize = 30;
@ -244,7 +245,6 @@ export function ChatWindow({
? await getChatMessagesByUuid(chatUuid, { page: 1, page_size: pageSize })
: await getMessages(chat.id, { page: 1, page_size: pageSize });
const initial = (resp.results || []) as Message[];
// сортируем по времени на всякий случай
const sorted = [...initial].sort((a: any, b: any) => {
const ta = a?.created_at ? new Date(a.created_at).getTime() : 0;
const tb = b?.created_at ? new Date(b.created_at).getTime() : 0;
@ -252,13 +252,14 @@ export function ChatWindow({
});
setMessages(sorted);
setHasMore(!!(resp as any).next || ((resp as any).count ?? 0) > sorted.length);
// прочитанность отмечается по мере попадания сообщений в зону видимости (IntersectionObserver)
// Молниеносный скролл вниз (мгновенно, без анимации)
requestAnimationFrame(() => {
const el = listRef.current;
if (el) el.scrollTo({ top: el.scrollHeight, behavior: 'auto' });
});
} finally {
setLoading(false);
// scroll down
setTimeout(() => {
listRef.current?.scrollTo({ top: listRef.current.scrollHeight, behavior: 'smooth' });
}, 50);
}
})();
}, [chat?.id, chatUuid]);

View File

@ -28,6 +28,8 @@ export interface CheckLessonFormData {
duration: number;
price: number | undefined;
is_recurring: boolean;
/** Статус (для завершённых занятий — можно менять) */
status?: 'scheduled' | 'in_progress' | 'completed' | 'cancelled';
}
export interface CheckLessonProps {
@ -72,6 +74,8 @@ export interface CheckLessonProps {
onCancel: () => void;
/** Удалить занятие (только в режиме редактирования). deleteAllFuture — удалить всю цепочку постоянных. */
onDelete?: (deleteAllFuture: boolean) => void;
/** Редактируется завершённое занятие — можно менять только цену и статус */
isCompletedLesson?: boolean;
}
export const CheckLesson: React.FC<CheckLessonProps> = ({
@ -102,6 +106,7 @@ export const CheckLesson: React.FC<CheckLessonProps> = ({
onSubmit,
onCancel,
onDelete,
isCompletedLesson = false,
}) => {
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
const navDisabled = lessonsLoading || isFormVisible;
@ -142,21 +147,11 @@ export const CheckLesson: React.FC<CheckLessonProps> = ({
width: '100%',
height: '100%',
minHeight: '548px',
perspective: '1000px',
display: 'flex',
flexDirection: 'column',
}}
>
<div
style={{
position: 'relative',
width: '100%',
height: '100%',
transformStyle: 'preserve-3d',
transition: 'transform 0.6s ease-in-out',
transform: isFormVisible ? 'rotateY(180deg)' : 'rotateY(0deg)',
}}
>
<div style={{ position: 'relative', width: '100%', height: '100%' }}>
{/* Лицевая сторона: Список занятий */}
<div
className="ios-glass-panel"
@ -166,13 +161,12 @@ export const CheckLesson: React.FC<CheckLessonProps> = ({
left: 0,
width: '100%',
height: '100%',
backfaceVisibility: 'hidden',
WebkitBackfaceVisibility: 'hidden',
transform: 'rotateY(0deg)',
opacity: isFormVisible ? 0 : 1,
visibility: isFormVisible ? 'hidden' : 'visible',
transition: 'opacity 0.2s ease',
borderRadius: '20px',
padding: '24px',
overflowY: 'hidden',
transformOrigin: 'center center',
display: 'flex',
flexDirection: 'column',
}}
@ -369,13 +363,12 @@ export const CheckLesson: React.FC<CheckLessonProps> = ({
left: 0,
width: '100%',
height: '100%',
backfaceVisibility: 'hidden',
WebkitBackfaceVisibility: 'hidden',
transform: 'rotateY(180deg)',
opacity: isFormVisible ? 1 : 0,
visibility: isFormVisible ? 'visible' : 'hidden',
transition: 'opacity 0.2s ease',
borderRadius: '20px',
padding: '24px',
overflowY: 'auto',
transformOrigin: 'center center',
display: 'flex',
flexDirection: 'column',
}}
@ -413,7 +406,11 @@ export const CheckLesson: React.FC<CheckLessonProps> = ({
margin: 0,
}}
>
{isEditingMode ? 'Редактировать занятие' : 'Создать занятие'}
{isCompletedLesson
? 'Изменить завершённое занятие'
: isEditingMode
? 'Редактировать занятие'
: 'Создать занятие'}
</h3>
<button
type="button"
@ -459,6 +456,7 @@ export const CheckLesson: React.FC<CheckLessonProps> = ({
</div>
)}
{!isCompletedLesson && (
<div style={{ gridColumn: 1 }}>
<label
style={{
@ -479,7 +477,9 @@ export const CheckLesson: React.FC<CheckLessonProps> = ({
required
/>
</div>
)}
{!isCompletedLesson && (
<div style={{ gridColumn: 2 }}>
<label
style={{
@ -509,7 +509,9 @@ export const CheckLesson: React.FC<CheckLessonProps> = ({
required
/>
</div>
)}
{!isCompletedLesson && (
<div style={{ gridColumn: '1 / -1' }}>
<label
style={{
@ -551,7 +553,10 @@ export const CheckLesson: React.FC<CheckLessonProps> = ({
}}
/>
</div>
)}
{!isCompletedLesson && (
<>
<div style={{ gridColumn: 1 }}>
<label
style={{
@ -687,10 +692,51 @@ export const CheckLesson: React.FC<CheckLessonProps> = ({
<Switch
checked={formData.is_recurring}
onChange={(checked) => setFormData((prev) => ({ ...prev, is_recurring: checked }))}
disabled={formLoading}
disabled={formLoading || isCompletedLesson}
label="Постоянное занятие (повторяется еженедельно)"
/>
</div>
</>
)}
{isCompletedLesson && (
<div style={{ gridColumn: '1 / -1' }}>
<label
style={{
display: 'block',
fontSize: 12,
fontWeight: 500,
color: 'var(--md-sys-color-on-surface-variant)',
marginBottom: 4,
}}
>
Статус
</label>
<select
value={formData.status ?? 'completed'}
onChange={(e) => setFormData((prev) => ({ ...prev, status: e.target.value as 'completed' | 'cancelled' }))}
disabled={formLoading}
style={{
width: '100%',
padding: '12px 16px',
fontSize: 16,
color: 'var(--md-sys-color-on-surface)',
background: 'var(--md-sys-color-surface)',
border: '1px solid var(--md-sys-color-outline)',
borderRadius: 4,
fontFamily: 'inherit',
cursor: formLoading ? 'not-allowed' : 'pointer',
outline: 'none',
}}
>
<option value="completed">Завершено</option>
<option value="cancelled">Отменено</option>
</select>
<p style={{ fontSize: 12, color: 'var(--md-sys-color-on-surface-variant)', marginTop: 4, marginBottom: 0 }}>
Изменение статуса задним числом не отправляет уведомления ученику и родителям
</p>
</div>
)}
<div
style={{
@ -703,7 +749,7 @@ export const CheckLesson: React.FC<CheckLessonProps> = ({
}}
>
<div style={{ display: 'flex', gap: 12 }}>
{isEditingMode && onDelete && (
{isEditingMode && !isCompletedLesson && onDelete && (
<button
type="button"
onClick={handleDeleteClick}

View File

@ -7,6 +7,7 @@
import React, { useState, useEffect } from 'react';
import { loadComponent } from '@/lib/material-components';
import { createLesson } from '@/api/schedule';
import { getErrorMessage } from '@/lib/error-utils';
import { getStudents, Student } from '@/api/students';
import { getSubjects, getMentorSubjects, createMentorSubject, Subject, MentorSubject } from '@/api/subjects';
import { getCurrentUser, User } from '@/api/auth';
@ -300,14 +301,7 @@ export const CreateLessonDialog: React.FC<CreateLessonDialogProps> = ({
onClose();
} catch (err: any) {
console.error('[CreateLessonDialog] Ошибка создания занятия:', err);
if (err.response?.data) {
const fieldErrors = Object.entries(err.response.data)
.map(([key, value]) => `${key}: ${Array.isArray(value) ? value.join(', ') : value}`)
.join('\n');
setError(fieldErrors);
} else {
setError(err.message || 'Ошибка создания занятия');
}
setError(getErrorMessage(err, 'Не удалось создать занятие. Проверьте данные.'));
} finally {
setLoading(false);
}

View File

@ -1,5 +1,5 @@
/**
* Flip-карточка с эффектом переворота (iOS 26).
* Карточка с лицевой и обратной стороной (переключение без анимации переворота).
*/
'use client';
@ -15,9 +15,9 @@ export interface FlipCardProps {
height?: string | number;
/** Дополнительный класс */
className?: string;
/** Управляемый режим переворота (если задан) */
/** Управляемый режим (если задан) */
flipped?: boolean;
/** Коллбек при смене состояния (для управляемого режима) */
/** Коллбек при смене состояния */
onFlippedChange?: (flipped: boolean) => void;
}
@ -43,22 +43,10 @@ export const FlipCard: React.FC<FlipCardProps> = ({
className={`flip-card ${className}`.trim()}
style={{
position: 'relative',
perspective: '1000px',
height: typeof height === 'number' ? `${height}px` : height,
width: '100%',
...(height === 'auto' && { minHeight: 340 }),
}}
>
<div
className="flip-card-inner"
style={{
position: 'relative',
width: '100%',
height: '100%',
transition: 'transform 0.6s',
transformStyle: 'preserve-3d',
transform: isFlipped ? 'rotateY(180deg)' : 'rotateY(0deg)',
}}
>
<div
className="flip-card-front"
@ -68,8 +56,9 @@ export const FlipCard: React.FC<FlipCardProps> = ({
left: 0,
width: '100%',
height: '100%',
backfaceVisibility: 'hidden',
WebkitBackfaceVisibility: 'hidden',
opacity: isFlipped ? 0 : 1,
visibility: isFlipped ? 'hidden' : 'visible',
transition: 'opacity 0.2s ease',
}}
>
{front}
@ -82,14 +71,13 @@ export const FlipCard: React.FC<FlipCardProps> = ({
left: 0,
width: '100%',
height: '100%',
backfaceVisibility: 'hidden',
WebkitBackfaceVisibility: 'hidden',
transform: 'rotateY(180deg)',
opacity: isFlipped ? 1 : 0,
visibility: isFlipped ? 'visible' : 'hidden',
transition: 'opacity 0.2s ease',
}}
>
{back}
</div>
</div>
</div>
);
};

View File

@ -61,6 +61,7 @@ import { isTrackReference } from '@livekit/components-core';
import '@/styles/livekit-components.css';
import '@/styles/livekit-theme.css';
import { getLesson } from '@/api/schedule';
import { participantConnected } from '@/api/livekit';
import type { Lesson } from '@/api/schedule';
import { getOrCreateLessonBoard } from '@/api/board';
@ -446,6 +447,18 @@ function RoomContent({ lessonId, boardId, boardLoading, showBoard, setShowBoard,
getNavBadges().then(setNavBadges).catch(() => setNavBadges(null));
}, [user]);
// Фиксируем подключение ментора/студента для метрик
useEffect(() => {
const onConnected = () => {
if (room.name) participantConnected(room.name).catch(() => {});
};
room.on(RoomEvent.Connected, onConnected);
if (room.state === 'connected' && room.name) participantConnected(room.name).catch(() => {});
return () => {
room.off(RoomEvent.Connected, onConnected);
};
}, [room]);
useEffect(() => {
if (!showPlatformChat || !lessonId) {
if (!showPlatformChat) setLessonChat(null);

View File

@ -2132,7 +2132,7 @@ img {
}
}
/* Flip-карточка эффект */
/* Flip-карточка (переключение без переворота) */
.flip-card {
position: relative;
width: 100%;
@ -2142,14 +2142,6 @@ img {
flex-direction: column;
}
.flip-card-inner {
position: relative;
width: 100%;
height: 100%;
transition: transform 0.6s;
transform-style: preserve-3d;
}
.flip-card-front,
.flip-card-back {
position: absolute;
@ -2157,12 +2149,6 @@ img {
left: 0;
width: 100%;
height: 100%;
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
display: flex;
flex-direction: column;
}
.flip-card-back {
transform: rotateY(180deg);
}