diff --git a/002_source/cms/src/components/dashboard/overview/summary/ActiveUserCount/index.tsx b/002_source/cms/src/components/dashboard/overview/summary/ActiveUserCount/index.tsx index 520ba73..e571cab 100644 --- a/002_source/cms/src/components/dashboard/overview/summary/ActiveUserCount/index.tsx +++ b/002_source/cms/src/components/dashboard/overview/summary/ActiveUserCount/index.tsx @@ -1,11 +1,10 @@ 'use client'; /* -# PROMPT +RULES: -this is a subset of a typescript project - -clone `LessonTypeCount`, `LessonCategoriesCount` to `UserCount` and do modifiy to get the count of users, thanks. +show loading when fetching record from db +show error when fetch record failed */ import * as React from 'react'; import getAllUserMetasCount from '@/db/UserMetas/GetAllCount'; @@ -15,6 +14,7 @@ import { useTranslation } from 'react-i18next'; import { Summary } from '@/components/dashboard/overview/summary'; import { LoadingSummary } from '../LoadingSummary'; +import { ErrorSummary } from '../ErrorSummary'; function ActiveUserCount(): React.JSX.Element { const { t } = useTranslation(); @@ -50,7 +50,15 @@ function ActiveUserCount(): React.JSX.Element { ); } - if (showError) return
{errorDetail}
; + if (showError) + return ( + + ); return ( + + + + + +
+ + {title} + + Error +
+
+
+ + + + + {trend === 'up' ? ( + + ) : ( + + )} + + + + {new Intl.NumberFormat('en-US', { style: 'percent', maximumFractionDigits: 2 }).format(diff / 100)} + {' '} + {trend === 'up' ? t('increase') : t('decrease')} {t('vs last month')} + + + + + ); +} diff --git a/002_source/cms/src/components/dashboard/overview/summary/LessonCategoriesCount/index.tsx b/002_source/cms/src/components/dashboard/overview/summary/LessonCategoriesCount/index.tsx index 6993e41..56d2816 100644 --- a/002_source/cms/src/components/dashboard/overview/summary/LessonCategoriesCount/index.tsx +++ b/002_source/cms/src/components/dashboard/overview/summary/LessonCategoriesCount/index.tsx @@ -15,6 +15,7 @@ import { useTranslation } from 'react-i18next'; import { Summary } from '@/components/dashboard/overview/summary'; import { LoadingSummary } from '../LoadingSummary'; +import { ErrorSummary } from '../ErrorSummary'; function LessonCategoriesCount(): React.JSX.Element { const { t } = useTranslation(); @@ -40,10 +41,26 @@ function LessonCategoriesCount(): React.JSX.Element { }, []); if (showLoading) { - return ; + return ( + + ); } - if (showError) return
{errorDetail}
; + if (showError) { + return ( + + ); + } return ( ); diff --git a/002_source/cms/src/components/dashboard/overview/summary/index.tsx b/002_source/cms/src/components/dashboard/overview/summary/index.tsx index 9c381d4..eaa8513 100644 --- a/002_source/cms/src/components/dashboard/overview/summary/index.tsx +++ b/002_source/cms/src/components/dashboard/overview/summary/index.tsx @@ -1,5 +1,11 @@ 'use client'; +/* +NOTES: +show loading when loading summary +use with: +- src/components/dashboard/overview/summary/ActiveUserCount/index.tsx +*/ import * as React from 'react'; import Avatar from '@mui/material/Avatar'; import Box from '@mui/material/Box'; @@ -26,7 +32,11 @@ export function Summary({ amount, diff, icon: Icon, title, trend }: SummaryProps return ( - +
- + {title} {new Intl.NumberFormat('en-US').format(amount)} @@ -47,7 +60,11 @@ export function Summary({ amount, diff, icon: Icon, title, trend }: SummaryProps - + )} - - + + {new Intl.NumberFormat('en-US', { style: 'percent', maximumFractionDigits: 2 }).format(diff / 100)} {' '} {trend === 'up' ? t('increase') : t('decrease')} {t('vs last month')}