docs: add comprehensive Stripe billing guide
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 4s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 4s
Covers architecture, configuration steps, user flows, API routes, webhooks, pricing, testing with Stripe CLI, production checklist, and troubleshooting.
This commit is contained in:
40
memento-note/hooks/use-cookie-consent.ts
Normal file
40
memento-note/hooks/use-cookie-consent.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
'use client'
|
||||
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import {
|
||||
CONSENT_CHANGE_EVENT,
|
||||
getConsent,
|
||||
hasConsentChoice,
|
||||
type ConsentRecord,
|
||||
} from '@/lib/consent/cookie-consent'
|
||||
|
||||
export function useCookieConsent() {
|
||||
const [consent, setConsentState] = useState<ConsentRecord | null>(null)
|
||||
const [ready, setReady] = useState(false)
|
||||
|
||||
const refresh = useCallback(() => {
|
||||
setConsentState(getConsent())
|
||||
setReady(true)
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
refresh()
|
||||
const onChange = () => refresh()
|
||||
const onStorage = (e: StorageEvent) => {
|
||||
if (e.key === 'memento-consent-v1') refresh()
|
||||
}
|
||||
window.addEventListener(CONSENT_CHANGE_EVENT, onChange)
|
||||
window.addEventListener('storage', onStorage)
|
||||
return () => {
|
||||
window.removeEventListener(CONSENT_CHANGE_EVENT, onChange)
|
||||
window.removeEventListener('storage', onStorage)
|
||||
}
|
||||
}, [refresh])
|
||||
|
||||
return {
|
||||
consent,
|
||||
ready,
|
||||
hasChoice: ready && hasConsentChoice(),
|
||||
needsBanner: ready && !hasConsentChoice(),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user