mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-09-03 06:12:53 +02:00
Hide coupon banner if user is learning
This commit is contained in:
@@ -2,18 +2,34 @@ import { CheckIcon, CopyIcon, XIcon } from 'lucide-react';
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { useCopyText } from '../../hooks/use-copy-text';
|
import { useCopyText } from '../../hooks/use-copy-text';
|
||||||
import { cn } from '../../lib/classname';
|
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 const sqlCouponCode = 'SQL30';
|
||||||
|
|
||||||
export function CourseDiscountBanner() {
|
export function CourseDiscountBanner() {
|
||||||
const { copyText, isCopied } = useCopyText();
|
const { copyText, isCopied } = useCopyText();
|
||||||
const [isVisible, setIsVisible] = useState(false);
|
const [isVisible, setIsVisible] = useState(false);
|
||||||
|
const isClientMounted = useClientMount();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timer = setTimeout(() => setIsVisible(true), 5000);
|
const timer = setTimeout(() => setIsVisible(true), 5000);
|
||||||
return () => clearTimeout(timer);
|
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 (
|
return (
|
||||||
<div
|
<div
|
||||||
data-coupon-alert
|
data-coupon-alert
|
||||||
|
Reference in New Issue
Block a user