chore(web): improve contribute modal

This commit is contained in:
isra el
2025-02-20 19:35:52 +03:00
parent f76af5ebd3
commit a199304e30

View File

@@ -25,6 +25,9 @@ import Link from 'next/link'
import { ExternalLinks } from '@/config/external-links'
import { CRYPTO_ADDRESSES } from '@/lib/constants'
import Image from 'next/image'
import { ApiEndpoints } from '@/config/api'
import httpBrowserClient from '@/lib/httpBrowserClient'
import { useQuery } from '@tanstack/react-query'
// Add constants for localStorage and timing
const STORAGE_KEYS = {
@@ -46,15 +49,36 @@ export function ContributeModal() {
setTimeout(() => setCopiedAddress(''), 3000)
}
const {
data: currentPlan,
isLoading: isLoadingPlan,
error: planError,
} = useQuery({
queryKey: ['currentPlan'],
queryFn: () =>
httpBrowserClient
.get(ApiEndpoints.billing.currentPlan())
.then((res) => res.data),
})
useEffect(() => {
const checkAndShowModal = () => {
setIsOpen(true)
return
if (isLoadingPlan) return
if (planError) return
if (currentPlan?.name?.toLowerCase() !== 'free') {
return
}
const hasContributed =
localStorage.getItem(STORAGE_KEYS.HAS_CONTRIBUTED) === 'true'
if (hasContributed) return
setIsOpen(true)
return;
const lastShown = localStorage.getItem(STORAGE_KEYS.LAST_SHOWN)
const now = Date.now()
@@ -73,7 +97,7 @@ export function ContributeModal() {
checkAndShowModal()
}
})
}, [])
}, [currentPlan?.name, isLoadingPlan, planError])
const handleContributed = () => {
localStorage.setItem(STORAGE_KEYS.HAS_CONTRIBUTED, 'true')