From 8b098ce276c3bc6473ba4d43cc22c773802821ed Mon Sep 17 00:00:00 2001 From: Aleksey Panivanov Date: Sun, 29 Oct 2023 23:40:25 +0500 Subject: [PATCH] upd --- .env | 4 ++-- src/ScheduledPage.tsx | 26 +++++++++++++++++++------- vite.config.ts | 4 ++-- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/.env b/.env index 72a191e..6fe1354 100644 --- a/.env +++ b/.env @@ -1,5 +1,5 @@ # VITE_COORD_URL=http://localhost:4000 VITE_COORD_URL=https://coord.graff.tech -# VITE_CRM_API_URL=http://localhost:3001 -VITE_CRM_API_URL=http://192.168.1.170:3001 +VITE_CRM_API_URL=http://localhost:3001 +# VITE_CRM_API_URL=http://192.168.1.170:3001 # VITE_CRM_API_URL=https://crm.stream.graff.tech/api \ No newline at end of file diff --git a/src/ScheduledPage.tsx b/src/ScheduledPage.tsx index d09cdf9..c00961f 100644 --- a/src/ScheduledPage.tsx +++ b/src/ScheduledPage.tsx @@ -1,5 +1,10 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable react-hooks/exhaustive-deps */ +import { + differenceInMilliseconds, + isAfter, + parseISO, +} from "date-fns"; import ky from "ky"; import { useEffect, useState } from "react"; import Countdown from "react-countdown"; @@ -15,14 +20,21 @@ function ScheduledPage() { async function connect() { try { - const result: any = await ky.get( - `${import.meta.env.VITE_CRM_API_URL}/scheduled_sessions/${ - params.sessionId - }` - ); + const result: any = await ky + .get( + `${import.meta.env.VITE_CRM_API_URL}/scheduled_sessions/${ + params.sessionId + }` + ) + .json(); - if (!result.id) { - setCountdownSeconds(result.countdownSeconds); + if (isAfter(parseISO(result.startAt), new Date())) { + const diffMs = differenceInMilliseconds( + parseISO(result.startAt), + new Date() + ); + + setCountdownSeconds(diffMs); return; } diff --git a/vite.config.ts b/vite.config.ts index 79ac0eb..5bc98b0 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -5,9 +5,9 @@ import react from "@vitejs/plugin-react-swc"; export default defineConfig({ plugins: [react()], server: { - port: 5000, + port: 5001, }, preview: { - port: 5000, + port: 5001, }, });