Skip to content

Commit 853a26b

Browse files
committed
Hide coupon banner if user is learning
1 parent 5379aec commit 853a26b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/components/SQLCourse/CourseDiscountBanner.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,34 @@ import { CheckIcon, CopyIcon, XIcon } from 'lucide-react';
22
import { useState, useEffect } from 'react';
33
import { useCopyText } from '../../hooks/use-copy-text';
44
import { cn } from '../../lib/classname';
5+
import { SQL_COURSE_SLUG } from './BuyButton';
6+
import { queryClient } from '../../stores/query-client';
7+
import { courseProgressOptions } from '../../queries/course-progress';
8+
import { useQuery } from '@tanstack/react-query';
9+
import { useClientMount } from '../../hooks/use-client-mount';
510

611
export const sqlCouponCode = 'SQL30';
712

813
export function CourseDiscountBanner() {
914
const { copyText, isCopied } = useCopyText();
1015
const [isVisible, setIsVisible] = useState(false);
16+
const isClientMounted = useClientMount();
1117

1218
useEffect(() => {
1319
const timer = setTimeout(() => setIsVisible(true), 5000);
1420
return () => clearTimeout(timer);
1521
}, []);
1622

23+
const { data: courseProgress, isLoading: isLoadingCourseProgress } = useQuery(
24+
courseProgressOptions(SQL_COURSE_SLUG),
25+
queryClient,
26+
);
27+
28+
const isAlreadyEnrolled = !!courseProgress?.enrolledAt;
29+
if (!isClientMounted || isLoadingCourseProgress || isAlreadyEnrolled) {
30+
return null;
31+
}
32+
1733
return (
1834
<div
1935
data-coupon-alert

0 commit comments

Comments
 (0)