/** * BUS-Tickets - Notification Settings Screen * Copyright (c) 2024-2026 IT Enterprise */ import { useState, useEffect } from 'react'; import { View, Text, ScrollView, Switch, TouchableOpacity, StyleSheet, Alert, } from 'react-native'; import { Ionicons } from '@expo/vector-icons'; import { useTheme } from '@/contexts/ThemeContext'; import { useNotifications } from '@/hooks/useNotifications'; import { NotificationSettings } from '@/services/NotificationService'; const REMINDER_OPTIONS = [ { value: 15, label: '15 minutes' }, { value: 30, label: '30 minutes' }, { value: 60, label: '1 hour' }, { value: 120, label: '2 hours' }, { value: 1440, label: '1 day' }, ]; export default function NotificationSettingsScreen() { const { colors } = useTheme(); const { settings, updateSettings, expoPushToken } = useNotifications(); const [localSettings, setLocalSettings] = useState(settings); const [showReminderPicker, setShowReminderPicker] = useState(false); useEffect(() => { setLocalSettings(settings); }, [settings]); const handleToggle = async ( key: keyof NotificationSettings, value: boolean ) => { const newSettings = { ...localSettings, [key]: value }; setLocalSettings(newSettings); await updateSettings({ [key]: value }); // If disabling all notifications if (key === 'enabled' && !value) { Alert.alert( 'Notifications Disabled', 'You will no longer receive push notifications. You can enable them again anytime.' ); } }; const handleReminderChange = async (minutes: number) => { setLocalSettings({ ...localSettings, tripReminderMinutes: minutes }); await updateSettings({ tripReminderMinutes: minutes }); setShowReminderPicker(false); }; const styles = createStyles(colors); const getReminderLabel = (minutes: number): string => { const option = REMINDER_OPTIONS.find((o) => o.value === minutes); return option?.label || `${minutes} minutes`; }; return ( {/* Push Token Info (for debugging) */} {__DEV__ && expoPushToken && ( Push Token: {expoPushToken} )} {/* Master Toggle */} Push Notifications Receive notifications about your trips handleToggle('enabled', value)} trackColor={{ false: colors.border, true: colors.primary }} thumbColor="#fff" /> {/* Notification Types */} {localSettings.enabled && ( Notification Types {/* Trip Reminders */} Trip Reminders Get reminded before your trip handleToggle('tripReminders', value)} trackColor={{ false: colors.border, true: colors.primary }} thumbColor="#fff" /> {/* Reminder Time */} {localSettings.tripReminders && ( setShowReminderPicker(!showReminderPicker)} > Reminder Time {getReminderLabel(localSettings.tripReminderMinutes)} before departure )} {showReminderPicker && ( {REMINDER_OPTIONS.map((option) => ( handleReminderChange(option.value)} > {option.label} {localSettings.tripReminderMinutes === option.value && ( )} ))} )} {/* Booking Confirmations */} Booking Confirmations Notifications when you book a ticket handleToggle('bookingConfirmations', value) } trackColor={{ false: colors.border, true: colors.primary }} thumbColor="#fff" /> {/* Trip Updates */} Trip Updates Delays, cancellations, and changes handleToggle('tripUpdates', value)} trackColor={{ false: colors.border, true: colors.primary }} thumbColor="#fff" /> {/* Promotions */} Promotions & Offers Special deals and discounts handleToggle('promotions', value)} trackColor={{ false: colors.border, true: colors.primary }} thumbColor="#fff" /> )} {/* Sound & Vibration */} {localSettings.enabled && ( Sound & Vibration Sound Play sound for notifications handleToggle('sound', value)} trackColor={{ false: colors.border, true: colors.primary }} thumbColor="#fff" /> Vibration Vibrate for notifications handleToggle('vibration', value)} trackColor={{ false: colors.border, true: colors.primary }} thumbColor="#fff" /> )} {/* Info */} You can also manage notifications in your device settings. ); } const createStyles = (colors: any) => StyleSheet.create({ container: { flex: 1, backgroundColor: colors.background, }, content: { padding: 16, }, debugSection: { backgroundColor: colors.card, padding: 12, borderRadius: 8, marginBottom: 16, }, debugLabel: { fontSize: 12, color: colors.textSecondary, marginBottom: 4, }, debugValue: { fontSize: 10, fontFamily: 'monospace', color: colors.text, }, section: { marginBottom: 24, }, sectionTitle: { fontSize: 14, fontWeight: '600', color: colors.textSecondary, textTransform: 'uppercase', marginBottom: 8, marginLeft: 4, }, card: { backgroundColor: colors.card, borderRadius: 12, padding: 4, }, settingRow: { flexDirection: 'row', alignItems: 'center', padding: 12, }, subSetting: { paddingLeft: 44, backgroundColor: colors.background, marginHorizontal: 8, borderRadius: 8, marginBottom: 8, }, settingIcon: { width: 40, height: 40, borderRadius: 20, backgroundColor: `${colors.primary}20`, justifyContent: 'center', alignItems: 'center', marginRight: 12, }, settingInfo: { flex: 1, marginLeft: 8, }, settingTitle: { fontSize: 16, color: colors.text, }, settingDescription: { fontSize: 12, color: colors.textSecondary, marginTop: 2, }, divider: { height: 1, backgroundColor: colors.border, marginHorizontal: 12, }, pickerContainer: { backgroundColor: colors.background, marginHorizontal: 8, borderRadius: 8, marginBottom: 8, overflow: 'hidden', }, pickerOption: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingVertical: 12, paddingHorizontal: 16, }, pickerOptionSelected: { backgroundColor: `${colors.primary}10`, }, pickerOptionText: { fontSize: 14, color: colors.text, }, pickerOptionTextSelected: { color: colors.primary, fontWeight: '600', }, infoSection: { flexDirection: 'row', alignItems: 'flex-start', gap: 8, padding: 16, }, infoText: { flex: 1, fontSize: 12, color: colors.textSecondary, lineHeight: 18, }, });