Newer
Older
taehui / qwilight-fe / src / app / [language] / hall / query / useGetTotalStandHall.ts
@Taehui Taehui on 17 Mar 963 bytes 2024-03-17 오후 2:12
import { Hall } from "@/app/[language]/hall/type";
import { useHallStore } from "@/store/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 useGetTotalStandHall() {
  const { tabPosition, totalTabPosition } = useHallStore();

  const t = useTranslations();

  const isPath = useIsPath();

  return useQuery<Hall[]>({
    enabled: tabPosition === 0 && totalTabPosition === 2 && isPath("/hall"),
    queryKey: ["totalStandHall"],
    queryFn: async () => {
      const { data } = await wwwAPI.get<GetHallAPI[]>("/hall/totalStand");
      return data.map((hall) => ({
        ...hall,
        text: t("textStand", { value: formatText(hall.value) }),
      }));
    },
    initialData: [],
  });
}