diff --git a/frontend/src/app/kiosk/page.tsx b/frontend/src/app/kiosk/page.tsx index 2485b22..7bc2a50 100644 --- a/frontend/src/app/kiosk/page.tsx +++ b/frontend/src/app/kiosk/page.tsx @@ -7,10 +7,12 @@ import { TriState } from "@/types/state"; import { Voucher } from "@/types/voucher"; import { api } from "@/utils/api"; import { formatCode } from "@/utils/format"; +import { useGlobal } from "@/contexts/GlobalContext"; export default function KioskPage() { const [voucher, setVoucher] = useState(null); const [state, setState] = useState(null); + const { wifiConfig, wifiString } = useGlobal(); const load = useCallback(async () => { if (state === "loading") return; @@ -38,7 +40,7 @@ export default function KioskPage() { return () => window.removeEventListener("vouchersUpdated", load); }, [load]); - function renderContent() { + const renderContent = useCallback(() => { switch (state) { case null: case "loading": @@ -50,10 +52,13 @@ export default function KioskPage() { ); case "ok": + const qrAvailable = wifiConfig && wifiString; return ( -
- -
+
+ {qrAvailable && } +

Voucher Code

@@ -64,7 +69,7 @@ export default function KioskPage() {
); } - } + }, [voucher, state, wifiConfig, wifiString]); return (
{renderContent()}
diff --git a/frontend/src/components/Header.tsx b/frontend/src/components/Header.tsx index 1a7ee3c..fde541f 100644 --- a/frontend/src/components/Header.tsx +++ b/frontend/src/components/Header.tsx @@ -1,6 +1,6 @@ "use client"; -import { useEffect, useRef, useState } from "react"; +import { useEffect, useMemo, useRef, useState } from "react"; import ThemeSwitcher from "@/components/utils/ThemeSwitcher"; import WifiQrModal from "@/components/modals/WifiQrModal"; import { useGlobal } from "@/contexts/GlobalContext"; @@ -9,8 +9,12 @@ import { useRouter } from "next/navigation"; export default function Header() { const [showWifi, setShowWifi] = useState(false); const headerRef = useRef(null); - const { wifiConfig } = useGlobal(); const router = useRouter(); + const { wifiConfig, wifiString } = useGlobal(); + const qrAvailable: boolean = useMemo( + () => !!(wifiConfig && wifiString), + [wifiConfig, wifiString], + ); useEffect(() => { // Set initial height and update on resize @@ -50,7 +54,7 @@ export default function Header() {
- {showWifi && wifiConfig && ( + {qrAvailable && showWifi && ( setShowWifi(false)} /> )}