feat: update purchcases page

This commit is contained in:
ivannoskov
2025-12-01 06:27:37 +03:00
parent d2cc1c39b3
commit 790fd5cd5b
3 changed files with 784 additions and 154 deletions

View File

@@ -23,7 +23,6 @@ import {
Plus,
ExternalLink,
CheckCircle2,
ArrowUpRightIcon,
} from "lucide-react";
import { Alert, AlertDescription } from "@/components/ui/alert";
import { BOT_USERNAME } from "@/lib/utils/constants";
@@ -49,7 +48,6 @@ export const TargetChannelSelector: React.FC = () => {
// Автоматический запуск polling при открытии диалога
useEffect(() => {
if (isAddDialogOpen && !isSuccess && initialChannelCount > 0) {
// Polling каждую секунду
pollingIntervalRef.current = setInterval(() => {
checkForNewChannels();
}, 1000);
@@ -71,20 +69,15 @@ export const TargetChannelSelector: React.FC = () => {
);
if (activeChannels.length > initialChannelCount) {
// Новый канал добавлен!
setIsSuccess(true);
// Останавливаем polling
if (pollingIntervalRef.current) {
clearInterval(pollingIntervalRef.current);
pollingIntervalRef.current = null;
}
// Закрываем диалог через 2 секунды
setTimeout(() => {
setIsAddDialogOpen(false);
setIsSuccess(false);
// Обновляем список каналов через провайдер
window.location.reload();
}, 2000);
}
@@ -99,16 +92,15 @@ export const TargetChannelSelector: React.FC = () => {
setIsAddDialogOpen(true);
};
const handleDialogClose = () => {
if (!isSuccess) {
// Не даем закрыть диалог во время ожидания
return;
}
setIsAddDialogOpen(false);
setIsSuccess(false);
if (pollingIntervalRef.current) {
clearInterval(pollingIntervalRef.current);
pollingIntervalRef.current = null;
const handleDialogOpenChange = (open: boolean) => {
if (!open) {
// Разрешаем закрытие всегда (в том числе через кнопку крестик)
setIsAddDialogOpen(false);
setIsSuccess(false);
if (pollingIntervalRef.current) {
clearInterval(pollingIntervalRef.current);
pollingIntervalRef.current = null;
}
}
};
@@ -203,10 +195,11 @@ export const TargetChannelSelector: React.FC = () => {
</SelectContent>
</Select>
<Dialog open={isAddDialogOpen} onOpenChange={handleDialogClose}>
<Dialog open={isAddDialogOpen} onOpenChange={handleDialogOpenChange}>
<DialogContent
className="sm:max-w-md"
onInteractOutside={(e) => !isSuccess && e.preventDefault()}
onEscapeKeyDown={(e) => !isSuccess && e.preventDefault()}
>
<DialogHeader>
<DialogTitle>Добавить целевой канал</DialogTitle>
@@ -244,6 +237,10 @@ export const TargetChannelSelector: React.FC = () => {
target="_blank"
rel="noopener noreferrer"
className="font-mono text-primary hover:underline inline-flex items-center gap-1"
tabIndex={0}
aria-label={`Открыть бота @${BOT_USERNAME} в Telegram`}
onClick={(e) => e.stopPropagation()}
onKeyDown={(e) => e.stopPropagation()}
>
@{BOT_USERNAME}
<ExternalLink className="h-3 w-3" />