Files
overleaf-cep/services/web/frontend/js/shared/hooks/use-ai-consent.ts
Malik Glossop a598c552a5 Merge pull request #31737 from overleaf/mg-shared-ai-consent
Migrate Writefull AI consent to shared tutorial system

GitOrigin-RevId: c9298a177c9f1aa1a941c96599d6d854591f8a76
2026-03-20 09:07:33 +00:00

34 lines
943 B
TypeScript

import { useCallback, useMemo, useState } from 'react'
import useTutorial from '@/shared/hooks/promotions/use-tutorial'
const AI_CONSENT_TUTORIAL_KEY = 'workbench-consent-release'
const eventData = { name: AI_CONSENT_TUTORIAL_KEY }
export { AI_CONSENT_TUTORIAL_KEY }
export default function useAiConsent() {
const { completeTutorial, checkCompletion } = useTutorial(
AI_CONSENT_TUTORIAL_KEY,
eventData
)
const hasGivenAiConsent = useMemo(() => checkCompletion(), [checkCompletion])
const [consentError, setConsentError] = useState(false)
const giveAiConsent = useCallback(async () => {
setConsentError(false)
try {
await completeTutorial(
{ event: 'promo-click', action: 'complete' },
{ failSilently: false }
)
return true
} catch {
setConsentError(true)
return false
}
}, [completeTutorial])
return { hasGivenAiConsent, giveAiConsent, consentError }
}