From a12fa3e6feedb3c7d83a097e187aa9945ff9bb10 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Fri, 8 Nov 2024 01:47:49 +0800 Subject: [PATCH] feat: add component which can render usage data and progress --- src/client/components/UsageCard.tsx | 61 +++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/client/components/UsageCard.tsx diff --git a/src/client/components/UsageCard.tsx b/src/client/components/UsageCard.tsx new file mode 100644 index 0000000..704b75e --- /dev/null +++ b/src/client/components/UsageCard.tsx @@ -0,0 +1,61 @@ +import React from 'react'; +import { Card, CardContent, CardHeader } from './ui/card'; +import { formatNumber } from '@/utils/common'; +import { LuAlertCircle } from 'react-icons/lu'; +import { Tooltip, TooltipContent, TooltipTrigger } from './ui/tooltip'; +import { useTranslation } from '@i18next-toolkit/react'; +import colors from 'tailwindcss/colors'; + +interface UsageCardProps { + title: string; + current: number; + limit?: number; +} +export const UsageCard: React.FC = React.memo((props) => { + const { title, current, limit } = props; + const { t } = useTranslation(); + + return ( + + {limit && ( +
+ )} + + {limit && current > limit && ( +
+ + + + + +
+ {t( + 'Exceeded the limit, please upgrade your plan or your workspace will be paused soon.' + )} +
+
+
+
+ )} + + {title} + + {limit && limit >= 0 ? ( +
+ {formatNumber(current)}{' '} + / {formatNumber(limit)} +
+ ) : ( +
+ {formatNumber(current)}{' '} + / +
+ )} +
+ + ); +}); +UsageCard.displayName = 'UsageCard';