-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract KpiCards to separate components
- Loading branch information
Showing
6 changed files
with
337 additions
and
3,535 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
next-frontend/components/visualizers/CurrentStreakKpiCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Calendar } from "lucide-react"; | ||
import { FC } from "react"; | ||
import { KpiCardUiProvider } from "@/components/ui-providers/KpiCardUiProvider"; | ||
import { queryKeys } from "@/components/hooks/queryHooks/queryKeys"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { Skeleton } from "@/components/shadcn/skeleton"; | ||
|
||
type CurrentStreakKpiCardProps = Record<string, never> | ||
|
||
export const CurrentStreakKpiCard: FC<CurrentStreakKpiCardProps> = () => { | ||
const stats = useQuery({ | ||
...queryKeys.statistics.dashboard, | ||
retry: false, | ||
}); | ||
|
||
if (stats.isPending) { | ||
return <Skeleton />; | ||
} | ||
|
||
if (stats.isError || stats.data.isErr) { | ||
return <span>Error occured</span>; | ||
} | ||
|
||
return ( | ||
<KpiCardUiProvider | ||
value={stats.data.value.streak} | ||
title="Current Streak" | ||
description="Keep it going!" | ||
> | ||
<Calendar /> | ||
</KpiCardUiProvider> | ||
); | ||
}; |
37 changes: 37 additions & 0 deletions
37
next-frontend/components/visualizers/TotalMinutesSpentKpiCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Hourglass } from "lucide-react"; | ||
import { type FC } from "react"; | ||
import { KpiCardUiProvider } from "@/components/ui-providers/KpiCardUiProvider"; | ||
import { queryKeys } from "@/components/hooks/queryHooks/queryKeys"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { Skeleton } from "@/components/shadcn/skeleton"; | ||
|
||
type TotalSessionTimeKpiCardProps = Record<string, never> | ||
|
||
export const TotalSessionTimeKpiCard: FC<TotalSessionTimeKpiCardProps> = () => { | ||
const stats = useQuery({ | ||
...queryKeys.statistics.dashboard, | ||
retry: false, | ||
}); | ||
|
||
if (stats.isPending) { | ||
return <Skeleton />; | ||
} | ||
|
||
if (stats.isError || stats.data.isErr) { | ||
return <span>Error occured</span>; | ||
} | ||
|
||
return ( | ||
<KpiCardUiProvider | ||
value={stats.data.value.minutes} | ||
title="Total Minutes Spent" | ||
description={`That's almost ${Math.ceil( | ||
stats.data.value.minutes / 60 | ||
).toFixed(2)} hours!`} | ||
> | ||
|
||
<Hourglass /> | ||
</KpiCardUiProvider> | ||
|
||
); | ||
}; |
33 changes: 33 additions & 0 deletions
33
next-frontend/components/visualizers/TotalSessionsKpiCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { AlignVerticalDistributeEnd } from "lucide-react"; | ||
import { FC } from "react"; | ||
import { KpiCardUiProvider } from "@/components/ui-providers/KpiCardUiProvider"; | ||
import { queryKeys } from "@/components/hooks/queryHooks/queryKeys"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { Skeleton } from "@/components/shadcn/skeleton"; | ||
|
||
type TotalSessionsKpiCardProps = Record<string, never> | ||
|
||
export const TotalSessionsKpiCard: FC<TotalSessionsKpiCardProps> = () => { | ||
const stats = useQuery({ | ||
...queryKeys.statistics.dashboard, | ||
retry: false, | ||
}); | ||
|
||
if (stats.isPending) { | ||
return <Skeleton />; | ||
} | ||
|
||
if (stats.isError || stats.data.isErr) { | ||
return <span>Error occured</span>; | ||
} | ||
|
||
return ( | ||
<KpiCardUiProvider | ||
value={stats.data.value.session_count} | ||
title={"Total Sessions"} | ||
description={"Many to go.."} | ||
> | ||
<AlignVerticalDistributeEnd /> | ||
</KpiCardUiProvider> | ||
); | ||
}; |
Oops, something went wrong.