"use client"; import React, { useState } from "react"; import { useFormatter, useTranslations } from "next-intl"; import dynamic from "next/dynamic"; import { IoAdd } from "react-icons/io5"; import { Button, buttonVariants } from "@/components/Button"; import InfoMessage, { InfoMessageType } from "@/components/InfoMessage"; import { Modal } from "@/components/Modal"; import { Spinner } from "@/components/Spinner"; import { useZones } from "@/hooks/useZones"; import { deleteZone } from "@/server/deleteZone"; import { TimeControl } from "@/types"; import { Link, useRouter } from "@/utils/routing"; const ZoneThumbnail = dynamic(() => import("./components/ZoneThumbnail"), { ssr: false, loading: () =>
, }); const Zones = () => { const t = useTranslations("Zones"); const at = useTranslations("App"); const router = useRouter(); const format = useFormatter(); const [deletingZoneId, setDeletingZoneId] = useState(null); const [responseMessage, setResponseMessage] = useState<{ type: InfoMessageType; message: string; } | null>(null); const { zones, isFetching, refetch } = useZones(); const onDelete = async () => { try { if (!deletingZoneId) return; await deleteZone({ id: deletingZoneId }); await refetch(); setDeletingZoneId(null); router.push("/zones"); } catch (err: unknown) { console.log(err); setResponseMessage({ type: "error", message: t("createFailure"), }); } }; return ( <>

{t("title")}

{t("info")}

{isFetching ? (
) : (
{zones?.map((zone) => { const notifications = [ ...(zone.classicNotifications ? [TimeControl.Classic] : []), ...(zone.rapidNotifications ? [TimeControl.Rapid] : []), ...(zone.blitzNotifications ? [TimeControl.Blitz] : []), ...(zone.otherNotifications ? [TimeControl.Other] : []), ]; const notificationsList = format.list( notifications.map((tc) => at("timeControlEnumInline", { tc })), { type: "conjunction" }, ); return (

{zone.name}

{zone.name}

{notifications.length === 0 ? t("noNotifications") : t.rich("withNotifications", { list: notificationsList, b: (str) => {str}, })}
{at("editButton")}
); })}
)}
{t("addZoneButton")}
setDeletingZoneId(null)} title={t("deleteZoneTitle")} subTitle={t("deleteZoneInfo")} > {responseMessage && ( setResponseMessage(null)} /> )}
); }; export default Zones;