mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 09:09:36 +02:00
Migrate Writefull AI consent to shared tutorial system GitOrigin-RevId: c9298a177c9f1aa1a941c96599d6d854591f8a76
34 lines
943 B
TypeScript
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 }
|
|
}
|