Newer
Older
taehui / qwilight-fe / src / app / [language] / hall / query / useGetAtBandHall.ts
import { Hall } from "@/app/[language]/hall/type";
import { useHallStore } from "@/state/Stores";
import { GetHallAPI } from "@/type/wwwAPI";
import { formatText } from "@/utilities/Utility";
import { wwwAPI } from "@/utilities/wwwAPI";
import { useQuery } from "@tanstack/react-query";
import { useTranslations } from "next-intl";
import { useIsPath } from "taehui-ts/fe-utilities";

export default function useGetAtBandHall() {
  const { tabPosition, atTabPosition } = useHallStore();

  const t = useTranslations();

  const isPath = useIsPath();

  return useQuery<Hall[]>({
    enabled: tabPosition === 1 && atTabPosition === 3 && isPath("/hall"),
    queryKey: ["atBandHall"],
    queryFn: async () => {
      const { data } = await wwwAPI.get<GetHallAPI[]>("/hall/atBand");
      return data.map((hall) => ({
        ...hall,
        text: t("textBand", { value: formatText(hall.value) }),
      }));
    },
    initialData: [],
  });
}