/* * File: ProfileScreen.tsx * Description: Screen for displaying and managing user profile information, with editable name fields. * Design & Developed by Tech4Biz Solutions * Copyright (c) Spurrin Innovations. All rights reserved. */ import React, { useState } from 'react'; import { View, Text, StyleSheet, Image, ScrollView, TouchableOpacity, Alert, Switch, Modal, // Import Modal TextInput, // Import TextInput } from 'react-native'; import Icon from 'react-native-vector-icons/Feather'; import { useProfile } from '../hooks/useProfile'; import { Colors, Spacing, Typography, Shadows, BorderRadius, } from '../../../../shared/src/theme'; import { Button } from '../../../../shared/src/components/Button'; import { useDispatch } from 'react-redux'; import { logout } from '../../Auth/redux/authSlice'; interface InfoRowProps { icon: string; label?: string; value?: string; onEdit?: () => void; isNav?: boolean; isLogout?: boolean; } const InfoRow: React.FC = ({ icon, label, value, onEdit, isNav, isLogout, }) => ( {value || label} {onEdit && !isNav && !isLogout && ( )} {isNav && ( )} ); const SectionHeader: React.FC<{ title: string; icon?: string }> = ({ title, icon }) => ( {icon && } {title} ); // New component for individual notification toggles const NotificationToggle: React.FC<{ label: string; isEnabled: boolean; onToggle: (value: boolean) => void; }> = ({ label, isEnabled, onToggle }) => ( {label} ); const ProfileScreen: React.FC<{ navigation: any }> = ({ navigation }) => { const initialUser = useProfile() || { user_id: '9fe5cd7f-e563-4c7f-93ec-6de64e12b83e', email: 'radiologist@gmail.com', first_name: 'Aman', last_name: 'Kumar', display_name: 'Aman Kumar', dashboard_role: 'radiologist', hospital_id: '0240c6d9-415f-49c9-ae24-7eba4927f939', dashboard_settings: { theme: 'light', language: 'en', timezone: 'UTC', }, notification_preferences: { critical_alerts: { sms: true, push: true, email: true, in_app: true, }, system_notifications: { push: true, email: true, in_app: true, }, }, onboarding_completed: false, onboarding_step: 0, onboarding_message: 'You need to complete onboarding (change password and upload profile photo).', onboarded: false, profile_photo_url: null, theme_color: null, accent_color: null, }; // State for user data, notifications, and the edit modal const [user, setUser] = useState(initialUser); const [notifications, setNotifications] = useState(user.notification_preferences); const [isModalVisible, setModalVisible] = useState(false); const [editingField, setEditingField] = useState(''); const [currentValue, setCurrentValue] = useState(''); const dispatch=useDispatch(); const handleLogout = () => { Alert.alert('Log Out', 'Are you sure you want to log out?', [ { text: 'Cancel', style: 'cancel' }, { text: 'OK', onPress: () => dispatch(logout()) }, ]); }; // Updated handleEdit to open the modal const handleEdit = (field: string, value: string) => { setEditingField(field); setCurrentValue(value); setModalVisible(true); }; // New function to save changes from the modal const handleSave = () => { const updatedUser = { ...user }; if (editingField === 'First Name') { updatedUser.first_name = currentValue; } else if (editingField === 'Last Name') { updatedUser.last_name = currentValue; } updatedUser.display_name = `${updatedUser.first_name} ${updatedUser.last_name}`; setUser(updatedUser); setModalVisible(false); Alert.alert('Profile Updated', `${editingField} has been changed.`); }; const handleNotificationToggle = ( category: 'critical_alerts' | 'system_notifications', channel: string, ) => { const newPrefs = { ...notifications }; // Asserting the channel type to fix TypeScript indexing error (newPrefs[category] as any)[channel] = !(newPrefs[category] as any)[channel]; setNotifications(newPrefs); // In a real app, you would dispatch an action here to save the new preferences. Alert.alert( 'Preference Updated', `${channel.toUpperCase()} for ${category.replace('_', ' ')} has been ${ (newPrefs[category] as any)[channel] ? 'enabled' : 'disabled' }.`, ); }; return ( {/* Profile Section */} {user.display_name} {user.dashboard_role} {user.email} {/* Onboarding Section */} {!user.onboarding_completed && ( {user.onboarding_message} )} {/* Personal Information Section - New */} handleEdit('First Name', user.first_name)} /> handleEdit('Last Name', user.last_name)} /> {/* Settings Section */} {/* */} {/* Notification Preferences Section - Updated with Toggles */} Critical Alerts {Object.entries(notifications.critical_alerts).map(([channel, isEnabled]) => ( handleNotificationToggle('critical_alerts', channel)} /> ))} System Notifications {Object.entries(notifications.system_notifications).map( ([channel, isEnabled]) => ( handleNotificationToggle('system_notifications', channel)} /> ), )} {/* Actions Section */} navigation.navigate('Support')} /> {/* Edit Modal */} setModalVisible(false)}> Edit {editingField}