import { builder, PublicPageResponse } from '@tempi/core-renderer'; import { useGlobalData } from 'contexts'; import useSWR from 'swr'; export interface UsePagePublicInterface { slug: string; hostname: string; envs: any; requestUUID?: string; languageCode?: string; subpath?: string; prefixLangUrl?: string; password?: string | null; errorCode?: string; } export const usePagePublic = ({ slug, hostname, envs, languageCode, password, }: UsePagePublicInterface) => { if (!envs['REVALIDATE_PAGE_FLAG']) return {}; const { isMobile } = useGlobalData(); const device = isMobile ? 'mobile' : 'desktop'; const { data, mutate, error, isLoading } = useSWR( [`/page?slug=${slug}&device=${device}`, password], async () => { builder.init(hostname, { env: envs['ENV'], }); return builder.getPublicPageV2({ slug, device, languageCode, password }); }, { revalidateOnFocus: false, }, ); return { page: data as PublicPageResponse, mutatePage: mutate, error, isLoading, }; };