import React, { Fragment, useEffect, ReactElement } from "react"; import { useRouter } from "next/router"; import { observer } from "mobx-react-lite"; import { Tab } from "@headlessui/react"; // mobx store import { useMobxStore } from "lib/mobx/store-provider"; // services import { TrackEventService } from "services/track_event.service"; // layouts import { AppLayout } from "layouts/app-layout"; // components import { CustomAnalytics, ScopeAndDemand } from "components/analytics"; import { WorkspaceAnalyticsHeader } from "components/headers"; import { EmptyState } from "components/common"; // icons import { Plus } from "lucide-react"; // assets import emptyAnalytics from "public/empty-state/analytics.svg"; // constants import { ANALYTICS_TABS } from "constants/analytics"; // type import { NextPageWithLayout } from "types/app"; const trackEventService = new TrackEventService(); const AnalyticsPage: NextPageWithLayout = observer(() => { // router const router = useRouter(); const { workspaceSlug } = router.query; // store const { project: projectStore, user: userStore, commandPalette: commandPaletteStore } = useMobxStore(); const user = userStore.currentUser; const projects = workspaceSlug ? projectStore.projects[workspaceSlug?.toString()] : null; const trackAnalyticsEvent = (tab: string) => { if (!user) return; const eventPayload = { workspaceSlug: workspaceSlug?.toString(), }; const eventType = tab === "scope_and_demand" ? "WORKSPACE_SCOPE_AND_DEMAND_ANALYTICS" : "WORKSPACE_CUSTOM_ANALYTICS"; trackEventService.trackAnalyticsEvent(eventPayload, eventType, user); }; useEffect(() => { if (!workspaceSlug) return; if (user && workspaceSlug) trackEventService.trackAnalyticsEvent( { workspaceSlug: workspaceSlug?.toString() }, "WORKSPACE_SCOPE_AND_DEMAND_ANALYTICS", user ); }, [user, workspaceSlug]); return ( <> {projects && projects.length > 0 ? (