feat: redirect to AI consent settings when consent is missing
- requestAiConsent now redirects to /settings/general?highlight=aiConsent instead of opening the modal when called outside the settings page - Settings page highlights the consent section and scrolls to it - Adds consent.ai.settingsBanner i18n key (fr/en) - Keeps inline modal on /settings/general so the grant button still works
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
import { createContext, useContext, useState, useEffect, useRef, useCallback } from 'react'
|
||||
import { useSession } from 'next-auth/react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { getLocalStorageAiConsent, setLocalStorageAiConsent, removeLocalStorageAiConsent } from '@/lib/consent/ai-consent-client'
|
||||
import { redirectToAiConsentSettings } from '@/lib/consent/ai-consent-redirect'
|
||||
import { updateAISettings } from '@/app/actions/ai-settings'
|
||||
import { AiConsentModal } from './ai-consent-modal'
|
||||
import { toast } from 'sonner'
|
||||
@@ -24,6 +26,7 @@ interface AiConsentProviderProps {
|
||||
export function AiConsentProvider({ children, initialPersistentConsent = false }: AiConsentProviderProps) {
|
||||
const { data: session, update: updateSession } = useSession()
|
||||
const { t } = useLanguage()
|
||||
const router = useRouter()
|
||||
|
||||
const [persistentConsent, setPersistentConsent] = useState(false)
|
||||
const [sessionConsent, setSessionConsent] = useState(false)
|
||||
@@ -60,11 +63,22 @@ export function AiConsentProvider({ children, initialPersistentConsent = false }
|
||||
return Promise.resolve(true)
|
||||
}
|
||||
|
||||
setModalOpen(true)
|
||||
// On settings page we keep the inline modal; elsewhere redirect to settings
|
||||
// so the user sees exactly where to grant consent.
|
||||
if (typeof window !== 'undefined' && window.location.pathname.startsWith('/settings/general')) {
|
||||
setModalOpen(true)
|
||||
return new Promise<boolean>((resolve) => {
|
||||
pendingResolveRef.current = resolve
|
||||
})
|
||||
}
|
||||
|
||||
redirectToAiConsentSettings(router, { replace: false })
|
||||
return new Promise<boolean>((resolve) => {
|
||||
pendingResolveRef.current = resolve
|
||||
pendingResolveRef.current(false)
|
||||
pendingResolveRef.current = null
|
||||
})
|
||||
}, [hasAiConsent])
|
||||
}, [hasAiConsent, router])
|
||||
|
||||
const handleConfirm = async (remember: boolean) => {
|
||||
setModalOpen(false)
|
||||
|
||||
Reference in New Issue
Block a user