Merge pull request 'fix(mobile): unify logout confirmation modal and button labels across platforms' (#134) from fix/consistent-logout-confirmation into main
Reviewed-on: https://git.zedobject.local/AcuPedia/acupedia-mobile-ui/pulls/134 Reviewed-by: Amit Salunke <amit@noreply.localhost>
This commit is contained in:
commit
4453a2a96c
|
|
@ -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 (
|
||||
<>
|
||||
<Tabs
|
||||
screenOptions={{
|
||||
headerShown: false,
|
||||
|
|
@ -142,5 +128,11 @@ export default function TabsLayout() {
|
|||
}}
|
||||
/>
|
||||
</Tabs>
|
||||
<LogoutConfirmModal
|
||||
visible={logoutModalVisible}
|
||||
onCancel={() => setLogoutModalVisible(false)}
|
||||
onConfirm={doLogout}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<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,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() {
|
|||
<LogoutButton onPress={handleLogout} />
|
||||
</View>
|
||||
</ScrollView>
|
||||
|
||||
<LogoutConfirmModal
|
||||
visible={logoutModalVisible}
|
||||
onCancel={() => setLogoutModalVisible(false)}
|
||||
onConfirm={doLogout}
|
||||
/>
|
||||
</SafeAreaView>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)}
|
||||
/>
|
||||
)}
|
||||
|
||||
<LogoutConfirmModal
|
||||
visible={logoutModalVisible}
|
||||
onCancel={() => setLogoutModalVisible(false)}
|
||||
onConfirm={doLogout}
|
||||
/>
|
||||
</SafeAreaView>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue