()
| 34 | type SubscriptionTier = keyof typeof TIER_LIMITS; |
| 35 | |
| 36 | export function AnalyticsSettingsPage() { |
| 37 | const roles = useAuthStore((state) => state.roles); |
| 38 | const canManageSettings = hasAdminRole(roles); |
| 39 | const isReadOnly = !canManageSettings; |
| 40 | |
| 41 | // Mock data - will be replaced with actual API calls in US-013 |
| 42 | const [currentTier] = useState<SubscriptionTier>('free'); |
| 43 | const [retentionPeriod, setRetentionPeriod] = useState('30'); |
| 44 | const [isSubmitting, setIsSubmitting] = useState(false); |
| 45 | const [error, setError] = useState<string | null>(null); |
| 46 | const [successMessage, setSuccessMessage] = useState<string | null>(null); |
| 47 | const [storageUsage] = useState<{ used: string; total: string } | null>(null); |
| 48 | |
| 49 | const tierInfo = TIER_LIMITS[currentTier]; |
| 50 | const maxAllowedRetention = tierInfo.maxRetentionDays; |
| 51 | |
| 52 | // Filter retention periods based on tier limit |
| 53 | const availableRetentionPeriods = RETENTION_PERIODS.filter( |
| 54 | (period) => period.days <= maxAllowedRetention, |
| 55 | ); |
| 56 | |
| 57 | useEffect(() => { |
| 58 | // TODO: US-013 will implement API call to fetch current settings |
| 59 | // fetchSettings().catch(console.error); |
| 60 | }, []); |
| 61 | |
| 62 | const handleSave = async () => { |
| 63 | if (isReadOnly) return; |
| 64 | |
| 65 | setError(null); |
| 66 | setSuccessMessage(null); |
| 67 | setIsSubmitting(true); |
| 68 | |
| 69 | try { |
| 70 | // TODO: US-013 will implement API call to save settings |
| 71 | // await api.analytics.updateSettings({ retentionDays: parseInt(retentionPeriod) }); |
| 72 | |
| 73 | // Simulate API call |
| 74 | await new Promise((resolve) => setTimeout(resolve, 500)); |
| 75 | |
| 76 | setSuccessMessage('Analytics settings updated successfully'); |
| 77 | |
| 78 | // Clear success message after 5 seconds |
| 79 | setTimeout(() => setSuccessMessage(null), 5000); |
| 80 | } catch (err) { |
| 81 | setError(err instanceof Error ? err.message : 'Failed to update analytics settings'); |
| 82 | } finally { |
| 83 | setIsSubmitting(false); |
| 84 | } |
| 85 | }; |
| 86 | |
| 87 | return ( |
| 88 | <div className="flex-1 bg-background"> |
| 89 | <div className="container mx-auto py-4 md:py-8 px-3 md:px-4"> |
| 90 | {/* Header */} |
| 91 | <div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-4 md:mb-8"> |
| 92 | <div> |
| 93 | <h1 className="text-xl md:text-2xl font-semibold">Analytics Settings</h1> |
nothing calls this directly
no test coverage detected