restart session logic

This commit is contained in:
2025-06-09 18:00:12 +05:00
parent a4a3fde940
commit 55f4ec479b
5 changed files with 71 additions and 38 deletions
+48 -20
View File
@@ -18,9 +18,9 @@ interface Props {
export default function CreateSessionModal({ targetServerId }: Props) {
const { setModal } = useModalStore();
const [name, setName] = useState("");
const [phone, setPhone] = useState("");
const [email, setEmail] = useState("");
const [name, setName] = useState<string | null>(null);
const [phone, setPhone] = useState<string | null>(null);
const [email, setEmail] = useState<string | null>(null);
const [isSessionExists, setIsSessionExists] = useState(false);
const queryClient = useQueryClient();
@@ -120,26 +120,54 @@ export default function CreateSessionModal({ targetServerId }: Props) {
}
endSession(undefined, {
onSuccess: () => {
createClient(undefined, {
onSuccess: (client) => {
createSession({
clientId: client.id,
serverId: selectedServer.id,
appId: selectedApp.id,
});
},
onError: (error) => {
console.log(error);
},
});
},
// onSuccess: () => {
// createClient(undefined, {
// onSuccess: (client) => {
// createSession({
// clientId: client.id,
// serverId: selectedServer.id,
// appId: selectedApp.id,
// });
// },
// onError: (error) => {
// console.log(error);
// },
// });
// },
onError: (error) => {
console.log("Ошибка при завершении сессии:", error);
},
});
}
useEffect(() => {
console.log(servers, selectedServer, selectedApp, isSessionExists);
if (
selectedServer &&
servers?.find((server) => server.id === selectedServer?.id)?.sessions?.[0]
?.status === "ended" &&
selectedApp &&
isSessionExists
) {
createClient(undefined, {
onSuccess: (client) => {
createSession({
clientId: client.id,
serverId: selectedServer?.id,
appId: selectedApp.id,
});
},
});
}
}, [
selectedApp,
servers,
createClient,
createSession,
isSessionExists,
selectedServer,
]);
const ref = useRef<HTMLFormElement>(null);
return (
@@ -162,20 +190,20 @@ export default function CreateSessionModal({ targetServerId }: Props) {
<p className="title-s font-medium">Укажите данные клиента</p>
<div className="flex flex-col gap-y-[0.556vw]">
<NewInput
value={phone}
value={phone || ""}
onChange={(e) => setPhone(e.target.value)}
placeholder="Номер телефона"
required
/>
<NewInput
value={name}
value={name || ""}
onChange={(e) => setName(e.target.value)}
placeholder="Имя"
required
/>
<NewInput
type="email"
value={email}
value={email || ""}
onChange={(e) => setEmail(e.target.value)}
placeholder="Электронная почта"
/>
@@ -103,7 +103,7 @@ function CurrentSessionModal({ session }: { session: ISession }) {
</div>
<div className="flex flex-col gap-[0.833vw]">
<h2 className="title-s font-medium">Детали</h2>
<div>
<div className="flex flex-col gap-[0.556vw]">
<div className="flex gap-[0.556vw]">
<p className="caption-s font-medium text-[#BDBDBD]">Менеджер:</p>
<p className="caption-s font-medium">{session.owner.fullname}</p>
@@ -118,6 +118,7 @@ function CurrentSessionModal({ session }: { session: ISession }) {
</div>
<div className="flex flex-col gap-[0.556vw]">
<NewButton
size="large"
variant="critical"
className="w-full"
onClick={() => {
@@ -128,6 +129,7 @@ function CurrentSessionModal({ session }: { session: ISession }) {
Завершить сеанс
</NewButton>
<NewButton
size="large"
variant="primary"
className="w-full"
onClick={() => setModal(null)}