{"version":3,"file":"WrapperStatsQuery-UUMI7iuR.js","sources":["../../../frontend/src/Hooks/useIntersectionObserver.ts","../../../frontend/src/Hooks/useStatsQuery.ts","../../../frontend/src/Components/Stats/Charts/WrapperStatsQuery.tsx"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nconst useIntersectionObserver = (reference: any) => {\n const [isVisible, setIsVisible] = useState(false);\n\n useEffect(() => {\n const handleIntersect = (entries: any, observer: any) => {\n if (entries[0].isIntersecting) {\n setIsVisible(true);\n observer.unobserve(entries[0].target);\n observer.disconnect();\n }\n };\n\n // Create the observer, passing in the callback\n const observer = new IntersectionObserver(handleIntersect);\n\n // If we have a ref value, start observing it\n if (reference) {\n observer.observe(reference.current);\n }\n\n // If unmounting, disconnect the observer\n return () => observer.disconnect();\n }, [reference]);\n\n return isVisible;\n};\n\nexport default useIntersectionObserver;\n","import { useQuery } from 'react-query';\n\nimport { getStats, getDashboardStats } from '../Services/Api';\n\nconst useStatsQuery = (\n key: any,\n {\n postId,\n newsletterId,\n statsSlug,\n from,\n to,\n dashboard = false,\n interval,\n dimensionId,\n scope,\n }: any,\n useQueryProps?: any,\n) => {\n const { data, ...params } = useQuery(\n [key, postId, statsSlug, from, to, interval, dimensionId].filter((n) => n),\n () => {\n if (dashboard) {\n return getDashboardStats(\n postId,\n newsletterId,\n statsSlug,\n from,\n to,\n interval,\n dimensionId,\n scope,\n );\n }\n\n return getStats(postId, statsSlug, from, to, interval);\n },\n {\n refetchOnWindowFocus: false,\n ...useQueryProps,\n },\n );\n\n return {\n data: data?.data || [],\n ...params,\n };\n};\n\nexport default useStatsQuery;\n","import React, { useRef, useState } from 'react';\nimport { useIntl } from 'react-intl';\n\nimport useIntersectionObserver from '../../../Hooks/useIntersectionObserver';\nimport useStatsQuery from '../../../Hooks/useStatsQuery';\n\nconst convertDateRangeToISOString = (dateRange: any) => {\n const from = new Date(dateRange[0]);\n const to = new Date(dateRange[1]);\n\n const fromDate = new Date(from);\n fromDate.setUTCHours(0, 0, 0, 0);\n\n const toDate = new Date(to);\n toDate.setUTCHours(23, 59, 59, 999);\n\n return [fromDate.toISOString(), toDate.toISOString()];\n};\n\nfunction WrapperStatsQuery({\n statsSlug,\n i18nKeyForSubtitle,\n children,\n defaultInterval,\n from,\n enableDateRange,\n dateRangeProps,\n ...props\n}: any) {\n const intl = useIntl();\n const myRef = useRef(null);\n const isSectionVisible = useIntersectionObserver(myRef);\n const [interval, setInterval] = useState(defaultInterval);\n const [dateRange, setDateRange] = React.useState([\n from || new Date().setMonth(new Date().getMonth() - 3),\n new Date(),\n ]);\n const [fromDateTime, toDateTime] = convertDateRangeToISOString(dateRange);\n\n const { data, isFetching } = useStatsQuery(\n statsSlug,\n {\n statsSlug,\n interval,\n from: enableDateRange ? fromDateTime : undefined,\n to: enableDateRange ? toDateTime : undefined,\n ...props,\n },\n {\n enabled: isSectionVisible,\n },\n );\n\n return (\n
\n {React.cloneElement(children, {\n data,\n loading: isFetching,\n setInterval,\n interval,\n enableDateRange,\n dateRangeProps: {\n dateRange,\n setDateRange,\n ...dateRangeProps,\n },\n subtitle: i18nKeyForSubtitle\n ? intl.formatMessage({ id: i18nKeyForSubtitle }, { count: data?.count || 0 })\n : undefined,\n })}\n
\n );\n}\n\nexport default WrapperStatsQuery;\n"],"names":["useIntersectionObserver","reference","_useState","useState","_useState2","_slicedToArray","isVisible","setIsVisible","useEffect","handleIntersect","entries","observer","isIntersecting","unobserve","target","disconnect","IntersectionObserver","observe","current","useStatsQuery","key","_ref","useQueryProps","postId","newsletterId","statsSlug","from","to","_ref$dashboard","dashboard","interval","dimensionId","scope","_useQuery","useQuery","filter","n","getDashboardStats","getStats","_objectSpread","refetchOnWindowFocus","data","params","_objectWithoutProperties","_excluded","convertDateRangeToISOString","dateRange","Date","fromDate","setUTCHours","toDate","toISOString","WrapperStatsQuery","i18nKeyForSubtitle","children","defaultInterval","enableDateRange","dateRangeProps","props","intl","useIntl","myRef","useRef","isSectionVisible","setInterval","_React$useState","React","setMonth","getMonth","_React$useState2","setDateRange","_convertDateRangeToIS","_convertDateRangeToIS2","fromDateTime","toDateTime","_useStatsQuery","undefined","enabled","isFetching","createElement","ref","cloneElement","loading","subtitle","formatMessage","id","count"],"mappings":";u1BAEMA,IAAAA,EAA0B,SAACC,EAAmB,CAClD,IAAAC,EAAkCC,EAAAA,SAAS,EAAK,EAACC,EAAAC,EAAAH,EAAA,CAAA,EAA1CI,EAASF,EAAA,CAAA,EAAEG,EAAYH,EAAA,CAAA,EAE9BI,OAAAA,EAAAA,UAAU,UAAM,CACd,IAAMC,EAAkB,SAACC,EAAcC,EAAkB,CACnDD,EAAQ,CAAC,EAAEE,iBACbL,EAAa,EAAI,EACjBI,EAASE,UAAUH,EAAQ,CAAC,EAAEI,MAAM,EACpCH,EAASI,WAAW,EAExB,EAGMJ,EAAW,IAAIK,qBAAqBP,CAAe,EAGzD,OAAIR,GACOgB,EAAAA,QAAQhB,EAAUiB,OAAO,EAI7B,UAAA,CAAA,OAAMP,EAASI,WAAW,CAAC,CAAA,EACjC,CAACd,CAAS,CAAC,EAEPK,CACT,ymDCvBA,IAAMa,GAAgB,SACpBC,EAAQC,EAYRC,EACG,CAAA,IAXDC,EAAMF,EAANE,OACAC,EAAYH,EAAZG,aACAC,EAASJ,EAATI,UACAC,EAAIL,EAAJK,KACAC,EAAEN,EAAFM,GAAEC,EAAAP,EACFQ,UAAAA,EAASD,IAAG,OAAA,GAAKA,EACjBE,EAAQT,EAARS,SACAC,EAAWV,EAAXU,YACAC,EAAKX,EAALW,MAIFC,EAA4BC,EAC1B,CAACd,EAAKG,EAAQE,EAAWC,EAAMC,EAAIG,EAAUC,CAAW,EAAEI,OAAO,SAACC,EAAC,CAAKA,OAAAA,CAAC,CAAA,EACzE,UAAM,CACJ,OAAIP,EACKQ,EACLd,EACAC,EACAC,EACAC,EACAC,EACAG,EACAC,EACAC,CACF,EAGKM,EAASf,EAAQE,EAAWC,EAAMC,EAAIG,CAAQ,GACtDS,EAAA,CAECC,qBAAs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