diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx deleted file mode 100644 index 44e7e25..0000000 --- a/src/pages/Home.tsx +++ /dev/null @@ -1,142 +0,0 @@ -import { useEffect } from 'react'; -import { useAppDispatch } from '../app/hooks'; -import { useGetDashboardQuery } from '../services/dashboardApi'; -import { setBreadcrumb } from '../features/breadcrumbSlice'; -import Breadcrumb from '../components/Breadcrumb'; -import { showErrorToast } from '../components/Toast'; - -import type { Game, School } from '../types'; -import { getPercentage } from '../utilities/numberUtils'; - -function Home() { - const dispatch = useAppDispatch(); - const { - data: dashboards, - isLoading, - isSuccess, - isError, - } = useGetDashboardQuery(); - - if (isError) { - showErrorToast('Gagal memuat data'); - } - - useEffect(() => { - dispatch(setBreadcrumb([])); - }, [dispatch]); - - return ( -
-
- -
Home (Test)
-

Selamat datang di Dashboard Gameon.

-
-
- {isLoading &&

Loading...

} - {isSuccess && ( -
-

Analitik

-
-
-
-
-
- {dashboards?.data?.gameCount} -
-
Total Permainan
-
-
-
-
-
-
-
- {dashboards?.data?.schoolCount} -
-
Total Sekolah
-
-
-
-
-
-
-
- {dashboards?.data?.adminCount} -
-
Total Admin
-

- {dashboards?.data?.activeAdmin} admin aktif -

-
-
-

- {getPercentage( - dashboards?.data?.activeAdmin, - dashboards?.data?.adminCount - )} -

-
-
-
-
-
-
-
- {dashboards?.data?.studentsCount} -
-
Total Siswa
-

- {dashboards?.data?.activeStudents} siswa aktif -

-
-
-

- {' '} - {getPercentage( - dashboards?.data?.activeStudents, - dashboards?.data?.studentsCount - )} -

-
-
-
-
-
- )} - {isSuccess && ( -
-

Permainan

-
- {dashboards?.data?.games?.map((game: Game) => ( -
-
{game.name}
-

{game.description}

-
- ))} -
-
- )} - {isSuccess && ( -
-

Sekolah

-
- {dashboards?.data?.schools?.map((school: School) => ( -
-
{school.name}
-

{school.address}

-
- ))} -
-
- )} -
-
- ); -} - -export default Home; diff --git a/src/pages/Home/components/PerformanceWidget.tsx b/src/pages/Home/components/PerformanceWidget.tsx new file mode 100644 index 0000000..0abe57c --- /dev/null +++ b/src/pages/Home/components/PerformanceWidget.tsx @@ -0,0 +1,80 @@ +import { + Gamepad2Icon, + GraduationCapIcon, + SchoolIcon, + UserIcon, +} from 'lucide-react'; +import { getPercentage } from '../../../utilities/numberUtils'; + +import type { PerformanceWidgetProps, WidgetIconType } from '../../../types'; + +function PerformanceWidget({ + type, + countItem, + activeItem, + name, + children, +}: PerformanceWidgetProps) { + const widgetIcon: WidgetIconType = { + permainan: ( + + ), + sekolah: ( + + ), + admin: ( + + ), + siswa: ( + + ), + }; + + return ( +
+
+
+ {widgetIcon[name as keyof WidgetIconType]} +
+ {type === 'advanced' && ( +
+

+ {getPercentage(activeItem, countItem)} +

+

+ {activeItem} {name} aktif +

+
+ )} +
+
+
+
+ Performa {name} +
+

+ {countItem}{' '} + + {name === 'admin' || name === 'siswa' ? 'orang' : 'item'} + +

+
+ {type === 'advanced' &&
{children}
} +
+
+ ); +} + +export default PerformanceWidget; diff --git a/src/pages/Home/index.tsx b/src/pages/Home/index.tsx new file mode 100644 index 0000000..e0503eb --- /dev/null +++ b/src/pages/Home/index.tsx @@ -0,0 +1,94 @@ +import { useEffect } from 'react'; +import { useAppDispatch } from '../../app/hooks'; +import { useGetDashboardQuery } from '../../services/dashboardApi'; +import { setBreadcrumb } from '../../features/breadcrumbSlice'; +import { showErrorToast } from '../../components/Toast'; +import Breadcrumb from '../../components/Breadcrumb'; +import PerformanceWidget from './components/PerformanceWidget'; + +import type { Game, School } from '../../types'; + +function Home() { + const dispatch = useAppDispatch(); + const { + data: dashboards, + isLoading, + isSuccess, + isError, + } = useGetDashboardQuery(); + + if (isError) { + showErrorToast('Gagal memuat data'); + } + + useEffect(() => { + dispatch(setBreadcrumb([])); + }, [dispatch]); + + return ( +
+
+ +
Home (Test)
+

Selamat datang di Dashboard Gameon.

+
+
+ + + + +
+
+ {isLoading &&

Loading...

} + {isSuccess && ( +
+

Permainan

+
+ {dashboards?.data?.games?.map((game: Game) => ( +
+
{game.name}
+

{game.description}

+
+ ))} +
+
+ )} + {isSuccess && ( +
+

Sekolah

+
+ {dashboards?.data?.schools?.map((school: School) => ( +
+
{school.name}
+

{school.address}

+
+ ))} +
+
+ )} +
+
+ ); +} + +export default Home; diff --git a/src/types/componentType.ts b/src/types/componentType.ts index 13471d1..65f2eac 100644 --- a/src/types/componentType.ts +++ b/src/types/componentType.ts @@ -99,6 +99,14 @@ interface ModalDisplayProps { title: string; } +interface PerformanceWidgetProps { + activeItem?: number; + countItem: number | undefined; + children?: ReactNode; + name: string; + type: 'simple' | 'advanced'; +} + export type { AlertDialogProps, Breadcrumb, @@ -110,6 +118,7 @@ export type { HeaderContainerProps, HeaderProfileProps, ModalDisplayProps, + PerformanceWidgetProps, ProfileUserProps, ScoreTableProps, StudentTableProps, diff --git a/src/types/utilitiesType.ts b/src/types/utilitiesType.ts index bbe4857..32cb480 100644 --- a/src/types/utilitiesType.ts +++ b/src/types/utilitiesType.ts @@ -12,5 +12,16 @@ interface NormalizedScore { interface NormalizeScoreChartDataEntry { [key: string]: number | string; } +interface WidgetIconType { + permainan: JSX.Element; + sekolah: JSX.Element; + admin: JSX.Element; + siswa: JSX.Element; +} -export type { NormalizedScore, NormalizeScoreChartDataEntry, ThemeState }; +export type { + NormalizedScore, + NormalizeScoreChartDataEntry, + ThemeState, + WidgetIconType, +};