import { Modal, Stack, Button, Text, Title, Anchor, useMantineTheme, useComputedColorScheme, } from '@mantine/core'; import { useTranslation } from 'react-i18next'; import { useState } from 'react'; import { Z_ANALYTICS_MODAL } from '@app/styles/zIndex'; import { useAppConfig } from '@app/contexts/AppConfigContext'; import apiClient from '@app/services/apiClient'; interface AdminAnalyticsChoiceModalProps { opened: boolean; onClose: () => void; } export default function AdminAnalyticsChoiceModal({ opened, onClose }: AdminAnalyticsChoiceModalProps) { const { t } = useTranslation(); const { refetch } = useAppConfig(); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const theme = useMantineTheme(); const computedColorScheme = useComputedColorScheme('light', { getInitialValueInEffect: true }); const isDark = computedColorScheme === 'dark'; const privacyHighlightStyles = { color: isDark ? '#FFFFFF' : theme.colors.blue[7], padding: `${theme.spacing.xs} ${theme.spacing.sm}`, borderRadius: theme.radius.md, fontWeight: 700, textAlign: 'center' as const, display: 'flex', alignItems: 'center', justifyContent: 'center', gap: theme.spacing.xs, letterSpacing: 0.3, }; const handleChoice = async (enableAnalytics: boolean) => { setLoading(true); setError(null); try { const formData = new FormData(); formData.append('enabled', enableAnalytics.toString()); await apiClient.post('/api/v1/settings/update-enable-analytics', formData); // Refetch config to apply new settings without page reload await refetch(); // Close the modal after successful save onClose(); } catch (err) { setError(err instanceof Error ? err.message : 'Unknown error occurred'); setLoading(false); } }; const handleEnable = () => { handleChoice(true); }; const handleDisable = () => { handleChoice(false); }; return ( {}} // Prevent closing closeOnClickOutside={false} closeOnEscape={false} withCloseButton={false} size="lg" centered zIndex={Z_ANALYTICS_MODAL} > {t('analytics.title', 'Do you want make Stirling PDF better?')} {t('analytics.paragraph1', 'Stirling PDF has opt in analytics to help us improve the product.')} • {t('analytics.privacyAssurance', 'We do not track any personal information or the contents of your files.')} • {t('analytics.paragraph2', 'Please consider enabling analytics to help Stirling-PDF grow and to allow us to understand our users better.')}{' '} {t('analytics.learnMore', 'Learn more')} {error && ( {error} )} {t('analytics.settings', 'You can change the settings for analytics in the config/settings.yml file')} ); }