+
{session.owner.fullname}
+
Клиент: {session.client.name} •
{session.app.name}
diff --git a/src/components/icons/FlashIcon.tsx b/src/components/icons/FlashIcon.tsx
index bfa2724..85995c5 100644
--- a/src/components/icons/FlashIcon.tsx
+++ b/src/components/icons/FlashIcon.tsx
@@ -1,15 +1,13 @@
function FlashIcon() {
return (
);
diff --git a/src/components/modals/CreateSessionModal.tsx b/src/components/modals/CreateSessionModal.tsx
index babf83e..a6634db 100644
--- a/src/components/modals/CreateSessionModal.tsx
+++ b/src/components/modals/CreateSessionModal.tsx
@@ -28,6 +28,7 @@ export default function CreateSessionModal({
targetServer
);
const [selectedApp, setSelectedApp] = useState
(null);
+
const queryClient = useQueryClient();
const { mutate: createClient } = useMutation({
@@ -56,8 +57,9 @@ export default function CreateSessionModal({
})
.json();
},
- onSuccess: () => {
+ onMutate: () => {
queryClient.invalidateQueries({ queryKey: ["sessions"] });
+ queryClient.invalidateQueries({ queryKey: ["last-started"] });
queryClient.invalidateQueries({ queryKey: ["servers"] });
setModal(null);
},
@@ -121,7 +123,7 @@ export default function CreateSessionModal({
Выберите параметры сеанса
- {selectedServer?.apps?.length && selectedServer?.apps?.length > 0 && (
+ {selectedServer?.apps && selectedServer?.apps?.length > 0 && (
queryClient.invalidateQueries({ queryKey: ["sessions"] }),
});
- const { data: currentServer } = useQuery({
+ const { data: currentSession } = useQuery({
queryKey: ["sessions", server.sessions?.[0]?.id],
queryFn: () =>
api.get(`sessions/${server.sessions?.[0]?.id}`).json(),
});
- console.log(currentServer);
+ console.log(currentSession);
+
+ const [now, setNow] = useState(Date.now());
+
+ useEffect(() => {
+ const interval = setInterval(() => {
+ setNow(Date.now());
+ }, 1000);
+ return () => clearInterval(interval);
+ }, []);
+
+ useEffect(() => {
+ if (!currentSession) return;
+ const duration = intervalToDuration({
+ start: currentSession.createdAt,
+ end: now,
+ });
+ const hours = (duration.hours || 0).toString().padStart(2, "0");
+ const minutes = (duration.minutes || 0).toString().padStart(2, "0");
+ const seconds = (duration.seconds || 0).toString().padStart(2, "0");
+ console.log(`${hours}:${minutes}:${seconds}`);
+ }, [currentSession, now]);
+
+ if (!currentSession) return null;
return (
@@ -41,7 +66,23 @@ function CurrentSessionModal({ server }: { server: IServer }) {
{server.name}
- Сеанс идёт 24:05
+ Сеанс идёт{" "}
+ {(() => {
+ const duration = intervalToDuration({
+ start: currentSession.createdAt,
+ end: now,
+ });
+ const hours = (duration.hours || 0)
+ .toString()
+ .padStart(2, "0");
+ const minutes = (duration.minutes || 0)
+ .toString()
+ .padStart(2, "0");
+ const seconds = (duration.seconds || 0)
+ .toString()
+ .padStart(2, "0");
+ return `${hours}:${minutes}:${seconds}`;
+ })()}
@@ -57,10 +98,12 @@ function CurrentSessionModal({ server }: { server: IServer }) {
Клиент
-
{server.client?.name}
+
+ {currentSession.client.name}
+
- {!server.client?.email && (
+ {!currentSession.client.email && (
Добавьте email
@@ -77,7 +120,9 @@ function CurrentSessionModal({ server }: { server: IServer }) {
Менеджер:
-
{server.owner?.fullname}
+
+ {currentSession.owner.fullname}
+
diff --git a/src/pages/DashboardPage.tsx b/src/pages/DashboardPage.tsx
index 1ada217..70f2d5e 100644
--- a/src/pages/DashboardPage.tsx
+++ b/src/pages/DashboardPage.tsx
@@ -43,25 +43,25 @@ function DashboardPage() {
// }
return (
-
-
-
-
-
Интерактивные столы
+
+
+
+
+
Интерактивные столы
-
+
{servers?.map((server) => (
))}
-
-
-
Последние сеансы
-
-
+
+
+
Последние сеансы
+
+
{sessions
?.filter((session) => session.status === "ended")
.map((session) => (
@@ -69,12 +69,12 @@ function DashboardPage() {
))}
Смотреть всё
-
+
diff --git a/src/types/IServer.ts b/src/types/IServer.ts
index f9f6bd4..03b3b0f 100644
--- a/src/types/IServer.ts
+++ b/src/types/IServer.ts
@@ -1,6 +1,4 @@
import { IApp } from "./IApp";
-import { IClient } from "./IClient";
-import { IOwner } from "./IOwner";
import { ISession } from "./ISession";
export interface IServer {
@@ -12,6 +10,4 @@ export interface IServer {
sessions?: ISession[];
apps?: IApp[];
status: "online" | "offline";
- client?: IClient;
- owner?: IOwner;
}
diff --git a/src/types/ISession.ts b/src/types/ISession.ts
index 15bda42..7461e3b 100644
--- a/src/types/ISession.ts
+++ b/src/types/ISession.ts
@@ -14,4 +14,5 @@ export interface ISession {
client: IUser;
app: IApp;
owner: IOwner;
+ createdAt: Date;
}