Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

890 B
Raw Blame
import { Folder } from "@/lib/types";
import { useRouterStuff } from "@dub/ui";
import { fetcher } from "@dub/utils";
import useSWR, { SWRConfiguration } from "swr";
import useWorkspace from "./use-workspace";

export default function useFolders({
  includeParams = [],
  query,
  options,
}: {
  includeParams?: string[];
  query?: Record<string, any>;
  options?: SWRConfiguration;
} = {}) {
  const { id: workspaceId, plan } = useWorkspace();
  const { getQueryString } = useRouterStuff();

  const {
    data: folders,
    isValidating,
    isLoading,
  } = useSWR<Folder[]>(
    workspaceId
      ? `/api/folders${getQueryString(
          { workspaceId, ...query },
          { include: includeParams },
        )}`
      : null,
    fetcher,
    {
      dedupingInterval: 60000,
      ...options,
    },
  );

  return {
    folders,
    loading: isLoading,
    isValidating,
  };
}