diff --git a/src/app/(tabs)/_layout.tsx b/src/app/(tabs)/_layout.tsx index 74e0d2f..8df2038 100644 --- a/src/app/(tabs)/_layout.tsx +++ b/src/app/(tabs)/_layout.tsx @@ -1,9 +1,11 @@ +import { useState } from "react"; import { Tabs, router } from "expo-router"; import { Ionicons } from "@expo/vector-icons"; -import { Alert, Platform } from "react-native"; +import { Platform } from "react-native"; import { AuthColors } from "@/features/auth/constants/colors"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { useAuthStore } from "@/store/auth.store"; +import LogoutConfirmModal from "@/components/LogoutConfirmModal"; export default function TabsLayout() { const insets = useSafeAreaInsets(); @@ -13,40 +15,24 @@ export default function TabsLayout() { const { accessToken, logout } = useAuthStore(); const isAuthenticated = !!accessToken; + const [logoutModalVisible, setLogoutModalVisible] = useState(false); + + const doLogout = () => { + setLogoutModalVisible(false); + logout(); + router.replace("/login"); + }; const handleAuthAction = () => { if (isAuthenticated) { - const doLogout = () => { - logout(); - router.replace("/login"); - }; - - if (Platform.OS === "web") { - const confirmed = typeof window !== "undefined" ? window.confirm("Are you sure you want to logout?") : true; - if (confirmed) { - doLogout(); - } - } else { - Alert.alert( - "Logout", - "Are you sure you want to logout?", - [ - { text: "Cancel", style: "cancel" }, - { - text: "Yes", - style: "destructive", - onPress: doLogout, - }, - ], - { cancelable: true } - ); - } + setLogoutModalVisible(true); } else { router.push("/login"); } }; return ( + <> + setLogoutModalVisible(false)} + onConfirm={doLogout} + /> + ); } diff --git a/src/components/LogoutConfirmModal.tsx b/src/components/LogoutConfirmModal.tsx new file mode 100644 index 0000000..26dc327 --- /dev/null +++ b/src/components/LogoutConfirmModal.tsx @@ -0,0 +1,145 @@ +import React from "react"; +import { + Modal, + Pressable, + StyleSheet, + Text, + TouchableOpacity, + View, +} from "react-native"; +import { Ionicons } from "@expo/vector-icons"; +import { moderateScale, scale, verticalScale } from "react-native-size-matters"; + +import { Colors } from "@/theme"; + +interface LogoutConfirmModalProps { + visible: boolean; + onCancel: () => void; + onConfirm: () => void; +} + +export default function LogoutConfirmModal({ + visible, + onCancel, + onConfirm, +}: LogoutConfirmModalProps) { + return ( + + + {}}> + + + + + Log Out + + Are you sure you want to log out of Acupedia? + + + + + Cancel + + + + Log Out + + + + + + ); +} + +const styles = StyleSheet.create({ + backdrop: { + flex: 1, + backgroundColor: "rgba(15, 23, 42, 0.55)", + justifyContent: "center", + alignItems: "center", + paddingHorizontal: scale(24), + }, + card: { + width: "100%", + maxWidth: 360, + backgroundColor: Colors.surface ?? "#FFFFFF", + borderRadius: moderateScale(20), + padding: moderateScale(22), + alignItems: "center", + shadowColor: "#000", + shadowOffset: { width: 0, height: 10 }, + shadowOpacity: 0.18, + shadowRadius: 20, + elevation: 8, + }, + iconContainer: { + width: scale(48), + height: scale(48), + borderRadius: scale(24), + backgroundColor: "#FEE2E2", + justifyContent: "center", + alignItems: "center", + marginBottom: verticalScale(12), + }, + title: { + fontSize: moderateScale(18), + fontWeight: "700", + color: Colors.textPrimary ?? "#0F172A", + marginBottom: verticalScale(6), + textAlign: "center", + }, + message: { + fontSize: moderateScale(14), + color: Colors.textSecondary ?? "#475569", + textAlign: "center", + lineHeight: moderateScale(20), + marginBottom: verticalScale(20), + }, + actions: { + flexDirection: "row", + gap: scale(10), + width: "100%", + }, + button: { + flex: 1, + paddingVertical: verticalScale(11), + borderRadius: moderateScale(12), + alignItems: "center", + justifyContent: "center", + }, + cancelButton: { + backgroundColor: "#F1F5F9", + borderWidth: 1, + borderColor: "#E2E8F0", + }, + confirmButton: { + backgroundColor: "#DC2626", + }, + cancelText: { + fontSize: moderateScale(14), + fontWeight: "600", + color: "#334155", + }, + confirmText: { + fontSize: moderateScale(14), + fontWeight: "700", + color: "#FFFFFF", + }, +}); diff --git a/src/screens/profile/ProfileOverviewScreen.tsx b/src/screens/profile/ProfileOverviewScreen.tsx index 1c089f2..d858c95 100644 --- a/src/screens/profile/ProfileOverviewScreen.tsx +++ b/src/screens/profile/ProfileOverviewScreen.tsx @@ -1,7 +1,5 @@ -import React from "react"; +import React, { useState } from "react"; import { - Alert, - Platform, ScrollView, StyleSheet, View, @@ -21,42 +19,23 @@ import ProfileHeader from "@/features/profile/components/ProfileHeader"; import ProfileAvatar from "@/features/profile/components/ProfileAvatar"; import ProfileOverviewCard from "@/features/profile/components/ProfileOverviewCard"; import LogoutButton from "@/features/settings/components/LogoutButton"; +import LogoutConfirmModal from "@/components/LogoutConfirmModal"; import { useAuthStore } from "@/store/auth.store"; export default function ProfileOverviewScreen() { const { user, accessToken, logout } = useAuthStore(); + const [logoutModalVisible, setLogoutModalVisible] = useState(false); const displayName = user?.name || "User Name"; const displayEmail = user?.email || "user@example.com"; - const handleLogout = () => { - const doLogout = () => { - logout(); - router.replace("/login"); - }; + const doLogout = () => { + setLogoutModalVisible(false); + logout(); + router.replace("/login"); + }; - if (Platform.OS === "web") { - const confirmed = - typeof window !== "undefined" - ? window.confirm("Are you sure you want to log out?") - : true; - if (confirmed) { - doLogout(); - } - } else { - Alert.alert( - "Log Out", - "Are you sure you want to log out of Acupedia?", - [ - { text: "Cancel", style: "cancel" }, - { - text: "Log Out", - style: "destructive", - onPress: doLogout, - }, - ], - { cancelable: true } - ); - } + const handleLogout = () => { + setLogoutModalVisible(true); }; if (!accessToken) { @@ -125,6 +104,12 @@ export default function ProfileOverviewScreen() { + + setLogoutModalVisible(false)} + onConfirm={doLogout} + /> ); } diff --git a/src/screens/settings/SettingsScreen.tsx b/src/screens/settings/SettingsScreen.tsx index 20ac161..9bd0221 100644 --- a/src/screens/settings/SettingsScreen.tsx +++ b/src/screens/settings/SettingsScreen.tsx @@ -1,7 +1,5 @@ import React, { useState } from "react"; import { - Alert, - Platform, ScrollView, StyleSheet, View, @@ -14,6 +12,7 @@ import { Colors } from "@/theme"; import SettingsHeader from "@/features/settings/components/SettingsHeader"; import SettingsSection from "@/features/settings/components/SettingsSection"; import LogoutButton from "@/features/settings/components/LogoutButton"; +import LogoutConfirmModal from "@/components/LogoutConfirmModal"; import { ACCOUNT_SETTINGS, PREFERENCE_SETTINGS, @@ -28,6 +27,7 @@ import EnvironmentSelectorModal from "@/components/EnvironmentSelectorModal"; export default function SettingsScreen() { const [envModalVisible, setEnvModalVisible] = useState(false); + const [logoutModalVisible, setLogoutModalVisible] = useState(false); const activeConfig = useEnvironmentStore((state) => state.getActiveConfig()); const user = useAuthStore((state) => state.user); const logout = useAuthStore((state) => state.logout); @@ -87,35 +87,14 @@ export default function SettingsScreen() { : []), ]; - const handleLogout = () => { - const doLogout = () => { - logout(); - router.replace("/login"); - }; + const doLogout = () => { + setLogoutModalVisible(false); + logout(); + router.replace("/login"); + }; - if (Platform.OS === "web") { - const confirmed = - typeof window !== "undefined" - ? window.confirm("Are you sure you want to log out?") - : true; - if (confirmed) { - doLogout(); - } - } else { - Alert.alert( - "Log Out", - "Are you sure you want to log out of Acupedia?", - [ - { text: "Cancel", style: "cancel" }, - { - text: "Log Out", - style: "destructive", - onPress: doLogout, - }, - ], - { cancelable: true } - ); - } + const handleLogout = () => { + setLogoutModalVisible(true); }; return ( @@ -153,6 +132,12 @@ export default function SettingsScreen() { onClose={() => setEnvModalVisible(false)} /> )} + + setLogoutModalVisible(false)} + onConfirm={doLogout} + /> ); }