diff --git a/src/components/GenerateCourse/AICourseLimit.tsx b/src/components/GenerateCourse/AICourseLimit.tsx index 78dfbb395..da7242ba9 100644 --- a/src/components/GenerateCourse/AICourseLimit.tsx +++ b/src/components/GenerateCourse/AICourseLimit.tsx @@ -13,10 +13,9 @@ import { queryClient } from '../../stores/query-client'; import { useOutsideClick } from '../../hooks/use-outside-click'; import { UpgradeAccountModal } from '../Billing/UpgradeAccountModal'; import { billingDetailsOptions } from '../../queries/billing'; +import { getPercentage } from '../../helper/number'; export function AICourseLimit() { - const containerRef = useRef(null); - const [isOpen, setIsOpen] = useState(false); const [showUpgradeModal, setShowUpgradeModal] = useState(false); const { data: limits, isLoading } = useQuery( @@ -27,105 +26,28 @@ export function AICourseLimit() { const { data: userBillingDetails, isLoading: isBillingDetailsLoading } = useQuery(billingDetailsOptions(), queryClient); - useOutsideClick(containerRef, () => { - setIsOpen(false); - }); - if (isLoading || !limits || isBillingDetailsLoading || !userBillingDetails) { return ( -
+
); } - const { - used: courseUsed, - limit: courseLimit, - lessonUsed, - lessonLimit, - followUpUsed, - followUpLimit, - } = limits; + const { used, limit } = limits; - const coursePercentage = Math.round((courseUsed / courseLimit) * 100); - const lessonPercentage = Math.round((lessonUsed / lessonLimit) * 100); - const followUpPercentage = Math.round((followUpUsed / followUpLimit) * 100); + const totalPercentage = getPercentage(used, limit); return ( <> -
- - - {isOpen && ( -
-
-
-
- - {courseUsed} of {courseLimit} courses used -
- -
-
- -
-
- - {lessonUsed} of {lessonLimit} lessons used -
- -
-
- -
-
- - {followUpUsed} of {followUpLimit} follow-ups used -
- -
-
-
- -
- - Limit resets every 24 hours -
-
- )} +
+ + {totalPercentage}% of the daily limit used + +
{userBillingDetails.status === 'none' && ( diff --git a/src/queries/ai-course.ts b/src/queries/ai-course.ts index e81ff7ef4..46439e5ac 100644 --- a/src/queries/ai-course.ts +++ b/src/queries/ai-course.ts @@ -72,10 +72,6 @@ type GetAICourseLimitParams = {}; type GetAICourseLimitResponse = { used: number; limit: number; - lessonUsed: number; - lessonLimit: number; - followUpUsed: number; - followUpLimit: number; }; export function getAiCourseLimitOptions() {