From 5c4cb83376b1f598c67b854a4cf161a34a368ff1 Mon Sep 17 00:00:00 2001 From: Urvish Date: Mon, 28 Sep 2026 13:02:52 +0530 Subject: [PATCH] Updated profile, added polished settings page, added restrictions for screenshot and screen recording --- .env | 12 +- package-lock.json | 11 + package.json | 21 +- src/app/_layout.tsx | 23 ++ src/app/profile/change-password.tsx | 186 +++++++++++++ src/app/profile/edit.tsx | 5 + src/app/settings/about.tsx | 159 +++++++++++ src/app/settings/help-support.tsx | 239 +++++++++++++++++ src/app/settings/index.tsx | 5 + src/app/settings/language.tsx | 232 ++++++++++++++++ src/app/settings/notifications.tsx | 144 ++++++++++ src/app/settings/privacy.tsx | 171 ++++++++++++ .../renderers/shared/AccordionSection.tsx | 6 +- .../content/renderers/shared/SectionCard.tsx | 12 +- .../profile/components/EditProfileAvatar.tsx | 100 +++---- .../profile/components/EditProfileForm.tsx | 249 ++++++++++++++---- .../profile/components/ProfileAvatar.tsx | 123 +++------ .../profile/components/ProfileHeader.tsx | 93 ++++--- .../profile/components/ProfileMenuItem.tsx | 14 +- .../components/ProfileOverviewCard.tsx | 98 ++++--- .../settings/components/LogoutButton.tsx | 62 +++++ .../settings/components/SettingsHeader.tsx | 118 +++++++++ .../settings/components/SettingsSection.tsx | 75 ++++++ .../settings/constants/settingsData.ts | 61 +++++ src/features/settings/types.ts | 19 ++ src/screens/profile/EditProfileScreen.tsx | 92 ++++--- src/screens/profile/ProfileOverviewScreen.tsx | 94 +++---- src/screens/settings/SettingsScreen.tsx | 150 +++++++++++ src/store/auth.store.ts | 15 +- src/store/settings.store.ts | 70 ++++- src/store/types.ts | 17 +- 31 files changed, 2253 insertions(+), 423 deletions(-) create mode 100644 src/app/profile/change-password.tsx create mode 100644 src/app/profile/edit.tsx create mode 100644 src/app/settings/about.tsx create mode 100644 src/app/settings/help-support.tsx create mode 100644 src/app/settings/index.tsx create mode 100644 src/app/settings/language.tsx create mode 100644 src/app/settings/notifications.tsx create mode 100644 src/app/settings/privacy.tsx create mode 100644 src/features/settings/components/LogoutButton.tsx create mode 100644 src/features/settings/components/SettingsHeader.tsx create mode 100644 src/features/settings/components/SettingsSection.tsx create mode 100644 src/features/settings/constants/settingsData.ts create mode 100644 src/features/settings/types.ts create mode 100644 src/screens/settings/SettingsScreen.tsx diff --git a/.env b/.env index 5e71768..995ef99 100644 --- a/.env +++ b/.env @@ -17,11 +17,11 @@ # old working .env file # Production Dev -# EXPO_PUBLIC_API_URL=https://api.acupedia.in/api -# EXPO_PUBLIC_STOREFRONT_URL=https://acupedia.in/store -# EXPO_PUBLIC_CONTENT_PREVIEW_ENABLED=false +EXPO_PUBLIC_API_URL=https://api.acupedia.in/api +EXPO_PUBLIC_STOREFRONT_URL=https://acupedia.in/store +EXPO_PUBLIC_CONTENT_PREVIEW_ENABLED=true # Local Dev -EXPO_PUBLIC_API_URL=http://localhost:8000/api -EXPO_PUBLIC_STOREFRONT_URL=http://localhost:3000 -EXPO_PUBLIC_CONTENT_PREVIEW_ENABLED=true \ No newline at end of file +# EXPO_PUBLIC_API_URL=http://localhost:8000/api +# EXPO_PUBLIC_STOREFRONT_URL=http://localhost:3000 +# EXPO_PUBLIC_CONTENT_PREVIEW_ENABLED=true \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index edfe0a1..c13f253 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ "expo-linear-gradient": "~57.0.1", "expo-linking": "~57.0.9", "expo-router": "~57.0.19", + "expo-screen-capture": "~57.0.3", "expo-secure-store": "~57.0.2", "expo-splash-screen": "~57.0.8", "expo-status-bar": "~57.0.1", @@ -4114,6 +4115,16 @@ } } }, + "node_modules/expo-screen-capture": { + "version": "57.0.3", + "resolved": "https://registry.npmjs.org/expo-screen-capture/-/expo-screen-capture-57.0.3.tgz", + "integrity": "sha512-EpTd6tBgX2nWKJUvYDIrnsC2xWGJnlOLqN48EzLwPTQlbbwDUeWwt+4RDZOyFkWCa67XiUbrzIEOJApNBVZSow==", + "license": "MIT", + "peerDependencies": { + "expo": "*", + "react": "*" + } + }, "node_modules/expo-secure-store": { "version": "57.0.3", "resolved": "https://registry.npmjs.org/expo-secure-store/-/expo-secure-store-57.0.3.tgz", diff --git a/package.json b/package.json index e09c599..60d0bd8 100644 --- a/package.json +++ b/package.json @@ -3,15 +3,24 @@ "main": "expo-router/entry", "version": "1.0.0", "dependencies": { + "@expo-google-fonts/inter": "^0.4.2", "@expo/ui": "~57.0.16", + "@expo/vector-icons": "^15.0.2", + "@react-native-async-storage/async-storage": "2.2.0", + "@react-native-community/netinfo": "12.0.1", + "@tanstack/react-query": "^5.101.2", + "axios": "^1.18.1", "expo": "~57.0.20", "expo-constants": "~57.0.17", "expo-device": "~57.0.1", "expo-font": "~57.0.3", "expo-glass-effect": "~57.0.1", "expo-image": "~57.0.4", + "expo-linear-gradient": "~57.0.1", "expo-linking": "~57.0.9", "expo-router": "~57.0.19", + "expo-screen-capture": "~57.0.3", + "expo-secure-store": "~57.0.2", "expo-splash-screen": "~57.0.8", "expo-status-bar": "~57.0.1", "expo-symbols": "~57.0.2", @@ -24,18 +33,10 @@ "react-native-reanimated": "4.5.1", "react-native-safe-area-context": "~5.7.0", "react-native-screens": "~4.26.0", - "react-native-web": "~0.21.0", - "react-native-worklets": "0.10.1", - "@expo-google-fonts/inter": "^0.4.2", - "@expo/vector-icons": "^15.0.2", - "@react-native-async-storage/async-storage": "2.2.0", - "@react-native-community/netinfo": "12.0.1", - "@tanstack/react-query": "^5.101.2", - "axios": "^1.18.1", - "expo-linear-gradient": "~57.0.1", - "expo-secure-store": "~57.0.2", "react-native-size-matters": "^0.4.2", "react-native-toast-message": "^2.3.3", + "react-native-web": "~0.21.0", + "react-native-worklets": "0.10.1", "zustand": "^4.5.7" }, "devDependencies": { diff --git a/src/app/_layout.tsx b/src/app/_layout.tsx index 64aaaa5..6611ac0 100644 --- a/src/app/_layout.tsx +++ b/src/app/_layout.tsx @@ -105,7 +105,10 @@ try { // Silently ignore if module exports are immutable in web bundle environment } +import { useEffect } from "react"; +import { Alert, Platform } from "react-native"; import { GestureHandlerRootView } from "react-native-gesture-handler"; +import * as ScreenCapture from "expo-screen-capture"; export default function RootLayout() { const [fontsLoaded] = useFonts({ @@ -115,6 +118,26 @@ export default function RootLayout() { "Inter-Bold": Inter_700Bold, }); + useEffect(() => { + if (Platform.OS === "web") return; + + let isMounted = true; + void ScreenCapture.preventScreenCaptureAsync(); + + const subscription = ScreenCapture.addScreenshotListener(() => { + if (!isMounted) return; + Alert.alert( + "Confidential Clinical Content", + "Acupedia clinical reference materials and diagrams are proprietary. Capturing screenshots is restricted to protect clinical data." + ); + }); + + return () => { + isMounted = false; + subscription?.remove(); + }; + }, []); + if (!fontsLoaded) { return null; } diff --git a/src/app/profile/change-password.tsx b/src/app/profile/change-password.tsx new file mode 100644 index 0000000..6a39621 --- /dev/null +++ b/src/app/profile/change-password.tsx @@ -0,0 +1,186 @@ +import React, { useState } from "react"; +import { + KeyboardAvoidingView, + Platform, + ScrollView, + StyleSheet, + View, + Alert, +} from "react-native"; +import { SafeAreaView } from "react-native-safe-area-context"; +import { router } from "expo-router"; +import { moderateScale, verticalScale } from "react-native-size-matters"; + +import SettingsHeader from "@/features/settings/components/SettingsHeader"; +import PasswordInput from "@/components/forms/PasswordInput"; +import PrimaryButton from "@/components/buttons/PrimaryButton"; +import FieldLabel from "@/components/forms/FieldLabel"; +import { Colors } from "@/theme"; +import { apiClient } from "@/api"; + +export default function ChangePasswordScreen() { + const [currentPassword, setCurrentPassword] = useState(""); + const [newPassword, setNewPassword] = useState(""); + const [confirmPassword, setConfirmPassword] = useState(""); + + const [currentError, setCurrentError] = useState(""); + const [newError, setNewError] = useState(""); + const [confirmError, setConfirmError] = useState(""); + const [isLoading, setIsLoading] = useState(false); + + const handleUpdatePassword = async () => { + let hasError = false; + setCurrentError(""); + setNewError(""); + setConfirmError(""); + + if (!currentPassword) { + setCurrentError("Current password is required"); + hasError = true; + } + + if (!newPassword) { + setNewError("New password is required"); + hasError = true; + } else if (newPassword.length < 8) { + setNewError("New password must be at least 8 characters"); + hasError = true; + } else if (!/[A-Z]/.test(newPassword)) { + setNewError("Must contain at least one uppercase letter"); + hasError = true; + } else if (!/[0-9]/.test(newPassword)) { + setNewError("Must contain at least one number"); + hasError = true; + } else if (!/[^A-Za-z0-9]/.test(newPassword)) { + setNewError("Must contain at least one special character"); + hasError = true; + } + + if (!confirmPassword) { + setConfirmError("Please confirm your new password"); + hasError = true; + } else if (newPassword !== confirmPassword) { + setConfirmError("Passwords do not match"); + hasError = true; + } + + if (hasError) return; + + setIsLoading(true); + try { + await apiClient.post("/auth/change-password", { + old_password: currentPassword, + new_password: newPassword, + }); + + const msg = "Password updated successfully!"; + if (Platform.OS === "web") { + window.alert(msg); + router.back(); + } else { + Alert.alert("Success", msg, [ + { text: "OK", onPress: () => router.back() }, + ]); + } + } catch (err: any) { + const errMsg = + err?.response?.data?.detail || + "Failed to update password. Please check your current password."; + setCurrentError(errMsg); + if (Platform.OS === "web") { + window.alert(errMsg); + } else { + Alert.alert("Error", errMsg); + } + } finally { + setIsLoading(false); + } + }; + + return ( + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ); +} + +const styles = StyleSheet.create({ + safeArea: { + flex: 1, + backgroundColor: Colors.background, + }, + keyboardContainer: { + flex: 1, + }, + contentContainer: { + flexGrow: 1, + paddingBottom: verticalScale(32), + }, + container: { + flex: 1, + paddingHorizontal: moderateScale(20), + paddingTop: verticalScale(12), + }, + form: { + marginTop: verticalScale(8), + }, + field: { + marginBottom: verticalScale(16), + }, + buttonSpacing: { + marginTop: verticalScale(12), + }, +}); diff --git a/src/app/profile/edit.tsx b/src/app/profile/edit.tsx new file mode 100644 index 0000000..91936fc --- /dev/null +++ b/src/app/profile/edit.tsx @@ -0,0 +1,5 @@ +import EditProfileScreen from "@/screens/profile/EditProfileScreen"; + +export default function EditProfileRoute() { + return ; +} diff --git a/src/app/settings/about.tsx b/src/app/settings/about.tsx new file mode 100644 index 0000000..8948797 --- /dev/null +++ b/src/app/settings/about.tsx @@ -0,0 +1,159 @@ +import React from "react"; +import { + ScrollView, + StyleSheet, + View, + Text, +} from "react-native"; +import { SafeAreaView } from "react-native-safe-area-context"; +import { Ionicons } from "@expo/vector-icons"; +import { moderateScale, verticalScale } from "react-native-size-matters"; + +import SettingsHeader from "@/features/settings/components/SettingsHeader"; +import { Colors } from "@/theme"; + +export default function AboutScreen() { + return ( + + + + + + + + + + Acupedia + + Comprehensive Clinical Acupuncture Encyclopedia + + + Version 1.0.0 (Build 240) + + + + + About This Platform + + Acupedia is a clinical reference application developed specifically for acupuncture practitioners, researchers, and healthcare professionals. It delivers evidence-based anatomical mappings, point categories, channel pathways, and clinical safety considerations. + + + + + Publisher & Organization + + Published by Panacea Clinical Systems Pvt Ltd. All international rights reserved. + + + + + Medical & Clinical Disclaimer + + The information provided in Acupedia is designed for accredited healthcare practitioners and educational reference only. It is not intended as a substitute for individualized clinical judgment, diagnosis, or emergency intervention. + + + + + © {new Date().getFullYear()} Panacea Clinical Systems. All Rights Reserved. + + + + + ); +} + +const styles = StyleSheet.create({ + safeArea: { + flex: 1, + backgroundColor: Colors.background, + }, + contentContainer: { + flexGrow: 1, + paddingBottom: verticalScale(32), + }, + container: { + flex: 1, + paddingHorizontal: moderateScale(20), + paddingTop: verticalScale(12), + }, + logoSection: { + alignItems: "center", + marginVertical: verticalScale(16), + }, + logoWrapper: { + width: moderateScale(80), + height: moderateScale(80), + borderRadius: moderateScale(40), + backgroundColor: "#DCFCE7", + justifyContent: "center", + alignItems: "center", + marginBottom: verticalScale(12), + borderWidth: 1, + borderColor: "#BBF7D0", + }, + appName: { + fontSize: moderateScale(22), + fontWeight: "800", + color: Colors.textPrimary, + marginBottom: verticalScale(4), + }, + appTagline: { + fontSize: moderateScale(13), + color: Colors.textSecondary, + textAlign: "center", + marginBottom: verticalScale(10), + }, + versionBadge: { + backgroundColor: "#F1F5F9", + paddingHorizontal: moderateScale(10), + paddingVertical: verticalScale(4), + borderRadius: moderateScale(12), + }, + versionText: { + fontSize: moderateScale(11), + fontWeight: "600", + color: "#64748B", + }, + card: { + backgroundColor: "#FFFFFF", + borderRadius: moderateScale(16), + borderWidth: 1, + borderColor: "#E5E7EB", + padding: moderateScale(18), + marginBottom: verticalScale(20), + }, + infoTitle: { + fontSize: moderateScale(14), + fontWeight: "700", + color: Colors.textPrimary, + marginBottom: verticalScale(6), + }, + infoText: { + fontSize: moderateScale(13), + color: Colors.textSecondary, + lineHeight: moderateScale(19), + }, + disclaimerText: { + fontSize: moderateScale(12), + color: "#64748B", + lineHeight: moderateScale(18), + fontStyle: "italic", + }, + separator: { + height: 1, + backgroundColor: "#F1F5F9", + marginVertical: verticalScale(14), + }, + copyrightText: { + fontSize: moderateScale(11), + color: Colors.textSecondary, + textAlign: "center", + }, +}); diff --git a/src/app/settings/help-support.tsx b/src/app/settings/help-support.tsx new file mode 100644 index 0000000..af463cb --- /dev/null +++ b/src/app/settings/help-support.tsx @@ -0,0 +1,239 @@ +import React, { useState } from "react"; +import { + ScrollView, + StyleSheet, + View, + Text, + TouchableOpacity, + Alert, + Linking, +} from "react-native"; +import { SafeAreaView } from "react-native-safe-area-context"; +import { Ionicons } from "@expo/vector-icons"; +import { moderateScale, verticalScale } from "react-native-size-matters"; + +import SettingsHeader from "@/features/settings/components/SettingsHeader"; +import { Colors } from "@/theme"; + +interface FAQ { + question: string; + answer: string; +} + +const FAQS: FAQ[] = [ + { + question: "What is Acupedia?", + answer: + "Acupedia is a comprehensive clinical reference application designed for acupuncture practitioners, researchers, and students. It offers verified anatomical point mappings, therapeutic indications, needling depths, and clinical protocols.", + }, + { + question: "How do I unlock additional clinical modules?", + answer: + "You can unlock full clinical libraries and specialized modules by visiting the Subscription tab or selecting any locked module to view tier plans.", + }, + { + question: "How do I edit my profile information?", + answer: + "Navigate to the Profile tab or Settings > Edit Profile. You can update your Full Name, Phone Number, and Country.", + }, + { + question: "Can I use Acupedia without an internet connection?", + answer: + "Yes. Once clinical modules and point definitions have been loaded, they remain cached on your device for offline reference in clinical settings.", + }, + { + question: "How do I report clinical inaccuracies or suggestions?", + answer: + "We take clinical accuracy seriously. Please reach out to our editorial and clinical review team directly using the Email Support button below.", + }, +]; + +export default function HelpSupportScreen() { + const [expandedIndex, setExpandedIndex] = useState(0); + + const handleContact = () => { + Linking.openURL("mailto:support@acupedia.com").catch(() => { + Alert.alert( + "Contact Support", + "Please email our support desk at support@acupedia.com" + ); + }); + }; + + const toggleExpand = (index: number) => { + setExpandedIndex(expandedIndex === index ? null : index); + }; + + return ( + + + + + + + Find quick answers to common clinical questions or contact our support team. + + + Frequently Asked Questions + + + {FAQS.map((faq, index) => { + const isExpanded = expandedIndex === index; + return ( + + toggleExpand(index)} + activeOpacity={0.7} + > + {faq.question} + + + + {isExpanded && ( + + {faq.answer} + + )} + + {index < FAQS.length - 1 && } + + ); + })} + + + Contact Our Team + + + + + + + Email Clinical Support + + Response typically within 24 hours (support@acupedia.com) + + + + + + + + ); +} + +const styles = StyleSheet.create({ + safeArea: { + flex: 1, + backgroundColor: Colors.background, + }, + contentContainer: { + flexGrow: 1, + paddingBottom: verticalScale(32), + }, + container: { + flex: 1, + paddingHorizontal: moderateScale(20), + paddingTop: verticalScale(12), + }, + sectionSubtitle: { + fontSize: moderateScale(13), + color: Colors.textSecondary, + marginBottom: verticalScale(16), + lineHeight: moderateScale(18), + }, + sectionTitle: { + fontSize: moderateScale(13), + fontWeight: "700", + color: Colors.textSecondary, + textTransform: "uppercase", + letterSpacing: 0.5, + marginBottom: verticalScale(8), + marginLeft: moderateScale(4), + }, + faqCard: { + backgroundColor: "#FFFFFF", + borderRadius: moderateScale(16), + borderWidth: 1, + borderColor: "#E5E7EB", + paddingHorizontal: moderateScale(16), + marginBottom: verticalScale(24), + }, + faqHeader: { + flexDirection: "row", + alignItems: "center", + justifyContent: "space-between", + paddingVertical: verticalScale(14), + }, + questionText: { + fontSize: moderateScale(14), + fontWeight: "600", + color: Colors.textPrimary, + flex: 1, + marginRight: moderateScale(12), + lineHeight: moderateScale(19), + }, + answerContainer: { + paddingBottom: verticalScale(14), + }, + answerText: { + fontSize: moderateScale(13), + color: Colors.textSecondary, + lineHeight: moderateScale(19), + }, + separator: { + height: 1, + backgroundColor: "#F1F5F9", + }, + contactCard: { + flexDirection: "row", + alignItems: "center", + backgroundColor: "#FFFFFF", + borderRadius: moderateScale(16), + borderWidth: 1, + borderColor: "#E5E7EB", + padding: moderateScale(16), + }, + contactIconWrapper: { + width: moderateScale(40), + height: moderateScale(40), + borderRadius: moderateScale(20), + backgroundColor: "#DCFCE7", + justifyContent: "center", + alignItems: "center", + }, + contactTextContainer: { + marginLeft: moderateScale(12), + flex: 1, + }, + contactLabel: { + fontSize: moderateScale(15), + fontWeight: "700", + color: Colors.textPrimary, + marginBottom: verticalScale(2), + }, + contactSubLabel: { + fontSize: moderateScale(12), + color: Colors.textSecondary, + lineHeight: moderateScale(16), + }, +}); diff --git a/src/app/settings/index.tsx b/src/app/settings/index.tsx new file mode 100644 index 0000000..b960147 --- /dev/null +++ b/src/app/settings/index.tsx @@ -0,0 +1,5 @@ +import SettingsScreen from "@/screens/settings/SettingsScreen"; + +export default function SettingsRoute() { + return ; +} diff --git a/src/app/settings/language.tsx b/src/app/settings/language.tsx new file mode 100644 index 0000000..63a7483 --- /dev/null +++ b/src/app/settings/language.tsx @@ -0,0 +1,232 @@ +import React from "react"; +import { + ScrollView, + StyleSheet, + View, + Text, + TouchableOpacity, + Alert, + Platform, +} from "react-native"; +import { SafeAreaView } from "react-native-safe-area-context"; +import { router } from "expo-router"; +import { moderateScale, verticalScale } from "react-native-size-matters"; + +import SettingsHeader from "@/features/settings/components/SettingsHeader"; +import PrimaryButton from "@/components/buttons/PrimaryButton"; +import { Colors } from "@/theme"; +import { useSettingsStore } from "@/store/settings.store"; + +interface LanguageItem { + code: string; + label: string; + nativeLabel: string; + available: boolean; +} + +const LANGUAGES: LanguageItem[] = [ + { + code: "en", + label: "English", + nativeLabel: "English (US)", + available: true, + }, + { + code: "hi", + label: "Hindi", + nativeLabel: "हिन्दी", + available: false, + }, + { + code: "es", + label: "Spanish", + nativeLabel: "Español", + available: false, + }, + { + code: "zh", + label: "Chinese", + nativeLabel: "中文 (Traditional & Simplified)", + available: false, + }, + { + code: "fr", + label: "French", + nativeLabel: "Français", + available: false, + }, +]; + +export default function LanguageScreen() { + const language = useSettingsStore((state) => state.language); + const setLanguage = useSettingsStore((state) => state.setLanguage); + + const handleSelect = (lang: LanguageItem) => { + if (!lang.available) { + const msg = `${lang.label} translation is in progress and will be available in an upcoming clinical taxonomy release.`; + if (Platform.OS === "web") { + window.alert(msg); + } else { + Alert.alert("Coming Soon", msg); + } + return; + } + setLanguage(lang.code); + }; + + const handleSave = () => { + const selected = LANGUAGES.find((l) => l.code === language); + const msg = `Language set to ${selected?.label || "English"}.`; + if (Platform.OS === "web") { + window.alert(msg); + router.back(); + } else { + Alert.alert("Success", msg, [ + { text: "OK", onPress: () => router.back() }, + ]); + } + }; + + return ( + + + + + + + Choose your preferred clinical taxonomy and interface language. + + + + {LANGUAGES.map((lang, index) => { + const isSelected = language === lang.code; + return ( + handleSelect(lang)} + activeOpacity={0.7} + > + + {lang.label} + {lang.nativeLabel} + + + {!lang.available ? ( + + Coming Soon + + ) : ( + + {isSelected && } + + )} + + ); + })} + + + + + + + + + ); +} + +const styles = StyleSheet.create({ + safeArea: { + flex: 1, + backgroundColor: Colors.background, + }, + contentContainer: { + flexGrow: 1, + paddingBottom: verticalScale(32), + }, + container: { + flex: 1, + paddingHorizontal: moderateScale(20), + paddingTop: verticalScale(12), + }, + sectionSubtitle: { + fontSize: moderateScale(13), + color: Colors.textSecondary, + marginBottom: verticalScale(16), + lineHeight: moderateScale(18), + }, + card: { + backgroundColor: "#FFFFFF", + borderRadius: moderateScale(16), + overflow: "hidden", + borderWidth: 1, + borderColor: "#E5E7EB", + }, + optionRow: { + flexDirection: "row", + alignItems: "center", + justifyContent: "space-between", + padding: moderateScale(16), + }, + border: { + borderBottomWidth: 1, + borderBottomColor: "#F1F5F9", + }, + textContainer: { + flex: 1, + marginRight: moderateScale(12), + }, + title: { + fontSize: moderateScale(14), + fontWeight: "600", + color: Colors.textPrimary, + }, + nativeLabel: { + fontSize: moderateScale(12), + color: Colors.textSecondary, + marginTop: verticalScale(2), + }, + comingSoonBadge: { + backgroundColor: "#F1F5F9", + paddingHorizontal: moderateScale(8), + paddingVertical: moderateScale(4), + borderRadius: moderateScale(6), + }, + comingSoonText: { + fontSize: moderateScale(11), + fontWeight: "600", + color: "#64748B", + }, + radio: { + width: moderateScale(20), + height: moderateScale(20), + borderRadius: moderateScale(10), + borderWidth: 2, + borderColor: "#CBD5E1", + justifyContent: "center", + alignItems: "center", + }, + radioSelected: { + borderColor: Colors.primary, + }, + radioInner: { + width: moderateScale(10), + height: moderateScale(10), + borderRadius: moderateScale(5), + backgroundColor: Colors.primary, + }, + buttonWrapper: { + marginTop: verticalScale(24), + }, +}); diff --git a/src/app/settings/notifications.tsx b/src/app/settings/notifications.tsx new file mode 100644 index 0000000..1a3b667 --- /dev/null +++ b/src/app/settings/notifications.tsx @@ -0,0 +1,144 @@ +import React from "react"; +import { + ScrollView, + StyleSheet, + View, + Text, + Alert, + Platform, +} from "react-native"; +import { SafeAreaView } from "react-native-safe-area-context"; +import { router } from "expo-router"; +import { moderateScale, verticalScale } from "react-native-size-matters"; + +import SettingsHeader from "@/features/settings/components/SettingsHeader"; +import ProfileMenuItem from "@/features/profile/components/ProfileMenuItem"; +import PrimaryButton from "@/components/buttons/PrimaryButton"; +import { Colors } from "@/theme"; +import { useSettingsStore } from "@/store/settings.store"; + +export default function NotificationSettingsScreen() { + const notifications = useSettingsStore((state) => state.notifications); + const setNotificationPreference = useSettingsStore( + (state) => state.setNotificationPreference + ); + + const handleSave = () => { + const msg = "Notification preferences saved successfully!"; + if (Platform.OS === "web") { + window.alert(msg); + router.back(); + } else { + Alert.alert("Success", msg, [ + { text: "OK", onPress: () => router.back() }, + ]); + } + }; + + return ( + + + + + + + Configure how and when you want to receive clinical notices and app updates. + + + + setNotificationPreference("push", val)} + /> + + + setNotificationPreference("clinicalUpdates", val) + } + /> + + + setNotificationPreference("weeklyDigest", val) + } + /> + + setNotificationPreference("sound", val)} + /> + + + setNotificationPreference("vibration", val) + } + /> + + + + + + + + + ); +} + +const styles = StyleSheet.create({ + safeArea: { + flex: 1, + backgroundColor: Colors.background, + }, + contentContainer: { + flexGrow: 1, + paddingBottom: verticalScale(32), + }, + container: { + flex: 1, + paddingHorizontal: moderateScale(20), + paddingTop: verticalScale(12), + }, + sectionSubtitle: { + fontSize: moderateScale(13), + color: Colors.textSecondary, + marginBottom: verticalScale(16), + lineHeight: moderateScale(18), + }, + card: { + backgroundColor: "#FFFFFF", + borderRadius: moderateScale(16), + overflow: "hidden", + borderWidth: 1, + borderColor: "#E5E7EB", + }, + buttonWrapper: { + marginTop: verticalScale(24), + }, +}); diff --git a/src/app/settings/privacy.tsx b/src/app/settings/privacy.tsx new file mode 100644 index 0000000..7226b6b --- /dev/null +++ b/src/app/settings/privacy.tsx @@ -0,0 +1,171 @@ +import React, { useState } from "react"; +import { + ScrollView, + StyleSheet, + View, + Text, + Alert, + Platform, +} from "react-native"; +import { SafeAreaView } from "react-native-safe-area-context"; +import { router } from "expo-router"; +import { moderateScale, verticalScale } from "react-native-size-matters"; + +import SettingsHeader from "@/features/settings/components/SettingsHeader"; +import ProfileMenuItem from "@/features/profile/components/ProfileMenuItem"; +import PrimaryButton from "@/components/buttons/PrimaryButton"; +import { Colors } from "@/theme"; + +export default function PrivacySettingsScreen() { + const [analyticsEnabled, setAnalyticsEnabled] = useState(true); + const [offlineCacheEnabled, setOfflineCacheEnabled] = useState(true); + + const handleClearHistory = () => { + const doClear = () => { + const msg = "Search and navigation history cleared."; + if (Platform.OS === "web") { + window.alert(msg); + } else { + Alert.alert("Success", msg); + } + }; + + if (Platform.OS === "web") { + if (window.confirm("Clear all local search history? This cannot be undone.")) { + doClear(); + } + } else { + Alert.alert( + "Clear Search History", + "Are you sure you want to clear your local search history?", + [ + { text: "Cancel", style: "cancel" }, + { text: "Clear", style: "destructive", onPress: doClear }, + ] + ); + } + }; + + const handleSave = () => { + const msg = "Privacy preferences updated!"; + if (Platform.OS === "web") { + window.alert(msg); + router.back(); + } else { + Alert.alert("Success", msg, [ + { text: "OK", onPress: () => router.back() }, + ]); + } + }; + + return ( + + + + + + + Manage your personal data storage, local history, and anonymized metrics. + + + + + + + + + + + + Clinical Privacy & Content Protection + + Acupedia is strictly compliant with privacy principles. We never sell your clinical search data, bookmarks, or account information to third parties. + + + Proprietary anatomical charts, point coordinates, and clinical needling depths are protected by hardware screen-capture and recording prevention on native mobile devices. + + + + + + + + + + ); +} + +const styles = StyleSheet.create({ + safeArea: { + flex: 1, + backgroundColor: Colors.background, + }, + contentContainer: { + flexGrow: 1, + paddingBottom: verticalScale(32), + }, + container: { + flex: 1, + paddingHorizontal: moderateScale(20), + paddingTop: verticalScale(12), + }, + sectionSubtitle: { + fontSize: moderateScale(13), + color: Colors.textSecondary, + marginBottom: verticalScale(16), + lineHeight: moderateScale(18), + }, + card: { + backgroundColor: "#FFFFFF", + borderRadius: moderateScale(16), + overflow: "hidden", + borderWidth: 1, + borderColor: "#E5E7EB", + marginBottom: verticalScale(20), + }, + infoBox: { + backgroundColor: "#F8FAFC", + borderRadius: moderateScale(14), + padding: moderateScale(16), + borderWidth: 1, + borderColor: "#E2E8F0", + }, + infoTitle: { + fontSize: moderateScale(14), + fontWeight: "700", + color: Colors.textPrimary, + marginBottom: verticalScale(4), + }, + infoText: { + fontSize: moderateScale(12), + color: Colors.textSecondary, + lineHeight: moderateScale(18), + }, + buttonWrapper: { + marginTop: verticalScale(24), + }, +}); diff --git a/src/features/content/renderers/shared/AccordionSection.tsx b/src/features/content/renderers/shared/AccordionSection.tsx index 2ccd98d..e0308db 100644 --- a/src/features/content/renderers/shared/AccordionSection.tsx +++ b/src/features/content/renderers/shared/AccordionSection.tsx @@ -1,4 +1,4 @@ -import React, { type PropsWithChildren, useMemo, useState } from "react"; +import React, { type PropsWithChildren, useEffect, useMemo, useState } from "react"; import { LayoutAnimation, Platform, @@ -30,6 +30,10 @@ export function AccordionSection({ const [expanded, setExpanded] = useState(defaultExpanded); const tone = useMemo(() => readingToneForTitle(title), [title]); + useEffect(() => { + setExpanded(defaultExpanded); + }, [defaultExpanded]); + const toggle = () => { LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut); setExpanded((value) => !value); diff --git a/src/features/content/renderers/shared/SectionCard.tsx b/src/features/content/renderers/shared/SectionCard.tsx index 2288449..3e6259f 100644 --- a/src/features/content/renderers/shared/SectionCard.tsx +++ b/src/features/content/renderers/shared/SectionCard.tsx @@ -2,6 +2,7 @@ import React, { type PropsWithChildren, isValidElement } from "react"; import { isEmptyValue } from "../../utils/attribute-presentation"; import { AccordionSection } from "./AccordionSection"; +import { useSettingsStore } from "@/store/settings.store"; export interface SectionCardProps { title: string; @@ -35,13 +36,20 @@ function hasRenderableContent(node: React.ReactNode): boolean { export function SectionCard({ title, - defaultExpanded = true, + defaultExpanded, children, }: PropsWithChildren) { if (!hasRenderableContent(children)) return null; + const accordionDefaultExpanded = useSettingsStore( + (state) => state.accordionDefaultExpanded + ); + + const isExpanded = + defaultExpanded !== undefined ? defaultExpanded : accordionDefaultExpanded; + return ( - + {children} ); diff --git a/src/features/profile/components/EditProfileAvatar.tsx b/src/features/profile/components/EditProfileAvatar.tsx index e05af7e..6c6a4a2 100644 --- a/src/features/profile/components/EditProfileAvatar.tsx +++ b/src/features/profile/components/EditProfileAvatar.tsx @@ -1,11 +1,9 @@ import React from "react"; import { - Pressable, StyleSheet, + Text, View, } from "react-native"; -import { Image } from "expo-image"; -import { Ionicons } from "@expo/vector-icons"; import { moderateScale, scale, @@ -13,46 +11,25 @@ import { } from "react-native-size-matters"; interface EditProfileAvatarProps { - imageUri?: string; - onPress?: () => void; + name?: string; } -export default function EditProfileAvatar({ - imageUri, - onPress, -}: EditProfileAvatarProps) { +function getInitials(nameString?: string): string { + if (!nameString || !nameString.trim()) return "U"; + const parts = nameString.trim().split(/\s+/); + if (parts.length === 1) { + return parts[0].slice(0, 2).toUpperCase(); + } + return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase(); +} + +export default function EditProfileAvatar({ name }: EditProfileAvatarProps) { + const initials = getInitials(name); + return ( - - {imageUri ? ( - - ) : ( - - - - )} - - - - + + {initials} ); @@ -61,37 +38,24 @@ export default function EditProfileAvatar({ const styles = StyleSheet.create({ container: { alignItems: "center", - marginBottom: verticalScale(28), + marginBottom: verticalScale(16), }, - avatarWrapper: { - position: "relative", - }, - - avatar: { - width: scale(108), - height: scale(108), - borderRadius: scale(54), - backgroundColor: "#F2F3F7", - justifyContent: "center", - alignItems: "center", - }, - - cameraButton: { - position: "absolute", - right: scale(0), - bottom: scale(2), - - width: scale(32), - height: scale(32), - borderRadius: scale(16), - - backgroundColor: "#5B3DF5", - - justifyContent: "center", - alignItems: "center", - + initialsContainer: { + width: scale(88), + height: scale(88), + borderRadius: scale(44), + backgroundColor: "#DCFCE7", borderWidth: 2, - borderColor: "#FFFFFF", + borderColor: "#BBF7D0", + justifyContent: "center", + alignItems: "center", + }, + + initialsText: { + fontSize: moderateScale(28), + fontWeight: "800", + color: "#15803D", + letterSpacing: 1, }, }); \ No newline at end of file diff --git a/src/features/profile/components/EditProfileForm.tsx b/src/features/profile/components/EditProfileForm.tsx index 63f5238..f646441 100644 --- a/src/features/profile/components/EditProfileForm.tsx +++ b/src/features/profile/components/EditProfileForm.tsx @@ -1,9 +1,16 @@ import React, { useState, useEffect } from "react"; import { + Modal, + Pressable, + ScrollView, StyleSheet, + Text, View, } from "react-native"; +import { Ionicons } from "@expo/vector-icons"; import { + moderateScale, + scale, verticalScale, } from "react-native-size-matters"; @@ -11,26 +18,48 @@ import BaseTextInput from "@/components/forms/BaseTextInput"; import DropdownField from "@/components/forms/DropdownField"; import FieldLabel from "@/components/forms/FieldLabel"; import PrimaryButton from "@/components/buttons/PrimaryButton"; +import { Colors } from "@/theme"; interface EditProfileFormProps { initialName?: string; initialEmail?: string; initialPhone?: string; - initialProfession?: string; initialCountry?: string; - onSave?: (updatedName: string, updatedPhone: string) => void; + onSave?: (updatedName: string, updatedPhone: string, updatedCountry: string) => void; + isLoading?: boolean; } +const COMMON_COUNTRIES = [ + "India", + "United States", + "United Kingdom", + "Canada", + "Australia", + "Germany", + "Singapore", + "Malaysia", + "New Zealand", + "United Arab Emirates", + "South Africa", + "Ireland", + "Netherlands", + "Switzerland", + "France", + "Spain", +]; + export default function EditProfileForm({ initialName = "User Name", initialEmail = "user@example.com", initialPhone = "", - initialProfession = "Practitioner", initialCountry = "India", onSave, + isLoading = false, }: EditProfileFormProps) { const [fullName, setFullName] = useState(initialName); const [phone, setPhone] = useState(initialPhone); + const [country, setCountry] = useState(initialCountry); + const [showCountryModal, setShowCountryModal] = useState(false); useEffect(() => { setFullName(initialName); @@ -40,35 +69,25 @@ export default function EditProfileForm({ setPhone(initialPhone); }, [initialPhone]); - const [profession, setProfession] = - useState(initialProfession); - - const [country] = - useState(initialCountry); + useEffect(() => { + setCountry(initialCountry); + }, [initialCountry]); return ( - - + - - + + + Email address is tied to your account identity and subscriptions. + - - + - - - + setShowCountryModal(true)} /> - - - - + { - // TODO: - // Open Country Picker + onSave?.(fullName, phone, country); }} /> - { - onSave?.(fullName, phone); - }} - /> + {/* Country Selection Modal */} + setShowCountryModal(false)} + > + setShowCountryModal(false)} + > + + + Select Country + setShowCountryModal(false)} + > + + + + + + {COMMON_COUNTRIES.map((c) => { + const isSelected = country === c; + return ( + [ + styles.countryItem, + isSelected && styles.countryItemSelected, + pressed && styles.countryItemPressed, + ]} + onPress={() => { + setCountry(c); + setShowCountryModal(false); + }} + > + + {c} + + {isSelected && ( + + )} + + ); + })} + + + + ); } const styles = StyleSheet.create({ container: { - marginTop: verticalScale(8), + marginTop: verticalScale(4), }, field: { - marginBottom: verticalScale(18), + marginBottom: verticalScale(16), + }, + + helperText: { + marginTop: verticalScale(4), + fontSize: moderateScale(11), + color: Colors.textSecondary, + lineHeight: moderateScale(15), + }, + + buttonWrapper: { + marginTop: verticalScale(10), + }, + + modalOverlay: { + flex: 1, + backgroundColor: "rgba(0, 0, 0, 0.4)", + justifyContent: "flex-end", + }, + + modalSheet: { + backgroundColor: "#FFFFFF", + borderTopLeftRadius: moderateScale(20), + borderTopRightRadius: moderateScale(20), + maxHeight: "70%", + paddingTop: verticalScale(16), + paddingBottom: verticalScale(32), + }, + + modalHeader: { + flexDirection: "row", + alignItems: "center", + justifyContent: "space-between", + paddingHorizontal: scale(20), + paddingBottom: verticalScale(12), + borderBottomWidth: 1, + borderBottomColor: "#F1F5F9", + }, + + modalTitle: { + fontSize: moderateScale(17), + fontWeight: "700", + color: Colors.textPrimary, + }, + + countryList: { + paddingHorizontal: scale(16), + paddingTop: verticalScale(8), + }, + + countryItem: { + flexDirection: "row", + alignItems: "center", + justifyContent: "space-between", + paddingVertical: verticalScale(12), + paddingHorizontal: scale(12), + borderRadius: moderateScale(10), + }, + + countryItemSelected: { + backgroundColor: "#DCFCE7", + }, + + countryItemPressed: { + backgroundColor: "#F1F5F9", + }, + + countryName: { + fontSize: moderateScale(14), + color: Colors.textPrimary, + fontWeight: "500", + }, + + countryNameSelected: { + fontWeight: "700", + color: "#15803D", }, }); \ No newline at end of file diff --git a/src/features/profile/components/ProfileAvatar.tsx b/src/features/profile/components/ProfileAvatar.tsx index 989b9e4..f5966ca 100644 --- a/src/features/profile/components/ProfileAvatar.tsx +++ b/src/features/profile/components/ProfileAvatar.tsx @@ -1,13 +1,9 @@ import React from "react"; import { - Pressable, StyleSheet, Text, View, } from "react-native"; -import { Image } from "expo-image"; -import { Ionicons } from "@expo/vector-icons"; -import { useRouter } from "expo-router"; import { moderateScale, scale, @@ -19,71 +15,31 @@ import { Colors } from "@/theme"; interface ProfileAvatarProps { name: string; email: string; - imageUri?: string; - onEditPress?: () => void; +} + +function getInitials(nameString: string): string { + if (!nameString || !nameString.trim()) return "U"; + const parts = nameString.trim().split(/\s+/); + if (parts.length === 1) { + return parts[0].slice(0, 2).toUpperCase(); + } + return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase(); } export default function ProfileAvatar({ name, email, - imageUri, - onEditPress, }: ProfileAvatarProps) { - const router = useRouter(); - - const handleEditProfile = () => { - onEditPress?.(); - router.push("/profile/edit"); - }; + const initials = getInitials(name); return ( - - {imageUri ? ( - - ) : ( - - - - )} - - - - + + {initials} - - - {name} - - - - - {email} - + {name} + {email} ); } @@ -91,51 +47,40 @@ export default function ProfileAvatar({ const styles = StyleSheet.create({ container: { alignItems: "center", - marginTop: verticalScale(10), - marginBottom: verticalScale(28), - }, - - avatarWrapper: { - position: "relative", + marginTop: verticalScale(4), marginBottom: verticalScale(16), }, - avatar: { - width: scale(96), - height: scale(96), - borderRadius: scale(48), - backgroundColor: "#F2F3F7", + initialsContainer: { + width: scale(88), + height: scale(88), + borderRadius: scale(44), + backgroundColor: "#DCFCE7", + borderWidth: 2, + borderColor: "#BBF7D0", justifyContent: "center", alignItems: "center", + marginBottom: verticalScale(12), }, - editButton: { - position: "absolute", - right: scale(-2), - bottom: scale(-2), - - width: scale(30), - height: scale(30), - borderRadius: scale(15), - - backgroundColor: "#5B3DF5", - - justifyContent: "center", - alignItems: "center", - - borderWidth: 2, - borderColor: "#FFFFFF", + initialsText: { + fontSize: moderateScale(28), + fontWeight: "800", + color: "#15803D", + letterSpacing: 1, }, name: { fontSize: moderateScale(18), fontWeight: "700", - color: Colors.text, + color: Colors.textPrimary, + textAlign: "center", }, email: { - marginTop: verticalScale(6), - fontSize: moderateScale(14), - color: "#7A7A7A", + marginTop: verticalScale(3), + fontSize: moderateScale(13), + color: Colors.textSecondary, + textAlign: "center", }, }); \ No newline at end of file diff --git a/src/features/profile/components/ProfileHeader.tsx b/src/features/profile/components/ProfileHeader.tsx index 66e7a08..fcda99f 100644 --- a/src/features/profile/components/ProfileHeader.tsx +++ b/src/features/profile/components/ProfileHeader.tsx @@ -17,55 +17,64 @@ import { Colors } from "@/theme"; interface ProfileHeaderProps { title?: string; + showBackButton?: boolean; onSettingsPress?: () => void; } export default function ProfileHeader({ title = "My Profile", + showBackButton = false, onSettingsPress, }: ProfileHeaderProps) { const router = useRouter(); return ( - { - if (router.canGoBack()) { - router.back(); - } else { - router.replace("/"); - } - }} - > - - + {showBackButton ? ( + [ + styles.iconButton, + pressed && styles.iconButtonPressed, + ]} + onPress={() => { + if (router.canGoBack()) { + router.back(); + } else { + router.replace("/"); + } + }} + > + + + ) : ( + + )} - + {title} [ + styles.iconButton, + pressed && styles.iconButtonPressed, + ]} onPress={onSettingsPress} > @@ -74,36 +83,36 @@ export default function ProfileHeader({ const styles = StyleSheet.create({ container: { - height: verticalScale(56), - + height: verticalScale(50), flexDirection: "row", - alignItems: "center", - justifyContent: "space-between", - - marginBottom: verticalScale(24), + marginBottom: verticalScale(16), }, iconButton: { - width: scale(40), - - height: scale(40), - + width: scale(38), + height: scale(38), + borderRadius: scale(19), justifyContent: "center", - alignItems: "center", + backgroundColor: "#F1F5F9", + }, + + iconButtonPressed: { + backgroundColor: "#E2E8F0", }, title: { flex: 1, - textAlign: "center", - fontSize: moderateScale(18), - fontWeight: "700", + color: Colors.textPrimary, + }, - color: Colors.text, + placeholder: { + width: scale(38), + height: scale(38), }, }); \ No newline at end of file diff --git a/src/features/profile/components/ProfileMenuItem.tsx b/src/features/profile/components/ProfileMenuItem.tsx index be3b248..6fefc8f 100644 --- a/src/features/profile/components/ProfileMenuItem.tsx +++ b/src/features/profile/components/ProfileMenuItem.tsx @@ -96,12 +96,14 @@ export default function ProfileMenuItem({ )} {isSwitch ? ( - + + + ) : showArrow ? ( { if (accessToken) { - void refreshAccess().catch((error) => console.warn("Unable to refresh profile access:", error)); + void refreshAccess().catch((error) => + console.warn("Unable to refresh profile access:", error) + ); } }, [accessToken, refreshAccess]); @@ -81,23 +84,17 @@ export default function ProfileOverviewCard() { icon={item.icon} title={item.title} value={item.value} + showArrow={false} isLast={index === accountOverviewItems.length - 1} /> ))} - - Subscriptions - - {activeSubscriptions.length === 0 ? ( - - No active paid subscription - - Free modules remain available. Paid access will appear here after checkout is verified. - - - ) : ( - activeSubscriptions.map((subscription, index) => ( + {activeSubscriptions.length > 0 && ( + + Active Subscriptions + + {activeSubscriptions.map((subscription, index) => ( - {planLabel(subscription.plan_code)} + + {planLabel(subscription.plan_code)} + Started: {formatDate(subscription.started_at)} @@ -118,10 +117,10 @@ export default function ProfileOverviewCard() { {subscription.status} - )) - )} + ))} + - + )} {activeEntitlements.length > 0 ? ( @@ -154,45 +153,68 @@ export default function ProfileOverviewCard() { } const styles = StyleSheet.create({ - container: { marginTop: verticalScale(8) }, - section: { marginTop: verticalScale(24) }, - heading: { - fontSize: moderateScale(16), - fontWeight: "700", - color: "#171717", - marginBottom: verticalScale(12), + container: { marginTop: verticalScale(4) }, + section: { marginTop: verticalScale(20) }, + + sectionHeaderRow: { + flexDirection: "row", + justifyContent: "space-between", + alignItems: "center", + marginBottom: verticalScale(8), }, + + heading: { + fontSize: moderateScale(13), + fontWeight: "700", + color: Colors.textSecondary, + textTransform: "uppercase", + letterSpacing: 0.5, + marginLeft: moderateScale(4), + }, + + manageText: { + fontSize: moderateScale(13), + fontWeight: "600", + color: Colors.primary, + }, + card: { backgroundColor: "#FFFFFF", borderRadius: moderateScale(16), overflow: "hidden", borderWidth: 1, - borderColor: "#ECECEC", + borderColor: "#E5E7EB", }, + subRow: { padding: moderateScale(16), flexDirection: "row", alignItems: "center", justifyContent: "space-between", }, + entitlementRow: { padding: moderateScale(16), flexDirection: "row", alignItems: "center", }, + entitlementIcon: { marginRight: moderateScale(10) }, subLeft: { flex: 1 }, + subTitle: { fontSize: moderateScale(14), fontWeight: "600", - color: "#171717", - marginBottom: verticalScale(4), + color: Colors.textPrimary, + marginBottom: verticalScale(2), }, + subDateText: { fontSize: moderateScale(12), - color: "#737373", + color: Colors.textSecondary, marginTop: verticalScale(2), }, + statusBadge: { backgroundColor: "#DCFCE7", paddingHorizontal: moderateScale(10), @@ -200,23 +222,13 @@ const styles = StyleSheet.create({ borderRadius: moderateScale(12), marginLeft: moderateScale(12), }, + statusText: { fontSize: moderateScale(11), - fontWeight: "600", + fontWeight: "700", color: "#15803D", textTransform: "capitalize", }, - separator: { borderBottomWidth: 1, borderBottomColor: "#ECECEC" }, - emptyRow: { padding: moderateScale(16) }, - emptyTitle: { - fontSize: moderateScale(14), - fontWeight: "600", - color: "#171717", - }, - emptyText: { - marginTop: verticalScale(5), - fontSize: moderateScale(12), - color: "#737373", - lineHeight: moderateScale(18), - }, + + separator: { borderBottomWidth: 1, borderBottomColor: "#F1F5F9" }, }); diff --git a/src/features/settings/components/LogoutButton.tsx b/src/features/settings/components/LogoutButton.tsx new file mode 100644 index 0000000..6abde33 --- /dev/null +++ b/src/features/settings/components/LogoutButton.tsx @@ -0,0 +1,62 @@ +import React from "react"; +import { + Pressable, + StyleSheet, + Text, +} from "react-native"; +import { Ionicons } from "@expo/vector-icons"; +import { + moderateScale, + scale, + verticalScale, +} from "react-native-size-matters"; + +interface LogoutButtonProps { + onPress: () => void; +} + +export default function LogoutButton({ onPress }: LogoutButtonProps) { + return ( + [ + styles.container, + pressed && styles.pressed, + ]} + > + + Log Out + + ); +} + +const styles = StyleSheet.create({ + container: { + height: verticalScale(50), + flexDirection: "row", + alignItems: "center", + justifyContent: "center", + marginTop: verticalScale(8), + marginBottom: verticalScale(24), + borderRadius: moderateScale(14), + borderWidth: 1, + borderColor: "#FECACA", + backgroundColor: "#FEF2F2", + }, + text: { + marginLeft: scale(8), + fontSize: moderateScale(15), + fontWeight: "700", + color: "#DC2626", + }, + pressed: { + opacity: 0.8, + backgroundColor: "#FEE2E2", + }, +}); diff --git a/src/features/settings/components/SettingsHeader.tsx b/src/features/settings/components/SettingsHeader.tsx new file mode 100644 index 0000000..e1e1860 --- /dev/null +++ b/src/features/settings/components/SettingsHeader.tsx @@ -0,0 +1,118 @@ +import React from "react"; +import { + Pressable, + StyleSheet, + Text, + View, +} from "react-native"; +import { Ionicons } from "@expo/vector-icons"; +import { useRouter } from "expo-router"; +import { + moderateScale, + scale, + verticalScale, +} from "react-native-size-matters"; + +import { Colors } from "@/theme"; + +interface SettingsHeaderProps { + title?: string; + onBackPress?: () => void; + rightAction?: React.ReactNode; +} + +export default function SettingsHeader({ + title = "Settings", + onBackPress, + rightAction, +}: SettingsHeaderProps) { + const router = useRouter(); + + const handleBack = () => { + if (onBackPress) { + onBackPress(); + return; + } + + if (router.canGoBack()) { + router.back(); + } else { + router.replace("/(tabs)/profile"); + } + }; + + return ( + + [ + styles.backButton, + pressed && styles.backButtonPressed, + ]} + onPress={handleBack} + > + + + + + {title} + + + {rightAction ? ( + {rightAction} + ) : ( + + )} + + ); +} + +const styles = StyleSheet.create({ + container: { + height: verticalScale(50), + flexDirection: "row", + alignItems: "center", + justifyContent: "space-between", + marginBottom: verticalScale(16), + }, + + backButton: { + width: scale(38), + height: scale(38), + borderRadius: scale(19), + justifyContent: "center", + alignItems: "center", + backgroundColor: "#F1F5F9", + }, + + backButtonPressed: { + backgroundColor: "#E2E8F0", + }, + + title: { + flex: 1, + textAlign: "center", + fontSize: moderateScale(17), + fontWeight: "700", + color: Colors.textPrimary, + marginHorizontal: scale(8), + }, + + placeholder: { + width: scale(38), + height: scale(38), + }, + + rightActionContainer: { + width: scale(38), + height: scale(38), + justifyContent: "center", + alignItems: "center", + }, +}); diff --git a/src/features/settings/components/SettingsSection.tsx b/src/features/settings/components/SettingsSection.tsx new file mode 100644 index 0000000..422ed60 --- /dev/null +++ b/src/features/settings/components/SettingsSection.tsx @@ -0,0 +1,75 @@ +import React from "react"; +import { StyleSheet, Text, View } from "react-native"; +import { useRouter } from "expo-router"; +import { moderateScale, verticalScale } from "react-native-size-matters"; + +import ProfileMenuItem from "@/features/profile/components/ProfileMenuItem"; +import { Colors } from "@/theme"; +import { SettingsSectionProps, SettingsItem } from "../types"; + +export default function SettingsSection({ + title, + items, +}: SettingsSectionProps) { + const router = useRouter(); + + const handlePress = (item: SettingsItem) => { + if (item.onPress) { + item.onPress(); + return; + } + if (item.route) { + router.push(item.route as never); + } + }; + + if (!items || items.length === 0) return null; + + return ( + + {title} + + + {items.map((item, index) => ( + handlePress(item)} + /> + ))} + + + ); +} + +const styles = StyleSheet.create({ + container: { + marginBottom: verticalScale(20), + }, + + sectionTitle: { + fontSize: moderateScale(13), + fontWeight: "700", + color: Colors.textSecondary, + textTransform: "uppercase", + letterSpacing: 0.5, + marginBottom: verticalScale(8), + marginLeft: moderateScale(4), + }, + + card: { + backgroundColor: "#FFFFFF", + borderRadius: moderateScale(16), + overflow: "hidden", + borderWidth: 1, + borderColor: "#E5E7EB", + }, +}); diff --git a/src/features/settings/constants/settingsData.ts b/src/features/settings/constants/settingsData.ts new file mode 100644 index 0000000..618c62f --- /dev/null +++ b/src/features/settings/constants/settingsData.ts @@ -0,0 +1,61 @@ +import { Ionicons } from "@expo/vector-icons"; +import { SettingsItem } from "../types"; + +export const ACCOUNT_SETTINGS: SettingsItem[] = [ + { + id: "edit-profile", + title: "Edit Profile", + subtitle: "Update name, phone number & country", + icon: "person-outline" as keyof typeof Ionicons.glyphMap, + route: "/profile/edit", + }, + { + id: "change-password", + title: "Change Password", + subtitle: "Manage login credentials & security", + icon: "lock-closed-outline" as keyof typeof Ionicons.glyphMap, + route: "/profile/change-password", + }, + { + id: "notification-settings", + title: "Notification Settings", + subtitle: "Clinical updates & reminder alerts", + icon: "notifications-outline" as keyof typeof Ionicons.glyphMap, + route: "/settings/notifications", + }, + { + id: "privacy-settings", + title: "Privacy & Data", + subtitle: "Search cache & data governance", + icon: "shield-checkmark-outline" as keyof typeof Ionicons.glyphMap, + route: "/settings/privacy", + }, +]; + +export const PREFERENCE_SETTINGS: SettingsItem[] = [ + { + id: "language", + title: "Language", + subtitle: "Interface localized language", + icon: "language-outline" as keyof typeof Ionicons.glyphMap, + value: "English", + route: "/settings/language", + }, +]; + +export const SUPPORT_SETTINGS: SettingsItem[] = [ + { + id: "help-support", + title: "Help & Support", + subtitle: "FAQs, user guide & clinical inquiries", + icon: "help-circle-outline" as keyof typeof Ionicons.glyphMap, + route: "/settings/help-support", + }, + { + id: "about-acupedia", + title: "About Acupedia", + subtitle: "Version, disclaimer & publisher info", + icon: "information-circle-outline" as keyof typeof Ionicons.glyphMap, + route: "/settings/about", + }, +]; diff --git a/src/features/settings/types.ts b/src/features/settings/types.ts new file mode 100644 index 0000000..1d327bb --- /dev/null +++ b/src/features/settings/types.ts @@ -0,0 +1,19 @@ +import { Ionicons } from "@expo/vector-icons"; + +export interface SettingsItem { + id: string; + title: string; + subtitle?: string; + icon: keyof typeof Ionicons.glyphMap; + route?: string; + value?: string; + isSwitch?: boolean; + switchValue?: boolean; + onSwitchChange?: (val: boolean) => void; + onPress?: () => void; +} + +export interface SettingsSectionProps { + title: string; + items: SettingsItem[]; +} diff --git a/src/screens/profile/EditProfileScreen.tsx b/src/screens/profile/EditProfileScreen.tsx index bff9bee..3b8406d 100644 --- a/src/screens/profile/EditProfileScreen.tsx +++ b/src/screens/profile/EditProfileScreen.tsx @@ -1,5 +1,6 @@ -import React from "react"; +import React, { useState } from "react"; import { + Alert, KeyboardAvoidingView, Platform, ScrollView, @@ -12,7 +13,8 @@ import { verticalScale, } from "react-native-size-matters"; import { router } from "expo-router"; -import EditProfileHeader from "@/features/profile/components/EditProfileHeader"; + +import SettingsHeader from "@/features/settings/components/SettingsHeader"; import { Colors } from "@/theme"; import EditProfileForm from "@/features/profile/components/EditProfileForm"; import EditProfileAvatar from "@/features/profile/components/EditProfileAvatar"; @@ -22,22 +24,51 @@ import { apiClient } from "@/api"; export default function EditProfileScreen() { const user = useAuthStore((state) => state.user); const refreshIdentity = useAuthStore((state) => state.refreshIdentity); + const [saving, setSaving] = useState(false); - const handleSave = async (updatedName: string, updatedPhone: string) => { - if (user) { - try { - await apiClient.put("/auth/profile", { - full_name: updatedName, - phone_number: updatedPhone, - }); - - await refreshIdentity(); - } catch (err: any) { - console.warn("Failed to update profile:", err); - alert("Failed to save changes. Please try again."); - } + const handleSave = async ( + updatedName: string, + updatedPhone: string, + updatedCountry: string + ) => { + if (!user) { + router.back(); + return; + } + + setSaving(true); + try { + await apiClient.put("/auth/profile", { + full_name: updatedName.trim(), + phone_number: updatedPhone.trim() || null, + country: updatedCountry.trim() || null, + }); + + await refreshIdentity(); + + const successMsg = "Profile updated successfully!"; + if (Platform.OS === "web") { + window.alert(successMsg); + router.back(); + } else { + Alert.alert("Success", successMsg, [ + { text: "OK", onPress: () => router.back() }, + ]); + } + } catch (err: any) { + const errMsg = + err?.response?.data?.detail || + err?.message || + "Failed to save profile changes. Please try again."; + console.warn("Failed to update profile:", err); + if (Platform.OS === "web") { + window.alert(errMsg); + } else { + Alert.alert("Error", errMsg); + } + } finally { + setSaving(false); } - router.back(); }; return ( @@ -52,27 +83,18 @@ export default function EditProfileScreen() { contentContainerStyle={styles.contentContainer} > - - + + + - { - // TODO: Open image picker - }} - /> - - - {/* Step 4 */} - {/* EditProfileForm */} - - {/* Step 5 */} - {/* Save Button */} @@ -92,12 +114,12 @@ const styles = StyleSheet.create({ contentContainer: { flexGrow: 1, - paddingBottom: verticalScale(24), + paddingBottom: verticalScale(32), }, container: { flex: 1, - paddingHorizontal: moderateScale(24), - paddingTop: verticalScale(20), + paddingHorizontal: moderateScale(20), + paddingTop: verticalScale(12), }, }); \ No newline at end of file diff --git a/src/screens/profile/ProfileOverviewScreen.tsx b/src/screens/profile/ProfileOverviewScreen.tsx index be8e8d7..1c089f2 100644 --- a/src/screens/profile/ProfileOverviewScreen.tsx +++ b/src/screens/profile/ProfileOverviewScreen.tsx @@ -17,10 +17,10 @@ import { router } from "expo-router"; import { Ionicons } from "@expo/vector-icons"; import { Colors } from "@/theme"; - 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 { useAuthStore } from "@/store/auth.store"; export default function ProfileOverviewScreen() { @@ -45,7 +45,7 @@ export default function ProfileOverviewScreen() { } else { Alert.alert( "Log Out", - "Are you sure you want to log out?", + "Are you sure you want to log out of Acupedia?", [ { text: "Cancel", style: "cancel" }, { @@ -54,7 +54,7 @@ export default function ProfileOverviewScreen() { onPress: doLogout, }, ], - { cancelable: true }, + { cancelable: true } ); } }; @@ -68,23 +68,29 @@ export default function ProfileOverviewScreen() { > - + - Join AcuPedia + Join Acupedia - Sign in or create an account to unlock premium clinical modules, track your learning progress, and customize your profile references. + Sign in or create an account to unlock clinical point pathways, track your learning progress, and customize your clinical references. - - router.push("/login")} + activeOpacity={0.85} > Log In - router.push("/register")} + activeOpacity={0.85} > Create Account @@ -102,6 +108,8 @@ export default function ProfileOverviewScreen() { > { router.push("/settings"); }} @@ -110,21 +118,11 @@ export default function ProfileOverviewScreen() { { - router.push("/profile/edit"); - }} /> - - - Log Out - + @@ -142,40 +140,25 @@ const styles = StyleSheet.create({ paddingBottom: verticalScale(24), }, - logoutButton: { - flexDirection: "row", - alignItems: "center", - justifyContent: "center", - gap: moderateScale(8), - backgroundColor: "#FEE2E2", - borderRadius: moderateScale(14), - paddingVertical: verticalScale(14), - marginTop: verticalScale(24), - }, - logoutButtonText: { - fontSize: moderateScale(15), - fontWeight: "700", - color: "#DC2626", - }, - container: { flex: 1, - paddingHorizontal: moderateScale(24), - paddingTop: verticalScale(20), + paddingHorizontal: moderateScale(20), + paddingTop: verticalScale(12), }, guestContentContainer: { flexGrow: 1, justifyContent: "center", - paddingHorizontal: moderateScale(24), + paddingHorizontal: moderateScale(20), paddingBottom: verticalScale(40), }, + guestCard: { backgroundColor: "#FFFFFF", - borderRadius: moderateScale(24), + borderRadius: moderateScale(20), borderWidth: 1, borderColor: "#E5E7EB", - padding: moderateScale(28), + padding: moderateScale(26), alignItems: "center", shadowColor: "#000000", shadowOffset: { width: 0, height: 4 }, @@ -183,44 +166,51 @@ const styles = StyleSheet.create({ shadowRadius: 10, elevation: 2, }, + guestIconWrapper: { - marginBottom: verticalScale(16), + marginBottom: verticalScale(14), }, + guestTitle: { fontSize: moderateScale(22), fontWeight: "800", color: Colors.textPrimary, - marginBottom: verticalScale(8), + marginBottom: verticalScale(6), }, + guestSubtitle: { - fontSize: moderateScale(14), + fontSize: moderateScale(13), color: Colors.textSecondary, textAlign: "center", - lineHeight: 20, - marginBottom: verticalScale(28), + lineHeight: 19, + marginBottom: verticalScale(24), }, + guestLoginButton: { width: "100%", backgroundColor: Colors.primary, - borderRadius: moderateScale(14), + borderRadius: moderateScale(12), paddingVertical: verticalScale(13), alignItems: "center", - marginBottom: verticalScale(12), + marginBottom: verticalScale(10), }, + guestLoginButtonText: { fontSize: moderateScale(15), fontWeight: "700", color: "#FFFFFF", }, + guestSignupButton: { width: "100%", backgroundColor: "#FFFFFF", - borderWidth: 2, + borderWidth: 1.5, borderColor: Colors.primary, - borderRadius: moderateScale(14), + borderRadius: moderateScale(12), paddingVertical: verticalScale(12), alignItems: "center", }, + guestSignupButtonText: { fontSize: moderateScale(15), fontWeight: "700", diff --git a/src/screens/settings/SettingsScreen.tsx b/src/screens/settings/SettingsScreen.tsx new file mode 100644 index 0000000..61a7d42 --- /dev/null +++ b/src/screens/settings/SettingsScreen.tsx @@ -0,0 +1,150 @@ +import React from "react"; +import { + Alert, + Platform, + ScrollView, + StyleSheet, + View, +} from "react-native"; +import { SafeAreaView } from "react-native-safe-area-context"; +import { router } from "expo-router"; +import { moderateScale, verticalScale } from "react-native-size-matters"; + +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 { + ACCOUNT_SETTINGS, + PREFERENCE_SETTINGS, + SUPPORT_SETTINGS, +} from "@/features/settings/constants/settingsData"; +import { SettingsItem } from "@/features/settings/types"; +import { useAuthStore } from "@/store/auth.store"; +import { useSettingsStore } from "@/store/settings.store"; + +export default function SettingsScreen() { + const user = useAuthStore((state) => state.user); + const logout = useAuthStore((state) => state.logout); + + const accordionDefaultExpanded = useSettingsStore( + (state) => state.accordionDefaultExpanded + ); + const setAccordionDefaultExpanded = useSettingsStore( + (state) => state.setAccordionDefaultExpanded + ); + + const contentPreviewEnabled = useSettingsStore( + (state) => state.contentPreviewEnabled + ); + const setContentPreviewEnabled = useSettingsStore( + (state) => state.setContentPreviewEnabled + ); + + // Clinical Preview Mode is strictly gated to admin role + const isAdmin = user?.roles?.includes("admin") ?? false; + + const appPreferenceItems: SettingsItem[] = [ + { + id: "expand-accordions", + title: "Expand Sections by Default", + subtitle: "Keep all detail accordions open while reading", + icon: "list-outline", + isSwitch: true, + switchValue: accordionDefaultExpanded, + onSwitchChange: (val) => setAccordionDefaultExpanded(val), + }, + ...(isAdmin + ? [ + { + id: "clinical-preview", + title: "Clinical Draft / Preview Mode", + subtitle: "View unpublished modules & draft revisions", + icon: "flask-outline" as const, + isSwitch: true, + switchValue: contentPreviewEnabled, + onSwitchChange: (val: boolean) => setContentPreviewEnabled(val), + }, + ] + : []), + ...PREFERENCE_SETTINGS, + ]; + + const handleLogout = () => { + 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 ( + + + + + + + + + + + + + + + + ); +} + +const styles = StyleSheet.create({ + safeArea: { + flex: 1, + backgroundColor: Colors.background, + }, + contentContainer: { + flexGrow: 1, + paddingBottom: verticalScale(32), + }, + container: { + flex: 1, + paddingHorizontal: moderateScale(20), + paddingTop: verticalScale(12), + }, +}); diff --git a/src/store/auth.store.ts b/src/store/auth.store.ts index 819f14a..ea3100a 100644 --- a/src/store/auth.store.ts +++ b/src/store/auth.store.ts @@ -7,7 +7,7 @@ import { setApiAccessToken, } from "@/api/access-token"; import { getAccessMe } from "@/features/access/api/access.api"; -import { isUnauthorizedApiError } from "@/api/error-utils"; +import { getApiErrorStatus, isUnauthorizedApiError } from "@/api/error-utils"; import { setUnauthorizedHandler } from "@/api/session-events"; import { getMe } from "@/features/auth/api/auth.api"; @@ -167,8 +167,11 @@ export const useAuthStore = create()( get().refreshAccess(), ]); + const isSessionInvalid = (reason: unknown) => + isUnauthorizedApiError(reason) || getApiErrorStatus(reason) === 404; + const unauthorized = - (identityResult.status === "rejected" && isUnauthorizedApiError(identityResult.reason)) || + (identityResult.status === "rejected" && isSessionInvalid(identityResult.reason)) || (accessResult.status === "rejected" && isUnauthorizedApiError(accessResult.reason)); if (unauthorized) { @@ -223,10 +226,14 @@ export const useAuthStore = create()( get().refreshAccess(), ]); - // Identity 401/invalid-token is handled conservatively by clearing the + // Identity 401/404/invalid-token is handled conservatively by clearing the // local session. Access failures are non-fatal and leave prior access // state intact for transient-network resilience. - if (identityResult.status === "rejected" && isUnauthorizedApiError(identityResult.reason)) { + if ( + identityResult.status === "rejected" && + (isUnauthorizedApiError(identityResult.reason) || + getApiErrorStatus(identityResult.reason) === 404) + ) { get().logout(); return; } diff --git a/src/store/settings.store.ts b/src/store/settings.store.ts index 9e77e8e..35f9766 100644 --- a/src/store/settings.store.ts +++ b/src/store/settings.store.ts @@ -1,21 +1,71 @@ +import AsyncStorage from "@react-native-async-storage/async-storage"; import { create } from "zustand"; +import { createJSONStorage, persist } from "zustand/middleware"; -import { SettingsState } from "./types"; +import { NotificationPreferences, SettingsState } from "./types"; interface SettingsStore extends SettingsState { - setTheme: (theme: "light" | "dark") => void; + setTheme: (theme: "light" | "dark" | "system") => void; setContentPreviewEnabled: (enabled: boolean) => void; + setAccordionDefaultExpanded: (expanded: boolean) => void; + toggleAccordionDefaultExpanded: () => void; + setNotificationPreference: ( + key: keyof NotificationPreferences, + value: boolean + ) => void; + setLanguage: (language: string) => void; + resetSettings: () => void; } -export const useSettingsStore = create((set) => ({ +const DEFAULT_NOTIFICATIONS: NotificationPreferences = { + push: true, + clinicalUpdates: true, + weeklyDigest: false, + sound: true, + vibration: true, +}; + +const DEFAULT_SETTINGS: SettingsState = { theme: "light", contentPreviewEnabled: false, + accordionDefaultExpanded: false, + notifications: DEFAULT_NOTIFICATIONS, + language: "en", +}; - setTheme: (theme) => - set({ - theme, +export const useSettingsStore = create()( + persist( + (set) => ({ + ...DEFAULT_SETTINGS, + + setTheme: (theme) => set({ theme }), + + setContentPreviewEnabled: (contentPreviewEnabled) => + set({ contentPreviewEnabled }), + + setAccordionDefaultExpanded: (accordionDefaultExpanded) => + set({ accordionDefaultExpanded }), + + toggleAccordionDefaultExpanded: () => + set((state) => ({ + accordionDefaultExpanded: !state.accordionDefaultExpanded, + })), + + setNotificationPreference: (key, value) => + set((state) => ({ + notifications: { + ...state.notifications, + [key]: value, + }, + })), + + setLanguage: (language) => set({ language }), + + resetSettings: () => set(DEFAULT_SETTINGS), }), - - setContentPreviewEnabled: (contentPreviewEnabled) => - set({ contentPreviewEnabled }), -})); \ No newline at end of file + { + name: "acupedia-settings-storage", + storage: createJSONStorage(() => AsyncStorage), + } + ) +); \ No newline at end of file diff --git a/src/store/types.ts b/src/store/types.ts index 8ad997e..bef6c95 100644 --- a/src/store/types.ts +++ b/src/store/types.ts @@ -108,7 +108,18 @@ export interface AppState { isLoading: boolean; } -export interface SettingsState { - theme: "light" | "dark"; - contentPreviewEnabled: boolean; +export interface NotificationPreferences { + push: boolean; + clinicalUpdates: boolean; + weeklyDigest: boolean; + sound: boolean; + vibration: boolean; +} + +export interface SettingsState { + theme: "light" | "dark" | "system"; + contentPreviewEnabled: boolean; + accordionDefaultExpanded: boolean; + notifications: NotificationPreferences; + language: string; }