Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 | import React, { useState } from 'react';
import {
View,
Text,
StyleSheet,
ScrollView,
Switch,
TouchableOpacity,
Alert,
TextInput,
Modal,
} from 'react-native';
import { Ionicons } from '@expo/vector-icons';
import { SafeAreaView } from 'react-native-safe-area-context';
import { router } from 'expo-router';
import { useAuth } from '@/contexts/AuthContext';
import { AppColors, BorderRadius, FontSizes, Spacing } from '@/constants/theme';
import { PageHeader } from '@/components/PageHeader';
interface SecurityItemProps {
icon: keyof typeof Ionicons.glyphMap;
iconColor: string;
iconBgColor: string;
title: string;
description: string;
onPress: () => void;
rightElement?: React.ReactNode;
}
function SecurityItem({
icon,
iconColor,
iconBgColor,
title,
description,
onPress,
rightElement,
}: SecurityItemProps) {
return (
<TouchableOpacity style={styles.securityRow} onPress={onPress}>
<View style={[styles.iconContainer, { backgroundColor: iconBgColor }]}>
<Ionicons name={icon} size={20} color={iconColor} />
</View>
<View style={styles.securityContent}>
<Text style={styles.securityTitle}>{title}</Text>
<Text style={styles.securityDescription}>{description}</Text>
</View>
{rightElement || <Ionicons name="chevron-forward" size={20} color={AppColors.textMuted} />}
</TouchableOpacity>
);
}
export default function PrivacyScreen() {
const { logout } = useAuth();
const [twoFactor, setTwoFactor] = useState(false);
const [biometric, setBiometric] = useState(false);
const [showPasswordModal, setShowPasswordModal] = useState(false);
const [currentPassword, setCurrentPassword] = useState('');
const [newPassword, setNewPassword] = useState('');
const [confirmPassword, setConfirmPassword] = useState('');
const handleChangePassword = () => {
setShowPasswordModal(true);
};
const handlePasswordSubmit = () => {
if (!currentPassword || !newPassword || !confirmPassword) {
Alert.alert('Error', 'Please fill in all fields');
return;
}
if (newPassword !== confirmPassword) {
Alert.alert('Error', 'New passwords do not match');
return;
}
if (newPassword.length < 8) {
Alert.alert('Error', 'Password must be at least 8 characters');
return;
}
setShowPasswordModal(false);
setCurrentPassword('');
setNewPassword('');
setConfirmPassword('');
Alert.alert('Success', 'Your password has been changed successfully.');
};
const handleEnable2FA = (value: boolean) => {
if (value) {
Alert.alert(
'Enable Two-Factor Authentication',
'This will add an extra layer of security to your account. You will need to enter a code from your authenticator app when signing in.',
[
{ text: 'Cancel', style: 'cancel' },
{
text: 'Enable',
onPress: () => {
setTwoFactor(true);
Alert.alert(
'Scan QR Code',
'Open your authenticator app (Google Authenticator, Authy, etc.) and scan the QR code.',
[{ text: 'Done' }]
);
}
},
]
);
} else {
Alert.alert(
'Disable Two-Factor Authentication',
'Are you sure? This will make your account less secure.',
[
{ text: 'Cancel', style: 'cancel' },
{
text: 'Disable',
style: 'destructive',
onPress: () => setTwoFactor(false)
},
]
);
}
};
const handleManageSessions = () => {
Alert.alert(
'Active Sessions',
'You are currently signed in on:\n\n' +
'• iPhone 14 Pro (This device)\n Last active: Just now\n\n' +
'• Chrome on MacBook Pro\n Last active: 2 hours ago\n\n' +
'• Safari on iPad\n Last active: 3 days ago',
[
{ text: 'Close' },
{
text: 'Sign Out All',
style: 'destructive',
onPress: () => {
Alert.alert(
'Sign Out All Devices',
'This will sign you out of all devices including this one.',
[
{ text: 'Cancel', style: 'cancel' },
{
text: 'Sign Out All',
style: 'destructive',
onPress: async () => {
await logout();
router.replace('/(auth)/login');
}
},
]
);
}
},
]
);
};
const handleExportData = () => {
Alert.alert(
'Export Your Data',
'We will prepare a downloadable file containing all your data. This may take a few minutes.\n\nYou will receive an email when your data is ready.',
[
{ text: 'Cancel', style: 'cancel' },
{
text: 'Request Export',
onPress: () => Alert.alert('Request Sent', 'You will receive an email when your data export is ready.')
},
]
);
};
const handleDeleteAccount = () => {
Alert.alert(
'Delete Account',
'Are you absolutely sure you want to delete your account?\n\n' +
'• All your data will be permanently deleted\n' +
'• You will lose access to all beneficiary data\n' +
'• This action cannot be undone',
[
{ text: 'Cancel', style: 'cancel' },
{
text: 'Delete Account',
style: 'destructive',
onPress: () => {
Alert.alert(
'Final Confirmation',
'Type "DELETE" to confirm account deletion.',
[{ text: 'Cancel', style: 'cancel' }]
);
}
},
]
);
};
return (
<SafeAreaView style={styles.container} edges={['top', 'bottom']}>
<PageHeader title="Privacy & Security" />
<ScrollView showsVerticalScrollIndicator={false}>
{/* Password & Authentication */}
<View style={styles.section}>
<Text style={styles.sectionTitle}>Authentication</Text>
<View style={styles.card}>
<SecurityItem
icon="key"
iconColor="#3B82F6"
iconBgColor="#DBEAFE"
title="Change Password"
description="Update your account password"
onPress={handleChangePassword}
/>
<View style={styles.divider} />
<SecurityItem
icon="shield-checkmark"
iconColor="#10B981"
iconBgColor="#D1FAE5"
title="Two-Factor Authentication"
description={twoFactor ? 'Enabled' : 'Not enabled'}
onPress={() => handleEnable2FA(!twoFactor)}
rightElement={
<Switch
value={twoFactor}
onValueChange={handleEnable2FA}
trackColor={{ false: '#E5E7EB', true: AppColors.primaryLight }}
thumbColor={twoFactor ? AppColors.primary : '#9CA3AF'}
/>
}
/>
<View style={styles.divider} />
<SecurityItem
icon="finger-print"
iconColor="#8B5CF6"
iconBgColor="#EDE9FE"
title="Biometric Login"
description="Face ID / Touch ID"
onPress={() => setBiometric(!biometric)}
rightElement={
<Switch
value={biometric}
onValueChange={setBiometric}
trackColor={{ false: '#E5E7EB', true: AppColors.primaryLight }}
thumbColor={biometric ? AppColors.primary : '#9CA3AF'}
/>
}
/>
</View>
</View>
{/* Session Management */}
<View style={styles.section}>
<Text style={styles.sectionTitle}>Sessions</Text>
<View style={styles.card}>
<SecurityItem
icon="phone-portrait"
iconColor="#F59E0B"
iconBgColor="#FEF3C7"
title="Manage Sessions"
description="View and manage active devices"
onPress={handleManageSessions}
/>
</View>
</View>
{/* Data & Privacy */}
<View style={styles.section}>
<Text style={styles.sectionTitle}>Data & Privacy</Text>
<View style={styles.card}>
<SecurityItem
icon="download"
iconColor="#6366F1"
iconBgColor="#E0E7FF"
title="Export Your Data"
description="Download a copy of your data"
onPress={handleExportData}
/>
<View style={styles.divider} />
<SecurityItem
icon="eye-off"
iconColor="#EC4899"
iconBgColor="#FCE7F3"
title="Data Sharing"
description="Control who can see your data"
onPress={() => Alert.alert('Data Sharing', 'Your data is only shared with authorized caregivers and healthcare providers you designate.')}
/>
</View>
</View>
{/* Login History */}
<View style={styles.section}>
<Text style={styles.sectionTitle}>Recent Activity</Text>
<View style={styles.card}>
<View style={styles.activityItem}>
<View style={styles.activityDot} />
<View style={styles.activityContent}>
<Text style={styles.activityTitle}>Login from iPhone</Text>
<Text style={styles.activityMeta}>Today at 2:34 PM • San Francisco, CA</Text>
</View>
</View>
<View style={styles.activityItem}>
<View style={[styles.activityDot, styles.activityDotOld]} />
<View style={styles.activityContent}>
<Text style={styles.activityTitle}>Login from MacBook</Text>
<Text style={styles.activityMeta}>Yesterday at 10:15 AM • San Francisco, CA</Text>
</View>
</View>
<View style={styles.activityItem}>
<View style={[styles.activityDot, styles.activityDotOld]} />
<View style={styles.activityContent}>
<Text style={styles.activityTitle}>Password changed</Text>
<Text style={styles.activityMeta}>Dec 1, 2024 at 4:22 PM</Text>
</View>
</View>
</View>
</View>
{/* Danger Zone */}
<View style={styles.section}>
<Text style={[styles.sectionTitle, { color: AppColors.error }]}>Danger Zone</Text>
<View style={styles.card}>
<TouchableOpacity style={styles.dangerButton} onPress={handleDeleteAccount}>
<Ionicons name="trash" size={20} color={AppColors.error} />
<Text style={styles.dangerButtonText}>Delete Account</Text>
</TouchableOpacity>
</View>
</View>
</ScrollView>
{/* Password Change Modal */}
<Modal
visible={showPasswordModal}
animationType="slide"
presentationStyle="pageSheet"
onRequestClose={() => setShowPasswordModal(false)}
>
<SafeAreaView style={styles.modalContainer} edges={['top', 'bottom']}>
<View style={styles.modalHeader}>
<TouchableOpacity onPress={() => setShowPasswordModal(false)}>
<Text style={styles.cancelText}>Cancel</Text>
</TouchableOpacity>
<Text style={styles.modalTitle}>Change Password</Text>
<TouchableOpacity onPress={handlePasswordSubmit}>
<Text style={styles.saveText}>Save</Text>
</TouchableOpacity>
</View>
<ScrollView style={styles.modalContent}>
<View style={styles.inputGroup}>
<Text style={styles.label}>Current Password</Text>
<TextInput
style={styles.input}
value={currentPassword}
onChangeText={setCurrentPassword}
placeholder="Enter current password"
placeholderTextColor={AppColors.textMuted}
secureTextEntry
/>
</View>
<View style={styles.inputGroup}>
<Text style={styles.label}>New Password</Text>
<TextInput
style={styles.input}
value={newPassword}
onChangeText={setNewPassword}
placeholder="Enter new password"
placeholderTextColor={AppColors.textMuted}
secureTextEntry
/>
<Text style={styles.hint}>Must be at least 8 characters</Text>
</View>
<View style={styles.inputGroup}>
<Text style={styles.label}>Confirm New Password</Text>
<TextInput
style={styles.input}
value={confirmPassword}
onChangeText={setConfirmPassword}
placeholder="Confirm new password"
placeholderTextColor={AppColors.textMuted}
secureTextEntry
/>
</View>
<View style={styles.passwordRequirements}>
<Text style={styles.requirementsTitle}>Password Requirements:</Text>
<Text style={styles.requirementItem}>• At least 8 characters</Text>
<Text style={styles.requirementItem}>• Mix of letters and numbers recommended</Text>
<Text style={styles.requirementItem}>• Special characters for extra security</Text>
</View>
</ScrollView>
</SafeAreaView>
</Modal>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: AppColors.surface,
},
section: {
marginTop: Spacing.md,
},
sectionTitle: {
fontSize: FontSizes.sm,
fontWeight: '600',
color: AppColors.textSecondary,
paddingHorizontal: Spacing.lg,
paddingVertical: Spacing.sm,
textTransform: 'uppercase',
},
card: {
backgroundColor: AppColors.background,
},
securityRow: {
flexDirection: 'row',
alignItems: 'center',
paddingVertical: Spacing.md,
paddingHorizontal: Spacing.lg,
},
iconContainer: {
width: 40,
height: 40,
borderRadius: BorderRadius.md,
justifyContent: 'center',
alignItems: 'center',
},
securityContent: {
flex: 1,
marginLeft: Spacing.md,
},
securityTitle: {
fontSize: FontSizes.base,
fontWeight: '500',
color: AppColors.textPrimary,
},
securityDescription: {
fontSize: FontSizes.xs,
color: AppColors.textMuted,
marginTop: 2,
},
divider: {
height: 1,
backgroundColor: AppColors.border,
marginLeft: Spacing.lg + 40 + Spacing.md,
},
activityItem: {
flexDirection: 'row',
alignItems: 'center',
paddingVertical: Spacing.md,
paddingHorizontal: Spacing.lg,
},
activityDot: {
width: 8,
height: 8,
borderRadius: 4,
backgroundColor: AppColors.success,
marginRight: Spacing.md,
},
activityDotOld: {
backgroundColor: AppColors.textMuted,
},
activityContent: {
flex: 1,
},
activityTitle: {
fontSize: FontSizes.sm,
fontWeight: '500',
color: AppColors.textPrimary,
},
activityMeta: {
fontSize: FontSizes.xs,
color: AppColors.textMuted,
marginTop: 2,
},
dangerButton: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
paddingVertical: Spacing.md,
},
dangerButtonText: {
fontSize: FontSizes.base,
fontWeight: '500',
color: AppColors.error,
marginLeft: Spacing.sm,
},
// Modal styles
modalContainer: {
flex: 1,
backgroundColor: AppColors.surface,
},
modalHeader: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
paddingHorizontal: Spacing.lg,
paddingVertical: Spacing.md,
backgroundColor: AppColors.background,
borderBottomWidth: 1,
borderBottomColor: AppColors.border,
},
modalTitle: {
fontSize: FontSizes.lg,
fontWeight: '600',
color: AppColors.textPrimary,
},
cancelText: {
fontSize: FontSizes.base,
color: AppColors.textSecondary,
},
saveText: {
fontSize: FontSizes.base,
fontWeight: '600',
color: AppColors.primary,
},
modalContent: {
padding: Spacing.lg,
},
inputGroup: {
marginBottom: Spacing.lg,
},
label: {
fontSize: FontSizes.sm,
fontWeight: '600',
color: AppColors.textPrimary,
marginBottom: Spacing.xs,
},
input: {
backgroundColor: AppColors.background,
borderRadius: BorderRadius.md,
paddingHorizontal: Spacing.md,
paddingVertical: Spacing.md,
fontSize: FontSizes.base,
color: AppColors.textPrimary,
borderWidth: 1,
borderColor: AppColors.border,
},
hint: {
fontSize: FontSizes.xs,
color: AppColors.textMuted,
marginTop: Spacing.xs,
},
passwordRequirements: {
backgroundColor: AppColors.background,
borderRadius: BorderRadius.lg,
padding: Spacing.md,
marginTop: Spacing.md,
},
requirementsTitle: {
fontSize: FontSizes.sm,
fontWeight: '600',
color: AppColors.textSecondary,
marginBottom: Spacing.sm,
},
requirementItem: {
fontSize: FontSizes.sm,
color: AppColors.textMuted,
marginBottom: 4,
},
});
|