Compare commits
No commits in common. "4453a2a96c03ead6557a6062ee6cd7f18b5c190f" and "e442a9825a5cdada48782d5d97c78af2a7c77922" have entirely different histories.
4453a2a96c
...
e442a9825a
|
|
@ -1,11 +1,9 @@
|
||||||
import { useState } from "react";
|
|
||||||
import { Tabs, router } from "expo-router";
|
import { Tabs, router } from "expo-router";
|
||||||
import { Ionicons } from "@expo/vector-icons";
|
import { Ionicons } from "@expo/vector-icons";
|
||||||
import { Platform } from "react-native";
|
import { Alert, Platform } from "react-native";
|
||||||
import { AuthColors } from "@/features/auth/constants/colors";
|
import { AuthColors } from "@/features/auth/constants/colors";
|
||||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||||
import { useAuthStore } from "@/store/auth.store";
|
import { useAuthStore } from "@/store/auth.store";
|
||||||
import LogoutConfirmModal from "@/components/LogoutConfirmModal";
|
|
||||||
|
|
||||||
export default function TabsLayout() {
|
export default function TabsLayout() {
|
||||||
const insets = useSafeAreaInsets();
|
const insets = useSafeAreaInsets();
|
||||||
|
|
@ -15,24 +13,40 @@ export default function TabsLayout() {
|
||||||
|
|
||||||
const { accessToken, logout } = useAuthStore();
|
const { accessToken, logout } = useAuthStore();
|
||||||
const isAuthenticated = !!accessToken;
|
const isAuthenticated = !!accessToken;
|
||||||
const [logoutModalVisible, setLogoutModalVisible] = useState(false);
|
|
||||||
|
|
||||||
const doLogout = () => {
|
|
||||||
setLogoutModalVisible(false);
|
|
||||||
logout();
|
|
||||||
router.replace("/login");
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleAuthAction = () => {
|
const handleAuthAction = () => {
|
||||||
if (isAuthenticated) {
|
if (isAuthenticated) {
|
||||||
setLogoutModalVisible(true);
|
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 }
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
router.push("/login");
|
router.push("/login");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
|
||||||
<Tabs
|
<Tabs
|
||||||
screenOptions={{
|
screenOptions={{
|
||||||
headerShown: false,
|
headerShown: false,
|
||||||
|
|
@ -128,11 +142,5 @@ export default function TabsLayout() {
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
<LogoutConfirmModal
|
|
||||||
visible={logoutModalVisible}
|
|
||||||
onCancel={() => setLogoutModalVisible(false)}
|
|
||||||
onConfirm={doLogout}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,145 +0,0 @@
|
||||||
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 (
|
|
||||||
<Modal
|
|
||||||
visible={visible}
|
|
||||||
transparent
|
|
||||||
animationType="fade"
|
|
||||||
onRequestClose={onCancel}
|
|
||||||
>
|
|
||||||
<Pressable style={styles.backdrop} onPress={onCancel}>
|
|
||||||
<Pressable style={styles.card} onPress={() => {}}>
|
|
||||||
<View style={styles.iconContainer}>
|
|
||||||
<Ionicons name="log-out-outline" size={26} color="#DC2626" />
|
|
||||||
</View>
|
|
||||||
|
|
||||||
<Text style={styles.title}>Log Out</Text>
|
|
||||||
<Text style={styles.message}>
|
|
||||||
Are you sure you want to log out of Acupedia?
|
|
||||||
</Text>
|
|
||||||
|
|
||||||
<View style={styles.actions}>
|
|
||||||
<TouchableOpacity
|
|
||||||
style={[styles.button, styles.cancelButton]}
|
|
||||||
onPress={onCancel}
|
|
||||||
activeOpacity={0.8}
|
|
||||||
accessibilityRole="button"
|
|
||||||
accessibilityLabel="Cancel"
|
|
||||||
>
|
|
||||||
<Text style={styles.cancelText}>Cancel</Text>
|
|
||||||
</TouchableOpacity>
|
|
||||||
|
|
||||||
<TouchableOpacity
|
|
||||||
style={[styles.button, styles.confirmButton]}
|
|
||||||
onPress={onConfirm}
|
|
||||||
activeOpacity={0.8}
|
|
||||||
accessibilityRole="button"
|
|
||||||
accessibilityLabel="Log Out"
|
|
||||||
>
|
|
||||||
<Text style={styles.confirmText}>Log Out</Text>
|
|
||||||
</TouchableOpacity>
|
|
||||||
</View>
|
|
||||||
</Pressable>
|
|
||||||
</Pressable>
|
|
||||||
</Modal>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
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",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import React, { useState } from "react";
|
import React from "react";
|
||||||
import {
|
import {
|
||||||
|
Alert,
|
||||||
|
Platform,
|
||||||
ScrollView,
|
ScrollView,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
View,
|
View,
|
||||||
|
|
@ -19,23 +21,42 @@ import ProfileHeader from "@/features/profile/components/ProfileHeader";
|
||||||
import ProfileAvatar from "@/features/profile/components/ProfileAvatar";
|
import ProfileAvatar from "@/features/profile/components/ProfileAvatar";
|
||||||
import ProfileOverviewCard from "@/features/profile/components/ProfileOverviewCard";
|
import ProfileOverviewCard from "@/features/profile/components/ProfileOverviewCard";
|
||||||
import LogoutButton from "@/features/settings/components/LogoutButton";
|
import LogoutButton from "@/features/settings/components/LogoutButton";
|
||||||
import LogoutConfirmModal from "@/components/LogoutConfirmModal";
|
|
||||||
import { useAuthStore } from "@/store/auth.store";
|
import { useAuthStore } from "@/store/auth.store";
|
||||||
|
|
||||||
export default function ProfileOverviewScreen() {
|
export default function ProfileOverviewScreen() {
|
||||||
const { user, accessToken, logout } = useAuthStore();
|
const { user, accessToken, logout } = useAuthStore();
|
||||||
const [logoutModalVisible, setLogoutModalVisible] = useState(false);
|
|
||||||
const displayName = user?.name || "User Name";
|
const displayName = user?.name || "User Name";
|
||||||
const displayEmail = user?.email || "user@example.com";
|
const displayEmail = user?.email || "user@example.com";
|
||||||
|
|
||||||
const doLogout = () => {
|
|
||||||
setLogoutModalVisible(false);
|
|
||||||
logout();
|
|
||||||
router.replace("/login");
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleLogout = () => {
|
const handleLogout = () => {
|
||||||
setLogoutModalVisible(true);
|
const doLogout = () => {
|
||||||
|
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 }
|
||||||
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!accessToken) {
|
if (!accessToken) {
|
||||||
|
|
@ -104,12 +125,6 @@ export default function ProfileOverviewScreen() {
|
||||||
<LogoutButton onPress={handleLogout} />
|
<LogoutButton onPress={handleLogout} />
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
<LogoutConfirmModal
|
|
||||||
visible={logoutModalVisible}
|
|
||||||
onCancel={() => setLogoutModalVisible(false)}
|
|
||||||
onConfirm={doLogout}
|
|
||||||
/>
|
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import {
|
import {
|
||||||
|
Alert,
|
||||||
|
Platform,
|
||||||
ScrollView,
|
ScrollView,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
View,
|
View,
|
||||||
|
|
@ -12,7 +14,6 @@ import { Colors } from "@/theme";
|
||||||
import SettingsHeader from "@/features/settings/components/SettingsHeader";
|
import SettingsHeader from "@/features/settings/components/SettingsHeader";
|
||||||
import SettingsSection from "@/features/settings/components/SettingsSection";
|
import SettingsSection from "@/features/settings/components/SettingsSection";
|
||||||
import LogoutButton from "@/features/settings/components/LogoutButton";
|
import LogoutButton from "@/features/settings/components/LogoutButton";
|
||||||
import LogoutConfirmModal from "@/components/LogoutConfirmModal";
|
|
||||||
import {
|
import {
|
||||||
ACCOUNT_SETTINGS,
|
ACCOUNT_SETTINGS,
|
||||||
PREFERENCE_SETTINGS,
|
PREFERENCE_SETTINGS,
|
||||||
|
|
@ -27,7 +28,6 @@ import EnvironmentSelectorModal from "@/components/EnvironmentSelectorModal";
|
||||||
|
|
||||||
export default function SettingsScreen() {
|
export default function SettingsScreen() {
|
||||||
const [envModalVisible, setEnvModalVisible] = useState(false);
|
const [envModalVisible, setEnvModalVisible] = useState(false);
|
||||||
const [logoutModalVisible, setLogoutModalVisible] = useState(false);
|
|
||||||
const activeConfig = useEnvironmentStore((state) => state.getActiveConfig());
|
const activeConfig = useEnvironmentStore((state) => state.getActiveConfig());
|
||||||
const user = useAuthStore((state) => state.user);
|
const user = useAuthStore((state) => state.user);
|
||||||
const logout = useAuthStore((state) => state.logout);
|
const logout = useAuthStore((state) => state.logout);
|
||||||
|
|
@ -87,14 +87,35 @@ export default function SettingsScreen() {
|
||||||
: []),
|
: []),
|
||||||
];
|
];
|
||||||
|
|
||||||
const doLogout = () => {
|
|
||||||
setLogoutModalVisible(false);
|
|
||||||
logout();
|
|
||||||
router.replace("/login");
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleLogout = () => {
|
const handleLogout = () => {
|
||||||
setLogoutModalVisible(true);
|
const doLogout = () => {
|
||||||
|
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 }
|
||||||
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -132,12 +153,6 @@ export default function SettingsScreen() {
|
||||||
onClose={() => setEnvModalVisible(false)}
|
onClose={() => setEnvModalVisible(false)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<LogoutConfirmModal
|
|
||||||
visible={logoutModalVisible}
|
|
||||||
onCancel={() => setLogoutModalVisible(false)}
|
|
||||||
onConfirm={doLogout}
|
|
||||||
/>
|
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue