diff --git a/web/components/analytics/custom-analytics/custom-analytics.tsx b/web/components/analytics/custom-analytics/custom-analytics.tsx index d04733b56..3152596c8 100644 --- a/web/components/analytics/custom-analytics/custom-analytics.tsx +++ b/web/components/analytics/custom-analytics/custom-analytics.tsx @@ -1,49 +1,51 @@ import { useRouter } from "next/router"; - -import { mutate } from "swr"; - -// react-hook-form -import { Control, UseFormSetValue } from "react-hook-form"; +import useSWR, { mutate } from "swr"; +import { Control, UseFormSetValue, useForm } from "react-hook-form"; // hooks import useProjects from "hooks/use-projects"; // components -import { - AnalyticsGraph, - AnalyticsSelectBar, - AnalyticsSidebar, - AnalyticsTable, -} from "components/analytics"; +import { AnalyticsGraph, AnalyticsSelectBar, AnalyticsSidebar, AnalyticsTable } from "components/analytics"; // ui import { Loader, PrimaryButton } from "components/ui"; // helpers import { convertResponseToBarGraphData } from "helpers/analytics.helper"; // types -import { IAnalyticsParams, IAnalyticsResponse, ICurrentUserResponse } from "types"; +import { IAnalyticsParams, IAnalyticsResponse, IUser } from "types"; // fetch-keys import { ANALYTICS } from "constants/fetch-keys"; +// services +import analyticsService from "services/analytics.service"; type Props = { - analytics: IAnalyticsResponse | undefined; - analyticsError: any; - params: IAnalyticsParams; - control: Control; - setValue: UseFormSetValue; fullScreen: boolean; - user: ICurrentUserResponse | undefined; + user?: IUser | undefined; }; -export const CustomAnalytics: React.FC = ({ - analytics, - analyticsError, - params, - control, - setValue, - fullScreen, - user, -}) => { +const defaultValues: IAnalyticsParams = { + x_axis: "priority", + y_axis: "issue_count", + segment: null, + project: null, +}; + +export const CustomAnalytics: React.FC = ({ fullScreen, user }) => { const router = useRouter(); const { workspaceSlug, projectId } = router.query; + const { control, watch, setValue } = useForm({ defaultValues }); + + const params: IAnalyticsParams = { + x_axis: watch("x_axis"), + y_axis: watch("y_axis"), + segment: watch("segment"), + project: watch("project"), + }; + + const { data: analytics, error: analyticsError } = useSWR( + workspaceSlug ? ANALYTICS(workspaceSlug.toString(), params) : null, + workspaceSlug ? () => analyticsService.getAnalytics(workspaceSlug.toString(), params) : null + ); + const isProjectLevel = projectId ? true : false; const yAxisKey = params.y_axis === "issue_count" ? "count" : "estimate"; @@ -52,11 +54,7 @@ export const CustomAnalytics: React.FC = ({ const { projects } = useProjects(); return ( -
+
= ({ yAxisKey={yAxisKey} fullScreen={fullScreen} /> - +
) : (
diff --git a/web/components/headers/workspace-analytics.tsx b/web/components/headers/workspace-analytics.tsx new file mode 100644 index 000000000..34f122b52 --- /dev/null +++ b/web/components/headers/workspace-analytics.tsx @@ -0,0 +1,33 @@ +import { useRouter } from "next/router"; +import { ArrowLeft } from "lucide-react"; +// ui +import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs"; + +export const WorkspaceAnalyticsHeader = () => { + const router = useRouter(); + + return ( + <> +
+
+
+ +
+
+ + + +
+
+
+ + ); +}; diff --git a/web/layouts/app-layout/header.tsx b/web/layouts/app-layout/header.tsx deleted file mode 100644 index e69de29bb..000000000 diff --git a/web/layouts/app-layout/index.ts b/web/layouts/app-layout/index.ts index 8a235ad00..c4bfd4db3 100644 --- a/web/layouts/app-layout/index.ts +++ b/web/layouts/app-layout/index.ts @@ -1,3 +1,2 @@ export * from "./layout"; export * from "./sidebar"; -export * from "./header"; diff --git a/web/pages/[workspaceSlug]/analytics.tsx b/web/pages/[workspaceSlug]/analytics.tsx index e088e4106..c3035d796 100644 --- a/web/pages/[workspaceSlug]/analytics.tsx +++ b/web/pages/[workspaceSlug]/analytics.tsx @@ -5,10 +5,7 @@ import { useRouter } from "next/router"; import useSWR from "swr"; // react-hook-form -import { useForm } from "react-hook-form"; -// hooks -import useUserAuth from "hooks/use-user-auth"; -import useProjects from "hooks/use-projects"; + // headless ui import { Tab } from "@headlessui/react"; // services @@ -29,36 +26,25 @@ import emptyAnalytics from "public/empty-state/analytics.svg"; import { IAnalyticsParams } from "types"; // fetch-keys import { ANALYTICS } from "constants/fetch-keys"; - -const defaultValues: IAnalyticsParams = { - x_axis: "priority", - y_axis: "issue_count", - segment: null, - project: null, -}; +import { AppLayout } from "layouts/app-layout"; +import { useMobxStore } from "lib/mobx/store-provider"; +import { observer } from "mobx-react-lite"; +import { WorkspaceAnalyticsHeader } from "components/headers/workspace-analytics"; const tabsList = ["Scope and Demand", "Custom Analytics"]; -const Analytics = () => { +const AnalyticsPage = observer(() => { + // router const router = useRouter(); const { workspaceSlug } = router.query; + // store + const { workspace: workspaceStore, project: projectStore, user: userStore } = useMobxStore(); - const { user } = useUserAuth(); - const { projects } = useProjects(); + const user = userStore.currentUser; + const projects = workspaceSlug ? projectStore.projects[workspaceSlug?.toString()] : null; - const { control, watch, setValue } = useForm({ defaultValues }); - - const params: IAnalyticsParams = { - x_axis: watch("x_axis"), - y_axis: watch("y_axis"), - segment: watch("segment"), - project: watch("project"), - }; - - const { data: analytics, error: analyticsError } = useSWR( - workspaceSlug ? ANALYTICS(workspaceSlug.toString(), params) : null, - workspaceSlug ? () => analyticsService.getAnalytics(workspaceSlug.toString(), params) : null - ); + // const { user } = useUserAuth(); + // const { projects } = useProjects(); const trackAnalyticsEvent = (tab: string) => { const eventPayload = { @@ -83,70 +69,123 @@ const Analytics = () => { }, [user, workspaceSlug]); return ( - - - - } - > - {projects ? ( - projects.length > 0 ? ( -
- - - {tabsList.map((tab) => ( - - `rounded-3xl border border-custom-border-200 px-4 py-2 text-xs hover:bg-custom-background-80 ${ - selected ? "bg-custom-background-80" : "" - }` - } - onClick={() => trackAnalyticsEvent(tab)} - > - {tab} - - ))} - - - - - - - - - - -
+ // + // + // + // } + // > + // {projects ? ( + // projects.length > 0 ? ( + //
+ // + // + // {tabsList.map((tab) => ( + // + // `rounded-3xl border border-custom-border-200 px-4 py-2 text-xs hover:bg-custom-background-80 ${ + // selected ? "bg-custom-background-80" : "" + // }` + // } + // onClick={() => trackAnalyticsEvent(tab)} + // > + // {tab} + // + // ))} + // + // + // + // + // + // + // + // + // + // + //
+ // ) : ( + // , + // text: "New Project", + // onClick: () => { + // const e = new KeyboardEvent("keydown", { + // key: "p", + // }); + // document.dispatchEvent(e); + // }, + // }} + // /> + // ) + // ) : null} + //
+ }> + <> + {projects && projects.length > 0 ? ( + <> +
+ + + {tabsList.map((tab) => ( + + `rounded-3xl border border-custom-border-200 px-4 py-2 text-xs hover:bg-custom-background-80 ${ + selected ? "bg-custom-background-80" : "" + }` + } + onClick={() => trackAnalyticsEvent(tab)} + > + {tab} + + ))} + + + + + + + + + + +
+ ) : ( - , - text: "New Project", - onClick: () => { - const e = new KeyboardEvent("keydown", { - key: "p", - }); - document.dispatchEvent(e); - }, - }} - /> - ) - ) : null} -
+ <> + , + text: "New Project", + onClick: () => { + const e = new KeyboardEvent("keydown", { + key: "p", + }); + document.dispatchEvent(e); + }, + }} + /> + + )} + + ); -}; +}); -export default Analytics; +export default AnalyticsPage;