feat: enhance TableSelector with automatic selection logic and update CreateSessionModal and EndSessionModal for improved session handling and user feedback
This commit is contained in:
@@ -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 (
|
||||
<div className="flex gap-[0.556vw] overflow-x-auto -mx-[1.111vw] pl-[1.111vw] [scrollbar-width:none]">
|
||||
{tables.map((table) => (
|
||||
|
||||
@@ -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: () =>
|
||||
|
||||
@@ -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 }) {
|
||||
<div className="p-[1.389vw] flex flex-col gap-[1.667vw]">
|
||||
<div className="flex flex-col gap-[0.556vw]">
|
||||
<p className="title-m font-medium">
|
||||
Точно хотите завершить сеанс?
|
||||
{isSuccess
|
||||
? "Доступен отчет по встрече"
|
||||
: "Точно хотите завершить сеанс?"}
|
||||
</p>
|
||||
<p className="caption-m font-medium text-[#BDBDBD]">
|
||||
Текущий сеанс будет завершен немедленно
|
||||
{isSuccess
|
||||
? "Вы можете просмотреть отчет или создать новый сеанс, перейдя на главную страницу"
|
||||
: "Текущий сеанс будет завершен немедленно"}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-col gap-[0.556vw]">
|
||||
<Button
|
||||
size="large"
|
||||
variant="critical"
|
||||
variant={isSuccess ? "cta" : "critical"}
|
||||
className="w-full"
|
||||
onClick={() => endSession()}
|
||||
onClick={() => {
|
||||
if (isSuccess) {
|
||||
setModal(<SessionModal session={session} />);
|
||||
} else {
|
||||
endSession();
|
||||
}
|
||||
}}
|
||||
disabled={isPending}
|
||||
>
|
||||
Завершить сеанс
|
||||
{isSuccess ? "Перейти к отчету" : "Завершить сеанс"}
|
||||
</Button>
|
||||
<Button
|
||||
size="large"
|
||||
variant="primary"
|
||||
className="w-full"
|
||||
onClick={() =>
|
||||
setModal(<CurrentSessionModal session={session} />)
|
||||
}
|
||||
onClick={() => {
|
||||
if (isSuccess) {
|
||||
setModal(null);
|
||||
} else {
|
||||
setModal(<CurrentSessionModal session={session} />);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Отменить
|
||||
{isSuccess ? "На главную" : "Отменить"}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -71,7 +71,7 @@ function LoginPage() {
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-3">
|
||||
<Button type="button" variant="secondary">
|
||||
<Button type="submit" variant="secondary">
|
||||
Забыли пароль?
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user