From c9357962c61b21173edd57b49e932b3b33e5ebde Mon Sep 17 00:00:00 2001 From: c00b3r Date: Wed, 2 Jul 2025 12:07:38 +0500 Subject: [PATCH] feat: enhance TableSelector with automatic selection logic and update CreateSessionModal and EndSessionModal for improved session handling and user feedback --- src/components/TableSelector.tsx | 11 +++++- src/components/modals/CreateSessionModal.tsx | 5 +-- src/components/modals/EndSessionModal.tsx | 40 ++++++++++++++------ src/pages/LoginPage.tsx | 2 +- 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/components/TableSelector.tsx b/src/components/TableSelector.tsx index e00c6fd..df9e64b 100644 --- a/src/components/TableSelector.tsx +++ b/src/components/TableSelector.tsx @@ -1,11 +1,12 @@ import clsx from "clsx"; import { Server } from "../types/Server"; import LightningIcon from "./icons/LightningIcon"; +import { useEffect } from "react"; interface TableSelectorProps { tables: Server[]; selectedTable: Server | null; - onSelect: (table: Server) => void; + onSelect: (table: Server | null) => void; } function TableSelector({ @@ -13,6 +14,14 @@ function TableSelector({ selectedTable, onSelect, }: TableSelectorProps) { + useEffect(() => { + if (selectedTable !== null) { + onSelect(selectedTable); + } else { + onSelect(tables.find((table) => table.status === "online") || null); + } + }, [onSelect, selectedTable, tables]); + return (
{tables.map((table) => ( diff --git a/src/components/modals/CreateSessionModal.tsx b/src/components/modals/CreateSessionModal.tsx index 290fbdc..5dfbbce 100644 --- a/src/components/modals/CreateSessionModal.tsx +++ b/src/components/modals/CreateSessionModal.tsx @@ -65,11 +65,8 @@ export default function CreateSessionModal({ targetServerId, client }: Props) { if (!error && data) { setName(data.name); setEmail(data.email); - } else { - setName(isFullPhone ? name : null); - setEmail(isFullPhone ? email : null); } - }, [data, error, isFullPhone, name, email]); + }, [data, error]); const { mutate: createClient } = useMutation({ mutationFn: () => diff --git a/src/components/modals/EndSessionModal.tsx b/src/components/modals/EndSessionModal.tsx index c1f6d6d..278722f 100644 --- a/src/components/modals/EndSessionModal.tsx +++ b/src/components/modals/EndSessionModal.tsx @@ -6,12 +6,17 @@ import Button from "../Button"; import CurrentSessionModal from "./CurrentSessionModal"; import api from "../../utils/api"; import SpinIcon from "../icons/SpinIcon"; +import SessionModal from "./SessionModal"; function EndSessionModal({ session }: { session: Session }) { const queryClient = useQueryClient(); const { setModal } = useModalStore(); - const { mutate: endSession, isPending } = useMutation({ + const { + mutate: endSession, + isPending, + isSuccess, + } = useMutation({ mutationKey: ["sessions", session.id], mutationFn: () => api.put(`sessions/${session.id}`, { json: { status: "ending" } }), @@ -22,7 +27,6 @@ function EndSessionModal({ session }: { session: Session }) { }, onSuccess: () => { queryClient.invalidateQueries({ queryKey: ["last-sessions"] }); - setModal(null); }, }); @@ -48,31 +52,45 @@ function EndSessionModal({ session }: { session: Session }) {

- Точно хотите завершить сеанс? + {isSuccess + ? "Доступен отчет по встрече" + : "Точно хотите завершить сеанс?"}

- Текущий сеанс будет завершен немедленно + {isSuccess + ? "Вы можете просмотреть отчет или создать новый сеанс, перейдя на главную страницу" + : "Текущий сеанс будет завершен немедленно"}

diff --git a/src/pages/LoginPage.tsx b/src/pages/LoginPage.tsx index 4ca0f5b..08bde66 100644 --- a/src/pages/LoginPage.tsx +++ b/src/pages/LoginPage.tsx @@ -71,7 +71,7 @@ function LoginPage() { />
-