1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-09-02 13:52:46 +02:00

Hide coupon banner if user is learning

This commit is contained in:
Kamran Ahmed
2025-06-13 18:18:26 +01:00
parent 5379aec4b2
commit 853a26b6f4

View File

@@ -2,18 +2,34 @@ import { CheckIcon, CopyIcon, XIcon } from 'lucide-react';
import { useState, useEffect } from 'react';
import { useCopyText } from '../../hooks/use-copy-text';
import { cn } from '../../lib/classname';
import { SQL_COURSE_SLUG } from './BuyButton';
import { queryClient } from '../../stores/query-client';
import { courseProgressOptions } from '../../queries/course-progress';
import { useQuery } from '@tanstack/react-query';
import { useClientMount } from '../../hooks/use-client-mount';
export const sqlCouponCode = 'SQL30';
export function CourseDiscountBanner() {
const { copyText, isCopied } = useCopyText();
const [isVisible, setIsVisible] = useState(false);
const isClientMounted = useClientMount();
useEffect(() => {
const timer = setTimeout(() => setIsVisible(true), 5000);
return () => clearTimeout(timer);
}, []);
const { data: courseProgress, isLoading: isLoadingCourseProgress } = useQuery(
courseProgressOptions(SQL_COURSE_SLUG),
queryClient,
);
const isAlreadyEnrolled = !!courseProgress?.enrolledAt;
if (!isClientMounted || isLoadingCourseProgress || isAlreadyEnrolled) {
return null;
}
return (
<div
data-coupon-alert