Newer
Older
taehui / qwilight-fe / src / hall / useGetTotalBandHall.ts
@Taehui Taehui on 16 Mar 958 bytes 2024-03-17 오전 8:09
import { useHallStore } from "@/Stores";
import { formatText } from "@/Utility";

import { wwwAXIOS } from "@/Www";
import { GetHallAPI } from "@/wwwAPI";
import { useQuery } from "@tanstack/react-query";
import { useTranslations } from "next-intl";
import { useIsPath } from "taehui-ts/fe-utility";

export default function useGetTotalBandHall() {
  const { tabPosition, totalTabPosition } = useHallStore();

  const t = useTranslations();

  const isPath = useIsPath();

  return useQuery<
    {
      avatarID: string;
      avatarName: string;
      text: string;
    }[]
  >({
    enabled: tabPosition === 0 && totalTabPosition === 3 && isPath("/hall"),
    queryKey: ["totalBandHall"],
    queryFn: async () => {
      const { data } = await wwwAXIOS.get<GetHallAPI[]>("/hall/totalBand");
      return data.map((hall) => ({
        ...hall,
        text: t("textBand", { value: formatText(hall.value) }),
      }));
    },
    initialData: [],
  });
}