Compare commits
No commits in common. "main" and "issue-110" have entirely different histories.
|
|
@ -32,7 +32,6 @@
|
||||||
"expo-symbols": "~1.0.7",
|
"expo-symbols": "~1.0.7",
|
||||||
"expo-system-ui": "~6.0.9",
|
"expo-system-ui": "~6.0.9",
|
||||||
"expo-web-browser": "~15.0.11",
|
"expo-web-browser": "~15.0.11",
|
||||||
"libphonenumber-js": "^1.13.16",
|
|
||||||
"react": "19.1.0",
|
"react": "19.1.0",
|
||||||
"react-dom": "19.1.0",
|
"react-dom": "19.1.0",
|
||||||
"react-native": "0.81.5",
|
"react-native": "0.81.5",
|
||||||
|
|
@ -6171,12 +6170,6 @@
|
||||||
"node": ">=6"
|
"node": ">=6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/libphonenumber-js": {
|
|
||||||
"version": "1.13.16",
|
|
||||||
"resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.13.16.tgz",
|
|
||||||
"integrity": "sha512-tIOCM9yx2Go6d5/ZANe0K+G4AZek1Ymx81HxQpf19Sri4zMP95eQbKdnUGHAvFQ4nx0PeLhFqvAfisTADXj3tQ==",
|
|
||||||
"license": "MIT"
|
|
||||||
},
|
|
||||||
"node_modules/lighthouse-logger": {
|
"node_modules/lighthouse-logger": {
|
||||||
"version": "1.4.2",
|
"version": "1.4.2",
|
||||||
"resolved": "https://registry.npmjs.org/lighthouse-logger/-/lighthouse-logger-1.4.2.tgz",
|
"resolved": "https://registry.npmjs.org/lighthouse-logger/-/lighthouse-logger-1.4.2.tgz",
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@
|
||||||
"expo-symbols": "~1.0.7",
|
"expo-symbols": "~1.0.7",
|
||||||
"expo-system-ui": "~6.0.9",
|
"expo-system-ui": "~6.0.9",
|
||||||
"expo-web-browser": "~15.0.11",
|
"expo-web-browser": "~15.0.11",
|
||||||
"libphonenumber-js": "^1.13.16",
|
|
||||||
"react": "19.1.0",
|
"react": "19.1.0",
|
||||||
"react-dom": "19.1.0",
|
"react-dom": "19.1.0",
|
||||||
"react-native": "0.81.5",
|
"react-native": "0.81.5",
|
||||||
|
|
|
||||||
|
|
@ -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 handleAuthAction = () => {
|
||||||
|
if (isAuthenticated) {
|
||||||
const doLogout = () => {
|
const doLogout = () => {
|
||||||
setLogoutModalVisible(false);
|
|
||||||
logout();
|
logout();
|
||||||
router.replace("/login");
|
router.replace("/login");
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAuthAction = () => {
|
if (Platform.OS === "web") {
|
||||||
if (isAuthenticated) {
|
const confirmed = typeof window !== "undefined" ? window.confirm("Are you sure you want to logout?") : true;
|
||||||
setLogoutModalVisible(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}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,11 +56,10 @@ export default function LibraryScreen() {
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
isNavigatingRef.current = false;
|
isNavigatingRef.current = false;
|
||||||
void modulesQuery.refetch().catch((error) => console.warn("Unable to refresh modules:", error));
|
|
||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
void refreshAccess().catch((error) => console.warn("Unable to refresh library access:", error));
|
void refreshAccess().catch((error) => console.warn("Unable to refresh library access:", error));
|
||||||
}
|
}
|
||||||
}, [accessToken, modulesQuery.refetch, refreshAccess]),
|
}, [accessToken, refreshAccess]),
|
||||||
);
|
);
|
||||||
|
|
||||||
const items = useMemo(
|
const items = useMemo(
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,9 @@ export default function ChangePasswordScreen() {
|
||||||
if (!newPassword) {
|
if (!newPassword) {
|
||||||
setNewError("New password is required");
|
setNewError("New password is required");
|
||||||
hasError = true;
|
hasError = true;
|
||||||
|
} else if (currentPassword && newPassword === currentPassword) {
|
||||||
|
setNewError("New password cannot be the same as current password");
|
||||||
|
hasError = true;
|
||||||
} else if (newPassword.length < 8) {
|
} else if (newPassword.length < 8) {
|
||||||
setNewError("New password must be at least 8 characters");
|
setNewError("New password must be at least 8 characters");
|
||||||
hasError = true;
|
hasError = true;
|
||||||
|
|
@ -63,7 +66,7 @@ export default function ChangePasswordScreen() {
|
||||||
setConfirmError("Please confirm your new password");
|
setConfirmError("Please confirm your new password");
|
||||||
hasError = true;
|
hasError = true;
|
||||||
} else if (newPassword !== confirmPassword) {
|
} else if (newPassword !== confirmPassword) {
|
||||||
setConfirmError("Confirm password do not match.");
|
setConfirmError("Passwords do not match");
|
||||||
hasError = true;
|
hasError = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,19 +97,14 @@ export default function ChangePasswordScreen() {
|
||||||
errMsg.toLowerCase().includes("same")
|
errMsg.toLowerCase().includes("same")
|
||||||
) {
|
) {
|
||||||
setNewError(errMsg);
|
setNewError(errMsg);
|
||||||
} else if (
|
|
||||||
typeof errMsg === "string" &&
|
|
||||||
(errMsg.toLowerCase().includes("current") || errMsg.toLowerCase().includes("old"))
|
|
||||||
) {
|
|
||||||
setCurrentError(errMsg);
|
|
||||||
} else if (
|
|
||||||
typeof errMsg === "string" &&
|
|
||||||
errMsg.toLowerCase().includes("confirm")
|
|
||||||
) {
|
|
||||||
setConfirmError(errMsg);
|
|
||||||
} else {
|
} else {
|
||||||
setCurrentError(errMsg);
|
setCurrentError(errMsg);
|
||||||
}
|
}
|
||||||
|
if (Platform.OS === "web") {
|
||||||
|
window.alert(errMsg);
|
||||||
|
} else {
|
||||||
|
Alert.alert("Error", errMsg);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
|
|
@ -131,10 +129,7 @@ export default function ChangePasswordScreen() {
|
||||||
<FieldLabel label="Current Password" required />
|
<FieldLabel label="Current Password" required />
|
||||||
<PasswordInput
|
<PasswordInput
|
||||||
value={currentPassword}
|
value={currentPassword}
|
||||||
onChangeText={(text) => {
|
onChangeText={setCurrentPassword}
|
||||||
setCurrentPassword(text);
|
|
||||||
if (currentError) setCurrentError("");
|
|
||||||
}}
|
|
||||||
placeholder="Enter current password"
|
placeholder="Enter current password"
|
||||||
error={currentError}
|
error={currentError}
|
||||||
/>
|
/>
|
||||||
|
|
@ -144,10 +139,7 @@ export default function ChangePasswordScreen() {
|
||||||
<FieldLabel label="New Password" required />
|
<FieldLabel label="New Password" required />
|
||||||
<PasswordInput
|
<PasswordInput
|
||||||
value={newPassword}
|
value={newPassword}
|
||||||
onChangeText={(text) => {
|
onChangeText={setNewPassword}
|
||||||
setNewPassword(text);
|
|
||||||
if (newError) setNewError("");
|
|
||||||
}}
|
|
||||||
placeholder="Min. 8 characters with numbers & symbols"
|
placeholder="Min. 8 characters with numbers & symbols"
|
||||||
error={newError}
|
error={newError}
|
||||||
/>
|
/>
|
||||||
|
|
@ -157,10 +149,7 @@ export default function ChangePasswordScreen() {
|
||||||
<FieldLabel label="Confirm New Password" required />
|
<FieldLabel label="Confirm New Password" required />
|
||||||
<PasswordInput
|
<PasswordInput
|
||||||
value={confirmPassword}
|
value={confirmPassword}
|
||||||
onChangeText={(text) => {
|
onChangeText={setConfirmPassword}
|
||||||
setConfirmPassword(text);
|
|
||||||
if (confirmError) setConfirmError("");
|
|
||||||
}}
|
|
||||||
placeholder="Re-enter new password"
|
placeholder="Re-enter new password"
|
||||||
error={confirmError}
|
error={confirmError}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -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,7 +1,4 @@
|
||||||
import { parsePhoneNumberFromString, type CountryCode as LibCountryCode } from "libphonenumber-js/max";
|
|
||||||
|
|
||||||
export interface CountryCode {
|
export interface CountryCode {
|
||||||
iso2: LibCountryCode;
|
|
||||||
code: string;
|
code: string;
|
||||||
label: string;
|
label: string;
|
||||||
country: string;
|
country: string;
|
||||||
|
|
@ -13,115 +10,121 @@ export interface CountryCode {
|
||||||
|
|
||||||
export const COUNTRY_CODES: CountryCode[] = [
|
export const COUNTRY_CODES: CountryCode[] = [
|
||||||
// South Asia
|
// South Asia
|
||||||
{ iso2: "IN", code: "+91", label: "🇮🇳 +91", country: "India", currency: "INR", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" },
|
{ code: "+91", label: "🇮🇳 +91", country: "India", currency: "INR", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" },
|
||||||
{ iso2: "PK", code: "+92", label: "🇵🇰 +92", country: "Pakistan", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" },
|
{ code: "+92", label: "🇵🇰 +92", country: "Pakistan", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" },
|
||||||
{ iso2: "BD", code: "+880", label: "🇧🇩 +880", country: "Bangladesh", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" },
|
{ code: "+880", label: "🇧🇩 +880", country: "Bangladesh", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" },
|
||||||
{ iso2: "LK", code: "+94", label: "🇱🇰 +94", country: "Sri Lanka", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
{ code: "+94", label: "🇱🇰 +94", country: "Sri Lanka", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
||||||
{ iso2: "NP", code: "+977", label: "🇳🇵 +977", country: "Nepal", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" },
|
{ code: "+977", label: "🇳🇵 +977", country: "Nepal", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" },
|
||||||
{ iso2: "BT", code: "+975", label: "🇧🇹 +975", country: "Bhutan", currency: "USD", minLength: 8, maxLength: 8, placeholder: "8-digit mobile number" },
|
{ code: "+975", label: "🇧🇹 +975", country: "Bhutan", currency: "USD", minLength: 8, maxLength: 8, placeholder: "8-digit mobile number" },
|
||||||
{ iso2: "MV", code: "+960", label: "🇲🇻 +960", country: "Maldives", currency: "USD", minLength: 7, maxLength: 7, placeholder: "7-digit mobile number" },
|
{ code: "+960", label: "🇲🇻 +960", country: "Maldives", currency: "USD", minLength: 7, maxLength: 7, placeholder: "7-digit mobile number" },
|
||||||
|
|
||||||
// North America
|
// North America
|
||||||
{ iso2: "US", code: "+1", label: "🇺🇸 +1", country: "United States", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit phone number" },
|
{ code: "+1", label: "🇺🇸 +1", country: "United States", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit phone number" },
|
||||||
{ iso2: "CA", code: "+1", label: "🇨🇦 +1", country: "Canada", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit phone number" },
|
{ code: "+1", label: "🇨🇦 +1", country: "Canada", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit phone number" },
|
||||||
{ iso2: "MX", code: "+52", label: "🇲🇽 +52", country: "Mexico", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" },
|
{ code: "+52", label: "🇲🇽 +52", country: "Mexico", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" },
|
||||||
|
|
||||||
// Europe & UK
|
// Europe & UK
|
||||||
{ iso2: "GB", code: "+44", label: "🇬🇧 +44", country: "United Kingdom", currency: "USD", minLength: 10, maxLength: 11, placeholder: "10 to 11 digits" },
|
{ code: "+44", label: "🇬🇧 +44", country: "United Kingdom", currency: "USD", minLength: 10, maxLength: 11, placeholder: "10 to 11 digits" },
|
||||||
{ iso2: "DE", code: "+49", label: "🇩🇪 +49", country: "Germany", currency: "EUR", minLength: 10, maxLength: 11, placeholder: "10 to 11 digits" },
|
{ code: "+49", label: "🇩🇪 +49", country: "Germany", currency: "EUR", minLength: 10, maxLength: 11, placeholder: "10 to 11 digits" },
|
||||||
{ iso2: "FR", code: "+33", label: "🇫🇷 +33", country: "France", currency: "EUR", minLength: 9, maxLength: 10, placeholder: "9 to 10 digits" },
|
{ code: "+33", label: "🇫🇷 +33", country: "France", currency: "EUR", minLength: 9, maxLength: 10, placeholder: "9 to 10 digits" },
|
||||||
{ iso2: "IT", code: "+39", label: "🇮🇹 +39", country: "Italy", currency: "EUR", minLength: 9, maxLength: 10, placeholder: "9 to 10 digits" },
|
{ code: "+39", label: "🇮🇹 +39", country: "Italy", currency: "EUR", minLength: 9, maxLength: 10, placeholder: "9 to 10 digits" },
|
||||||
{ iso2: "ES", code: "+34", label: "🇪🇸 +34", country: "Spain", currency: "EUR", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
{ code: "+34", label: "🇪🇸 +34", country: "Spain", currency: "EUR", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
||||||
{ iso2: "NL", code: "+31", label: "🇳🇱 +31", country: "Netherlands", currency: "EUR", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
{ code: "+31", label: "🇳🇱 +31", country: "Netherlands", currency: "EUR", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
||||||
{ iso2: "CH", code: "+41", label: "🇨🇭 +41", country: "Switzerland", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
{ code: "+41", label: "🇨🇭 +41", country: "Switzerland", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
||||||
{ iso2: "BE", code: "+32", label: "🇧🇪 +32", country: "Belgium", currency: "EUR", minLength: 8, maxLength: 9, placeholder: "8 to 9 digits" },
|
{ code: "+32", label: "🇧🇪 +32", country: "Belgium", currency: "EUR", minLength: 8, maxLength: 9, placeholder: "8 to 9 digits" },
|
||||||
{ iso2: "AT", code: "+43", label: "🇦🇹 +43", country: "Austria", currency: "EUR", minLength: 10, maxLength: 11, placeholder: "10 to 11 digits" },
|
{ code: "+43", label: "🇦🇹 +43", country: "Austria", currency: "EUR", minLength: 10, maxLength: 11, placeholder: "10 to 11 digits" },
|
||||||
{ iso2: "IE", code: "+353", label: "🇮🇪 +353", country: "Ireland", currency: "EUR", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
{ code: "+353", label: "🇮🇪 +353", country: "Ireland", currency: "EUR", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
||||||
{ iso2: "SE", code: "+46", label: "🇸🇪 +46", country: "Sweden", currency: "EUR", minLength: 7, maxLength: 10, placeholder: "7 to 10 digits" },
|
{ code: "+46", label: "🇸🇪 +46", country: "Sweden", currency: "EUR", minLength: 7, maxLength: 10, placeholder: "7 to 10 digits" },
|
||||||
{ iso2: "NO", code: "+47", label: "🇳🇴 +47", country: "Norway", currency: "USD", minLength: 8, maxLength: 8, placeholder: "8-digit mobile number" },
|
{ code: "+47", label: "🇳🇴 +47", country: "Norway", currency: "USD", minLength: 8, maxLength: 8, placeholder: "8-digit mobile number" },
|
||||||
{ iso2: "DK", code: "+45", label: "🇩🇰 +45", country: "Denmark", currency: "EUR", minLength: 8, maxLength: 8, placeholder: "8-digit mobile number" },
|
{ code: "+45", label: "🇩🇰 +45", country: "Denmark", currency: "EUR", minLength: 8, maxLength: 8, placeholder: "8-digit mobile number" },
|
||||||
{ iso2: "FI", code: "+358", label: "🇫🇮 +358", country: "Finland", currency: "EUR", minLength: 6, maxLength: 10, placeholder: "6 to 10 digits" },
|
{ code: "+358", label: "🇫🇮 +358", country: "Finland", currency: "EUR", minLength: 6, maxLength: 10, placeholder: "6 to 10 digits" },
|
||||||
{ iso2: "PT", code: "+351", label: "🇵🇹 +351", country: "Portugal", currency: "EUR", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
{ code: "+351", label: "🇵🇹 +351", country: "Portugal", currency: "EUR", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
||||||
{ iso2: "GR", code: "+30", label: "🇬🇷 +30", country: "Greece", currency: "EUR", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" },
|
{ code: "+30", label: "🇬🇷 +30", country: "Greece", currency: "EUR", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" },
|
||||||
{ iso2: "PL", code: "+48", label: "🇵🇱 +48", country: "Poland", currency: "EUR", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
{ code: "+48", label: "🇵🇱 +48", country: "Poland", currency: "EUR", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
||||||
{ iso2: "CZ", code: "+420", label: "🇨🇿 +420", country: "Czech Republic", currency: "EUR", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
{ code: "+420", label: "🇨🇿 +420", country: "Czech Republic", currency: "EUR", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
||||||
{ iso2: "HU", code: "+36", label: "🇭🇺 +36", country: "Hungary", currency: "EUR", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
{ code: "+36", label: "🇭🇺 +36", country: "Hungary", currency: "EUR", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
||||||
{ iso2: "RO", code: "+40", label: "🇷🇴 +40", country: "Romania", currency: "EUR", minLength: 9, maxLength: 10, placeholder: "9 to 10 digits" },
|
{ code: "+40", label: "🇷🇴 +40", country: "Romania", currency: "EUR", minLength: 9, maxLength: 10, placeholder: "9 to 10 digits" },
|
||||||
{ iso2: "UA", code: "+380", label: "🇺🇦 +380", country: "Ukraine", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
{ code: "+380", label: "🇺🇦 +380", country: "Ukraine", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
||||||
{ iso2: "IS", code: "+354", label: "🇮🇸 +354", country: "Iceland", currency: "EUR", minLength: 7, maxLength: 9, placeholder: "7 to 9 digits" },
|
{ code: "+354", label: "🇮🇸 +354", country: "Iceland", currency: "EUR", minLength: 7, maxLength: 9, placeholder: "7 to 9 digits" },
|
||||||
{ iso2: "LU", code: "+352", label: "🇱🇺 +352", country: "Luxembourg", currency: "EUR", minLength: 8, maxLength: 10, placeholder: "8 to 10 digits" },
|
{ code: "+352", label: "🇱🇺 +352", country: "Luxembourg", currency: "EUR", minLength: 8, maxLength: 10, placeholder: "8 to 10 digits" },
|
||||||
{ iso2: "HR", code: "+385", label: "🇭🇷 +385", country: "Croatia", currency: "EUR", minLength: 8, maxLength: 9, placeholder: "8 to 9 digits" },
|
{ code: "+385", label: "🇭🇷 +385", country: "Croatia", currency: "EUR", minLength: 8, maxLength: 9, placeholder: "8 to 9 digits" },
|
||||||
{ iso2: "SK", code: "+421", label: "🇸🇰 +421", country: "Slovakia", currency: "EUR", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
{ code: "+421", label: "🇸🇰 +421", country: "Slovakia", currency: "EUR", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
||||||
{ iso2: "BG", code: "+359", label: "🇧🇬 +359", country: "Bulgaria", currency: "EUR", minLength: 8, maxLength: 9, placeholder: "8 to 9 digits" },
|
{ code: "+359", label: "🇧🇬 +359", country: "Bulgaria", currency: "EUR", minLength: 8, maxLength: 9, placeholder: "8 to 9 digits" },
|
||||||
{ iso2: "RU", code: "+7", label: "🇷🇺 +7", country: "Russia", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" },
|
{ code: "+7", label: "🇷🇺 +7", country: "Russia", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" },
|
||||||
{ iso2: "TR", code: "+90", label: "🇹🇷 +90", country: "Turkey", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" },
|
{ code: "+90", label: "🇹🇷 +90", country: "Turkey", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" },
|
||||||
|
|
||||||
// Asia-Pacific
|
// Asia-Pacific
|
||||||
{ iso2: "AU", code: "+61", label: "🇦🇺 +61", country: "Australia", currency: "USD", minLength: 9, maxLength: 10, placeholder: "9 to 10 digits" },
|
{ code: "+61", label: "🇦🇺 +61", country: "Australia", currency: "USD", minLength: 9, maxLength: 10, placeholder: "9 to 10 digits" },
|
||||||
{ iso2: "NZ", code: "+64", label: "🇳🇿 +64", country: "New Zealand", currency: "USD", minLength: 8, maxLength: 10, placeholder: "8 to 10 digits" },
|
{ code: "+64", label: "🇳🇿 +64", country: "New Zealand", currency: "USD", minLength: 8, maxLength: 10, placeholder: "8 to 10 digits" },
|
||||||
{ iso2: "JP", code: "+81", label: "🇯🇵 +81", country: "Japan", currency: "USD", minLength: 10, maxLength: 11, placeholder: "10 to 11 digits" },
|
{ code: "+81", label: "🇯🇵 +81", country: "Japan", currency: "USD", minLength: 10, maxLength: 11, placeholder: "10 to 11 digits" },
|
||||||
{ iso2: "CN", code: "+86", label: "🇨🇳 +86", country: "China", currency: "USD", minLength: 11, maxLength: 11, placeholder: "11-digit mobile number" },
|
{ code: "+86", label: "🇨🇳 +86", country: "China", currency: "USD", minLength: 11, maxLength: 11, placeholder: "11-digit mobile number" },
|
||||||
{ iso2: "KR", code: "+82", label: "🇰🇷 +82", country: "South Korea", currency: "USD", minLength: 9, maxLength: 11, placeholder: "9 to 11 digits" },
|
{ code: "+82", label: "🇰🇷 +82", country: "South Korea", currency: "USD", minLength: 9, maxLength: 11, placeholder: "9 to 11 digits" },
|
||||||
{ iso2: "HK", code: "+852", label: "🇭🇰 +852", country: "Hong Kong", currency: "USD", minLength: 8, maxLength: 8, placeholder: "8-digit mobile number" },
|
{ code: "+852", label: "🇭🇰 +852", country: "Hong Kong", currency: "USD", minLength: 8, maxLength: 8, placeholder: "8-digit mobile number" },
|
||||||
{ iso2: "TW", code: "+886", label: "🇹🇼 +886", country: "Taiwan", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
{ code: "+886", label: "🇹🇼 +886", country: "Taiwan", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
||||||
{ iso2: "SG", code: "+65", label: "🇸🇬 +65", country: "Singapore", currency: "USD", minLength: 8, maxLength: 8, placeholder: "8-digit mobile number" },
|
{ code: "+65", label: "🇸🇬 +65", country: "Singapore", currency: "USD", minLength: 8, maxLength: 8, placeholder: "8-digit mobile number" },
|
||||||
{ iso2: "MY", code: "+60", label: "🇲🇾 +60", country: "Malaysia", currency: "USD", minLength: 9, maxLength: 10, placeholder: "9 to 10 digits" },
|
{ code: "+60", label: "🇲🇾 +60", country: "Malaysia", currency: "USD", minLength: 9, maxLength: 10, placeholder: "9 to 10 digits" },
|
||||||
{ iso2: "ID", code: "+62", label: "🇮🇩 +62", country: "Indonesia", currency: "USD", minLength: 9, maxLength: 12, placeholder: "9 to 12 digits" },
|
{ code: "+62", label: "🇮🇩 +62", country: "Indonesia", currency: "USD", minLength: 9, maxLength: 12, placeholder: "9 to 12 digits" },
|
||||||
{ iso2: "PH", code: "+63", label: "🇵🇭 +63", country: "Philippines", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" },
|
{ code: "+63", label: "🇵🇭 +63", country: "Philippines", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" },
|
||||||
{ iso2: "TH", code: "+66", label: "🇹🇭 +66", country: "Thailand", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
{ code: "+66", label: "🇹🇭 +66", country: "Thailand", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
||||||
{ iso2: "VN", code: "+84", label: "🇻🇳 +84", country: "Vietnam", currency: "USD", minLength: 9, maxLength: 10, placeholder: "9 to 10 digits" },
|
{ code: "+84", label: "🇻🇳 +84", country: "Vietnam", currency: "USD", minLength: 9, maxLength: 10, placeholder: "9 to 10 digits" },
|
||||||
|
|
||||||
// Middle East
|
// Middle East
|
||||||
{ iso2: "AE", code: "+971", label: "🇦🇪 +971", country: "UAE", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
{ code: "+971", label: "🇦🇪 +971", country: "UAE", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
||||||
{ iso2: "SA", code: "+966", label: "🇸🇦 +966", country: "Saudi Arabia", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
{ code: "+966", label: "🇸🇦 +966", country: "Saudi Arabia", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
||||||
{ iso2: "QA", code: "+974", label: "🇶🇦 +974", country: "Qatar", currency: "USD", minLength: 8, maxLength: 8, placeholder: "8-digit mobile number" },
|
{ code: "+974", label: "🇶🇦 +974", country: "Qatar", currency: "USD", minLength: 8, maxLength: 8, placeholder: "8-digit mobile number" },
|
||||||
{ iso2: "KW", code: "+965", label: "🇰🇼 +965", country: "Kuwait", currency: "USD", minLength: 8, maxLength: 8, placeholder: "8-digit mobile number" },
|
{ code: "+965", label: "🇰🇼 +965", country: "Kuwait", currency: "USD", minLength: 8, maxLength: 8, placeholder: "8-digit mobile number" },
|
||||||
{ iso2: "OM", code: "+968", label: "🇴🇲 +968", country: "Oman", currency: "USD", minLength: 8, maxLength: 8, placeholder: "8-digit mobile number" },
|
{ code: "+968", label: "🇴🇲 +968", country: "Oman", currency: "USD", minLength: 8, maxLength: 8, placeholder: "8-digit mobile number" },
|
||||||
{ iso2: "BH", code: "+973", label: "🇧🇭 +973", country: "Bahrain", currency: "USD", minLength: 8, maxLength: 8, placeholder: "8-digit mobile number" },
|
{ code: "+973", label: "🇧🇭 +973", country: "Bahrain", currency: "USD", minLength: 8, maxLength: 8, placeholder: "8-digit mobile number" },
|
||||||
{ iso2: "IL", code: "+972", label: "🇮🇱 +972", country: "Israel", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
{ code: "+972", label: "🇮🇱 +972", country: "Israel", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
||||||
{ iso2: "JO", code: "+962", label: "🇯🇴 +962", country: "Jordan", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
{ code: "+962", label: "🇯🇴 +962", country: "Jordan", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
||||||
{ iso2: "LB", code: "+961", label: "🇱🇧 +961", country: "Lebanon", currency: "USD", minLength: 7, maxLength: 8, placeholder: "7 to 8 digits" },
|
{ code: "+961", label: "🇱🇧 +961", country: "Lebanon", currency: "USD", minLength: 7, maxLength: 8, placeholder: "7 to 8 digits" },
|
||||||
|
|
||||||
// Latin America
|
// Latin America
|
||||||
{ iso2: "BR", code: "+55", label: "🇧🇷 +55", country: "Brazil", currency: "USD", minLength: 10, maxLength: 11, placeholder: "10 to 11 digits" },
|
{ code: "+55", label: "🇧🇷 +55", country: "Brazil", currency: "USD", minLength: 10, maxLength: 11, placeholder: "10 to 11 digits" },
|
||||||
{ iso2: "AR", code: "+54", label: "🇦🇷 +54", country: "Argentina", currency: "USD", minLength: 10, maxLength: 11, placeholder: "10 to 11 digits" },
|
{ code: "+54", label: "🇦🇷 +54", country: "Argentina", currency: "USD", minLength: 10, maxLength: 11, placeholder: "10 to 11 digits" },
|
||||||
{ iso2: "CL", code: "+56", label: "🇨🇱 +56", country: "Chile", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
{ code: "+56", label: "🇨🇱 +56", country: "Chile", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
||||||
{ iso2: "CO", code: "+57", label: "🇨🇴 +57", country: "Colombia", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" },
|
{ code: "+57", label: "🇨🇴 +57", country: "Colombia", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" },
|
||||||
{ iso2: "PE", code: "+51", label: "🇵🇪 +51", country: "Peru", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
{ code: "+51", label: "🇵🇪 +51", country: "Peru", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
||||||
|
|
||||||
// Africa
|
// Africa
|
||||||
{ iso2: "ZA", code: "+27", label: "🇿🇦 +27", country: "South Africa", currency: "USD", minLength: 9, maxLength: 10, placeholder: "9 to 10 digits" },
|
{ code: "+27", label: "🇿🇦 +27", country: "South Africa", currency: "USD", minLength: 9, maxLength: 10, placeholder: "9 to 10 digits" },
|
||||||
{ iso2: "NG", code: "+234", label: "🇳🇬 +234", country: "Nigeria", currency: "USD", minLength: 10, maxLength: 11, placeholder: "10 to 11 digits" },
|
{ code: "+234", label: "🇳🇬 +234", country: "Nigeria", currency: "USD", minLength: 10, maxLength: 11, placeholder: "10 to 11 digits" },
|
||||||
{ iso2: "KE", code: "+254", label: "🇰🇪 +254", country: "Kenya", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
{ code: "+254", label: "🇰🇪 +254", country: "Kenya", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
||||||
{ iso2: "GH", code: "+233", label: "🇬🇭 +233", country: "Ghana", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
{ code: "+233", label: "🇬🇭 +233", country: "Ghana", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
||||||
{ iso2: "EG", code: "+20", label: "🇪🇬 +20", country: "Egypt", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" },
|
{ code: "+20", label: "🇪🇬 +20", country: "Egypt", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" },
|
||||||
{ iso2: "MA", code: "+212", label: "🇲🇦 +212", country: "Morocco", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
{ code: "+212", label: "🇲🇦 +212", country: "Morocco", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" },
|
||||||
{ iso2: "MU", code: "+230", label: "🇲🇺 +230", country: "Mauritius", currency: "USD", minLength: 7, maxLength: 8, placeholder: "7 to 8 digits" },
|
{ code: "+230", label: "🇲🇺 +230", country: "Mauritius", currency: "USD", minLength: 7, maxLength: 8, placeholder: "7 to 8 digits" },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const DEFAULT_COUNTRY = COUNTRY_CODES[0]; // India (+91)
|
||||||
|
|
||||||
export const SORTED_COUNTRY_CODES: CountryCode[] = [...COUNTRY_CODES].sort((a, b) =>
|
export const SORTED_COUNTRY_CODES: CountryCode[] = [...COUNTRY_CODES].sort((a, b) =>
|
||||||
a.country.localeCompare(b.country)
|
a.country.localeCompare(b.country)
|
||||||
);
|
);
|
||||||
|
|
||||||
export const DEFAULT_COUNTRY = COUNTRY_CODES[0]; // India (+91)
|
export const getCountryRuleByDialCode = (dialCode: string): CountryCode => {
|
||||||
|
return (
|
||||||
export const getCountryRuleByIso = (iso?: string | null): CountryCode => {
|
COUNTRY_CODES.find((c) => c.code === dialCode) || {
|
||||||
if (!iso) return DEFAULT_COUNTRY;
|
code: dialCode,
|
||||||
const upper = iso.toUpperCase().trim();
|
label: dialCode,
|
||||||
return COUNTRY_CODES.find((c) => c.iso2 === upper) || DEFAULT_COUNTRY;
|
country: "Other",
|
||||||
|
currency: "USD",
|
||||||
|
minLength: 7,
|
||||||
|
maxLength: 15,
|
||||||
|
placeholder: "Phone number",
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getCountryRuleByName = (countryName?: string | null): CountryCode => {
|
export const getCountryRuleByName = (countryName: string): CountryCode => {
|
||||||
if (!countryName) return DEFAULT_COUNTRY;
|
if (!countryName) return DEFAULT_COUNTRY;
|
||||||
const normalized = countryName.toLowerCase().trim();
|
const normalized = countryName.toLowerCase().trim();
|
||||||
return (
|
return (
|
||||||
COUNTRY_CODES.find(
|
COUNTRY_CODES.find(
|
||||||
(c) =>
|
(c) =>
|
||||||
c.country.toLowerCase() === normalized ||
|
c.country.toLowerCase() === normalized ||
|
||||||
c.iso2.toLowerCase() === normalized ||
|
|
||||||
normalized.includes(c.country.toLowerCase())
|
normalized.includes(c.country.toLowerCase())
|
||||||
) || {
|
) || {
|
||||||
iso2: "IN",
|
|
||||||
code: "+91",
|
code: "+91",
|
||||||
label: "🇮🇳 +91",
|
label: "🇮🇳 +91",
|
||||||
country: countryName,
|
country: countryName,
|
||||||
|
|
@ -133,32 +136,6 @@ export const getCountryRuleByName = (countryName?: string | null): CountryCode =
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getCountryRuleByDialCode = (dialCode?: string | null, countryHint?: string | null): CountryCode => {
|
|
||||||
if (!dialCode) return DEFAULT_COUNTRY;
|
|
||||||
if (countryHint) {
|
|
||||||
const byCountry = getCountryRuleByName(countryHint);
|
|
||||||
if (byCountry && byCountry.code === dialCode) {
|
|
||||||
return byCountry;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
COUNTRY_CODES.find((c) => c.code === dialCode) || {
|
|
||||||
iso2: "IN",
|
|
||||||
code: dialCode,
|
|
||||||
label: dialCode,
|
|
||||||
country: countryHint || "Other",
|
|
||||||
currency: "USD",
|
|
||||||
minLength: 7,
|
|
||||||
maxLength: 15,
|
|
||||||
placeholder: "Phone number",
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates mobile phone number according to country telecom numbering plans.
|
|
||||||
* Uses libphonenumber-js to enforce mobile prefixes (e.g., France 06/07, India 6-9, UK 07).
|
|
||||||
*/
|
|
||||||
export const validatePhoneNumber = (
|
export const validatePhoneNumber = (
|
||||||
val?: string | null,
|
val?: string | null,
|
||||||
dialCode?: string,
|
dialCode?: string,
|
||||||
|
|
@ -172,8 +149,8 @@ export const validatePhoneNumber = (
|
||||||
return "Phone number cannot contain alphabetic characters.";
|
return "Phone number cannot contain alphabetic characters.";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Strictly disallow hyphens, dashes, and invalid symbols
|
// Strictly disallow hyphens, dashes, and invalid characters
|
||||||
if (/[\-_()/[\]]/.test(trimmed)) {
|
if (/[\-()_]/.test(trimmed)) {
|
||||||
return "Phone number cannot contain hyphens or special symbols.";
|
return "Phone number cannot contain hyphens or special symbols.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -187,88 +164,52 @@ export const validatePhoneNumber = (
|
||||||
return "Please enter a valid phone number with numeric digits.";
|
return "Please enter a valid phone number with numeric digits.";
|
||||||
}
|
}
|
||||||
|
|
||||||
let rule = country ? getCountryRuleByName(country) : undefined;
|
let rule = dialCode ? getCountryRuleByDialCode(dialCode) : undefined;
|
||||||
if (!rule && dialCode) {
|
if ((!rule || rule.country === "Other") && country) {
|
||||||
rule = getCountryRuleByDialCode(dialCode, country);
|
rule = getCountryRuleByName(country);
|
||||||
|
}
|
||||||
|
if (!rule || rule.country === "Other") {
|
||||||
|
if (dialCode === "+91" || (country && country.toLowerCase() === "india")) {
|
||||||
|
rule = getCountryRuleByDialCode("+91");
|
||||||
}
|
}
|
||||||
if (!rule) {
|
|
||||||
rule = DEFAULT_COUNTRY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const iso2 = rule.iso2 || "IN";
|
if (rule && rule.country !== "Other") {
|
||||||
|
|
||||||
// Extract national digits without dial code prefix
|
|
||||||
let nationalDigits = allDigits;
|
|
||||||
const dialDigits = rule.code.replace(/\D/g, "");
|
const dialDigits = rule.code.replace(/\D/g, "");
|
||||||
if (trimmed.startsWith("+")) {
|
let localDigits = allDigits;
|
||||||
if (allDigits.startsWith(dialDigits)) {
|
|
||||||
nationalDigits = allDigits.slice(dialDigits.length);
|
// If formatted with country code (e.g. +919876543210 or 919876543210 where total length > rule.maxLength), strip country prefix
|
||||||
}
|
if (
|
||||||
} else if (allDigits.startsWith(dialDigits) && allDigits.length > rule.maxLength) {
|
(trimmed.startsWith("+") || allDigits.length > rule.maxLength) &&
|
||||||
nationalDigits = allDigits.slice(dialDigits.length);
|
allDigits.startsWith(dialDigits) &&
|
||||||
|
allDigits.length === dialDigits.length + rule.minLength
|
||||||
|
) {
|
||||||
|
localDigits = allDigits.slice(dialDigits.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
const digitsWithoutTrunk0 = nationalDigits.startsWith("0") && iso2 !== "IT"
|
|
||||||
? nationalDigits.replace(/^0+/, "")
|
|
||||||
: nationalDigits;
|
|
||||||
|
|
||||||
// 1. Enforce length validation FIRST so digit count errors take precedence over prefix errors
|
|
||||||
if (iso2 === "IN") {
|
|
||||||
if (nationalDigits.length !== 10) {
|
|
||||||
return "India mobile number must be exactly 10 digits.";
|
|
||||||
}
|
|
||||||
if (!/^[6-9]/.test(nationalDigits)) {
|
|
||||||
return "India mobile number must begin with 6, 7, 8, or 9.";
|
|
||||||
}
|
|
||||||
} else if (iso2 === "FR") {
|
|
||||||
if (nationalDigits.length < 9) {
|
|
||||||
return "France mobile number is too short (must be 9 digits, or 10 digits with 0).";
|
|
||||||
}
|
|
||||||
if (nationalDigits.length > 10 || (nationalDigits.length === 10 && !nationalDigits.startsWith("0"))) {
|
|
||||||
return "France mobile number cannot exceed 9 digits (or 10 digits with leading 0).";
|
|
||||||
}
|
|
||||||
if (!/^[67]/.test(digitsWithoutTrunk0)) {
|
|
||||||
return "France mobile number must begin with 06 or 07 (or 6 or 7).";
|
|
||||||
}
|
|
||||||
} else if (iso2 === "GB") {
|
|
||||||
if (digitsWithoutTrunk0.length < 10) {
|
|
||||||
return "United Kingdom mobile number is too short (must be 10 digits, or 11 digits with 0).";
|
|
||||||
}
|
|
||||||
if (digitsWithoutTrunk0.length > 10) {
|
|
||||||
return "United Kingdom mobile number cannot exceed 10 digits (or 11 digits with leading 0).";
|
|
||||||
}
|
|
||||||
if (!/^7/.test(digitsWithoutTrunk0)) {
|
|
||||||
return "United Kingdom mobile number must begin with 07 (or 7).";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// General length check for other countries
|
|
||||||
if (rule.minLength === rule.maxLength) {
|
if (rule.minLength === rule.maxLength) {
|
||||||
if (digitsWithoutTrunk0.length !== rule.minLength && nationalDigits.length !== rule.minLength) {
|
if (localDigits.length !== rule.minLength) {
|
||||||
return `${rule.country} mobile number must be exactly ${rule.minLength} digits.`;
|
return `${rule.country} phone number must be exactly ${rule.minLength} digits.`;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (digitsWithoutTrunk0.length < rule.minLength && nationalDigits.length < rule.minLength) {
|
if (localDigits.length < rule.minLength) {
|
||||||
return `${rule.country} mobile number is too short (min ${rule.minLength} digits).`;
|
return `${rule.country} phone number must be at least ${rule.minLength} digits.`;
|
||||||
}
|
}
|
||||||
if (digitsWithoutTrunk0.length > rule.maxLength) {
|
if (localDigits.length > rule.maxLength) {
|
||||||
return `${rule.country} mobile number cannot exceed ${rule.maxLength} digits.`;
|
return `${rule.country} phone number cannot exceed ${rule.maxLength} digits.`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Validate telecom numbering rules with libphonenumber-js
|
|
||||||
const candidate = trimmed.startsWith("+") ? trimmed : `${rule.code}${nationalDigits}`;
|
|
||||||
const parsed = parsePhoneNumberFromString(candidate, iso2);
|
|
||||||
|
|
||||||
if (parsed && parsed.isValid()) {
|
|
||||||
const numberType = parsed.getType();
|
|
||||||
if (numberType === "FIXED_LINE") {
|
|
||||||
return `Please enter a valid mobile number for ${rule.country}.`;
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `Please enter a valid mobile number for ${rule.country} (e.g. ${rule.placeholder}).`;
|
// General fallback ITU E.164
|
||||||
|
if (allDigits.length < 7) {
|
||||||
|
return "Phone number must contain at least 7 digits.";
|
||||||
|
}
|
||||||
|
if (allDigits.length > 15) {
|
||||||
|
return "Phone number cannot exceed 15 digits.";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const isValidPhoneNumber = (
|
export const isValidPhoneNumber = (
|
||||||
|
|
@ -279,94 +220,6 @@ export const isValidPhoneNumber = (
|
||||||
return validatePhoneNumber(val, dialCode, country) === null;
|
return validatePhoneNumber(val, dialCode, country) === null;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Splits a full phone number into dialCode, country, and localDigits
|
|
||||||
*/
|
|
||||||
export const parsePhoneNumber = (
|
|
||||||
fullPhone?: string | null,
|
|
||||||
fallbackCountry = "India"
|
|
||||||
): { country: string; dialCode: string; localDigits: string; iso2: LibCountryCode } => {
|
|
||||||
const defaultRule = getCountryRuleByName(fallbackCountry) || DEFAULT_COUNTRY;
|
|
||||||
if (!fullPhone || !fullPhone.trim()) {
|
|
||||||
return { country: defaultRule.country, dialCode: defaultRule.code, localDigits: "", iso2: defaultRule.iso2 };
|
|
||||||
}
|
|
||||||
|
|
||||||
const trimmed = fullPhone.trim();
|
|
||||||
const parsed = parsePhoneNumberFromString(trimmed, defaultRule.iso2);
|
|
||||||
|
|
||||||
if (parsed) {
|
|
||||||
const matchedRule = parsed.country
|
|
||||||
? getCountryRuleByIso(parsed.country)
|
|
||||||
: getCountryRuleByDialCode(`+${parsed.countryCallingCode}`, fallbackCountry);
|
|
||||||
|
|
||||||
return {
|
|
||||||
country: matchedRule.country,
|
|
||||||
dialCode: `+${parsed.countryCallingCode}`,
|
|
||||||
localDigits: parsed.nationalNumber,
|
|
||||||
iso2: matchedRule.iso2,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const sorted = [...COUNTRY_CODES].sort((a, b) => b.code.length - a.code.length);
|
|
||||||
const matched = sorted.find((c) => trimmed.startsWith(c.code));
|
|
||||||
if (matched) {
|
|
||||||
const rawLocal = trimmed.slice(matched.code.length).replace(/\D/g, "");
|
|
||||||
return {
|
|
||||||
country: matched.country,
|
|
||||||
dialCode: matched.code,
|
|
||||||
localDigits: rawLocal.slice(0, matched.maxLength),
|
|
||||||
iso2: matched.iso2,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const rawDigits = trimmed.replace(/\D/g, "");
|
|
||||||
return {
|
|
||||||
country: defaultRule.country,
|
|
||||||
dialCode: defaultRule.code,
|
|
||||||
localDigits: rawDigits.slice(0, defaultRule.maxLength),
|
|
||||||
iso2: defaultRule.iso2,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Formats full phone number cleanly as E.164 without spaces (+<dialCode><digits>),
|
|
||||||
* automatically stripping any national trunk '0' where appropriate.
|
|
||||||
*/
|
|
||||||
export const formatE164Phone = (dialCode: string, localDigits: string, country?: string): string => {
|
|
||||||
if (!localDigits || !localDigits.trim()) return "";
|
|
||||||
const rule = country ? getCountryRuleByName(country) : getCountryRuleByDialCode(dialCode, country);
|
|
||||||
const rawDigits = localDigits.replace(/\D/g, "");
|
|
||||||
if (!rawDigits) return "";
|
|
||||||
|
|
||||||
const code = dialCode.startsWith("+") ? dialCode : `+${dialCode}`;
|
|
||||||
const candidate = localDigits.startsWith("+") ? localDigits : `${code}${rawDigits}`;
|
|
||||||
|
|
||||||
const parsed = parsePhoneNumberFromString(candidate, rule.iso2);
|
|
||||||
if (parsed && parsed.isValid()) {
|
|
||||||
return parsed.format("E.164");
|
|
||||||
}
|
|
||||||
|
|
||||||
let cleanLocal = rawDigits;
|
|
||||||
if (rule.iso2 !== "IT" && cleanLocal.startsWith("0")) {
|
|
||||||
cleanLocal = cleanLocal.replace(/^0+/, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
return `${code}${cleanLocal}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Strips non-numeric / non-phone characters from text in real-time
|
|
||||||
* If maxLength is provided, strictly restricts digit length
|
|
||||||
* If allowPlus is false, strips any '+' symbols as well (for local number inputs)
|
|
||||||
*/
|
|
||||||
export const cleanPhoneInput = (text: string, maxLength = 16, allowPlus = true): string => {
|
|
||||||
const trimmedStart = text.trimStart();
|
|
||||||
const hasPlus = allowPlus && trimmedStart.startsWith("+");
|
|
||||||
const rest = hasPlus ? trimmedStart.slice(1) : text;
|
|
||||||
const digitsOnly = rest.replace(/\D/g, "");
|
|
||||||
const boundedDigits = maxLength ? digitsOnly.slice(0, maxLength) : digitsOnly;
|
|
||||||
return hasPlus ? `+${boundedDigits}` : boundedDigits;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the dial code prefix of an existing phone number when country changes.
|
* Updates the dial code prefix of an existing phone number when country changes.
|
||||||
|
|
@ -383,13 +236,35 @@ export const updatePhoneDialCode = (
|
||||||
const oldRule = getCountryRuleByName(oldCountry);
|
const oldRule = getCountryRuleByName(oldCountry);
|
||||||
const newRule = getCountryRuleByName(newCountry);
|
const newRule = getCountryRuleByName(newCountry);
|
||||||
|
|
||||||
const parsed = parsePhoneNumber(trimmed, oldRule.country);
|
// Extract national digits without any dial code
|
||||||
const bounded = parsed.localDigits.slice(0, newRule.maxLength);
|
let nationalDigits = "";
|
||||||
|
if (trimmed.startsWith("+")) {
|
||||||
|
const matched = [...COUNTRY_CODES]
|
||||||
|
.sort((a, b) => b.code.length - a.code.length)
|
||||||
|
.find((c) => trimmed.startsWith(c.code));
|
||||||
|
if (matched) {
|
||||||
|
nationalDigits = trimmed.slice(matched.code.length).replace(/\D/g, "");
|
||||||
|
} else {
|
||||||
|
nationalDigits = trimmed.replace(/^\+/, "").replace(/\D/g, "");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const oldDialDigits = oldRule.code.replace(/\D/g, "");
|
||||||
|
const rawDigits = trimmed.replace(/\D/g, "");
|
||||||
|
if (oldDialDigits && rawDigits.startsWith(oldDialDigits) && rawDigits.length > oldDialDigits.length) {
|
||||||
|
nationalDigits = rawDigits.slice(oldDialDigits.length);
|
||||||
|
} else {
|
||||||
|
nationalDigits = rawDigits;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const bounded = nationalDigits.slice(0, newRule.maxLength);
|
||||||
return bounded ? `${newRule.code} ${bounded}` : `${newRule.code} `;
|
return bounded ? `${newRule.code} ${bounded}` : `${newRule.code} `;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RFC 5322 & RFC 1035 compliant email validation regex.
|
* RFC 5322 & RFC 1035 compliant email validation regex.
|
||||||
|
* Disallows invalid domain characters (e.g. + in domain like +gmail+.com, consecutive dots, leading/trailing hyphens)
|
||||||
|
* while properly accepting plus-addressing in local-part (e.g. sanskar+sarak@gmail.com).
|
||||||
*/
|
*/
|
||||||
export const EMAIL_REGEX = /^[a-zA-Z0-9_%+-]+(?:\.[a-zA-Z0-9_%+-]+)*@[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$/;
|
export const EMAIL_REGEX = /^[a-zA-Z0-9_%+-]+(?:\.[a-zA-Z0-9_%+-]+)*@[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$/;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,9 @@ import { AuthColors } from "../constants/colors";
|
||||||
import { Colors } from "@/theme";
|
import { Colors } from "@/theme";
|
||||||
import {
|
import {
|
||||||
CountryCode,
|
CountryCode,
|
||||||
COUNTRY_CODES,
|
|
||||||
DEFAULT_COUNTRY,
|
DEFAULT_COUNTRY,
|
||||||
SORTED_COUNTRY_CODES,
|
SORTED_COUNTRY_CODES,
|
||||||
validatePhoneNumber,
|
validatePhoneNumber,
|
||||||
formatE164Phone,
|
|
||||||
validateEmail,
|
validateEmail,
|
||||||
} from "@/constants/countries";
|
} from "@/constants/countries";
|
||||||
import { useAuthStore } from "@/store/auth.store";
|
import { useAuthStore } from "@/store/auth.store";
|
||||||
|
|
@ -67,37 +65,6 @@ export default function SignUpForm() {
|
||||||
}, [countrySearch]);
|
}, [countrySearch]);
|
||||||
|
|
||||||
const handlePhoneChange = (text: string) => {
|
const handlePhoneChange = (text: string) => {
|
||||||
const trimmed = text.trim();
|
|
||||||
|
|
||||||
// Check if user pasted an international number with '+' prefix
|
|
||||||
if (trimmed.startsWith("+")) {
|
|
||||||
const sorted = [...COUNTRY_CODES].sort((a, b) => b.code.length - a.code.length);
|
|
||||||
const matched = sorted.find((c) => trimmed.startsWith(c.code));
|
|
||||||
if (matched) {
|
|
||||||
if (matched.country !== selectedCountry.country) {
|
|
||||||
setSelectedCountry(matched);
|
|
||||||
}
|
|
||||||
const rest = trimmed.slice(matched.code.length).replace(/\D/g, "");
|
|
||||||
setPhone(rest.slice(0, matched.maxLength));
|
|
||||||
if (phoneError) setPhoneError("");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if user pasted dial digits without '+' (e.g. 919876543210)
|
|
||||||
const dialDigits = selectedCountry.code.replace(/\D/g, "");
|
|
||||||
const rawDigits = trimmed.replace(/\D/g, "");
|
|
||||||
if (
|
|
||||||
dialDigits &&
|
|
||||||
rawDigits.startsWith(dialDigits) &&
|
|
||||||
rawDigits.length > selectedCountry.maxLength
|
|
||||||
) {
|
|
||||||
const rest = rawDigits.slice(dialDigits.length);
|
|
||||||
setPhone(rest.slice(0, selectedCountry.maxLength));
|
|
||||||
if (phoneError) setPhoneError("");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const digits = text.replace(/\D/g, "");
|
const digits = text.replace(/\D/g, "");
|
||||||
setPhone(digits.slice(0, selectedCountry.maxLength));
|
setPhone(digits.slice(0, selectedCountry.maxLength));
|
||||||
if (phoneError) setPhoneError("");
|
if (phoneError) setPhoneError("");
|
||||||
|
|
@ -177,7 +144,7 @@ export default function SignUpForm() {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
try {
|
try {
|
||||||
const formattedPhone = phone.trim()
|
const formattedPhone = phone.trim()
|
||||||
? formatE164Phone(selectedCountry.code, phone.trim(), selectedCountry.country)
|
? `${selectedCountry.code}${phone.trim()}`
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
const response = await register({
|
const response = await register({
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ export function useModulesQuery() {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: contentQueryKeys.modules(preview),
|
queryKey: contentQueryKeys.modules(preview),
|
||||||
queryFn: () => contentApi.getModules(preview),
|
queryFn: () => contentApi.getModules(preview),
|
||||||
staleTime: 30 * 1000,
|
staleTime: 10 * 60 * 1000,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -141,21 +141,6 @@ export function ContentMediaGallery({ media, title = "Visual Reference" }: Conte
|
||||||
const [viewerIndex, setViewerIndex] = useState<number | null>(null);
|
const [viewerIndex, setViewerIndex] = useState<number | null>(null);
|
||||||
const listRef = useRef<FlatList<ContentMediaItem>>(null);
|
const listRef = useRef<FlatList<ContentMediaItem>>(null);
|
||||||
|
|
||||||
const MAX_VISIBLE_DOTS = 7;
|
|
||||||
const visibleDots = useMemo(() => {
|
|
||||||
if (items.length <= MAX_VISIBLE_DOTS) {
|
|
||||||
return items.map((item, index) => ({ item, index }));
|
|
||||||
}
|
|
||||||
const half = Math.floor(MAX_VISIBLE_DOTS / 2);
|
|
||||||
let start = Math.max(0, activeIndex - half);
|
|
||||||
let end = start + MAX_VISIBLE_DOTS;
|
|
||||||
if (end > items.length) {
|
|
||||||
end = items.length;
|
|
||||||
start = Math.max(0, end - MAX_VISIBLE_DOTS);
|
|
||||||
}
|
|
||||||
return items.slice(start, end).map((item, i) => ({ item, index: start + i }));
|
|
||||||
}, [items, activeIndex]);
|
|
||||||
|
|
||||||
if (!items.length) return null;
|
if (!items.length) return null;
|
||||||
|
|
||||||
const handleMomentumEnd = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
const handleMomentumEnd = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
||||||
|
|
@ -184,12 +169,6 @@ export function ContentMediaGallery({ media, title = "Visual Reference" }: Conte
|
||||||
offset: carouselWidth * index,
|
offset: carouselWidth * index,
|
||||||
index,
|
index,
|
||||||
})}
|
})}
|
||||||
onScrollToIndexFailed={(info) => {
|
|
||||||
listRef.current?.scrollToOffset({
|
|
||||||
offset: info.index * carouselWidth,
|
|
||||||
animated: true,
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
onMomentumScrollEnd={handleMomentumEnd}
|
onMomentumScrollEnd={handleMomentumEnd}
|
||||||
renderItem={({ item, index }) => (
|
renderItem={({ item, index }) => (
|
||||||
<Pressable
|
<Pressable
|
||||||
|
|
@ -213,16 +192,12 @@ export function ContentMediaGallery({ media, title = "Visual Reference" }: Conte
|
||||||
|
|
||||||
{items.length > 1 ? (
|
{items.length > 1 ? (
|
||||||
<View style={styles.dots} accessibilityElementsHidden>
|
<View style={styles.dots} accessibilityElementsHidden>
|
||||||
{visibleDots.map(({ item, index }) => (
|
{items.map((item, index) => (
|
||||||
<Pressable
|
<Pressable
|
||||||
key={item.id}
|
key={item.id}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setActiveIndex(index);
|
setActiveIndex(index);
|
||||||
try {
|
|
||||||
listRef.current?.scrollToIndex({ index, animated: true });
|
listRef.current?.scrollToIndex({ index, animated: true });
|
||||||
} catch {
|
|
||||||
listRef.current?.scrollToOffset({ offset: index * carouselWidth, animated: true });
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
hitSlop={6}
|
hitSlop={6}
|
||||||
>
|
>
|
||||||
|
|
@ -279,12 +254,7 @@ const styles = StyleSheet.create({
|
||||||
},
|
},
|
||||||
zoomText: { color: Colors.white, fontSize: 12, fontWeight: "700" },
|
zoomText: { color: Colors.white, fontSize: 12, fontWeight: "700" },
|
||||||
caption: { color: Colors.textSecondary, fontSize: 13, lineHeight: 19, textAlign: "center" },
|
caption: { color: Colors.textSecondary, fontSize: 13, lineHeight: 19, textAlign: "center" },
|
||||||
dots: {
|
dots: { flexDirection: "row", flexWrap: "wrap", justifyContent: "center", gap: 7 },
|
||||||
flexDirection: "row",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
gap: 7,
|
|
||||||
},
|
|
||||||
dot: { width: 7, height: 7, borderRadius: 4, backgroundColor: Colors.border },
|
dot: { width: 7, height: 7, borderRadius: 4, backgroundColor: Colors.border },
|
||||||
dotActive: { width: 18, backgroundColor: Colors.primary },
|
dotActive: { width: 18, backgroundColor: Colors.primary },
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import React, { useMemo } from "react";
|
||||||
import { ScrollView } from "react-native";
|
import { ScrollView } from "react-native";
|
||||||
|
|
||||||
import type { DetailRendererProps } from "../types/renderer.types";
|
import type { DetailRendererProps } from "../types/renderer.types";
|
||||||
import { buildDefinitionLabelMap, humanizeKey, resolveAttributeLabel } from "./helpers/value";
|
import { humanizeKey } from "./helpers/value";
|
||||||
import { ContentValue } from "./shared/ContentValue";
|
import { ContentValue } from "./shared/ContentValue";
|
||||||
import { Hero } from "./shared/Hero";
|
import { Hero } from "./shared/Hero";
|
||||||
import { ImageGallery } from "./shared/ImageGallery";
|
import { ImageGallery } from "./shared/ImageGallery";
|
||||||
|
|
@ -40,7 +40,10 @@ export function GenericDetailRenderer({
|
||||||
);
|
);
|
||||||
|
|
||||||
const definitionMap = useMemo(
|
const definitionMap = useMemo(
|
||||||
() => buildDefinitionLabelMap(definitions),
|
() =>
|
||||||
|
new Map(
|
||||||
|
(definitions ?? []).map((d) => [d.code, d.label]),
|
||||||
|
),
|
||||||
[definitions],
|
[definitions],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -70,7 +73,8 @@ export function GenericDetailRenderer({
|
||||||
!(isTherapeutic && key.toLowerCase() === "name"),
|
!(isTherapeutic && key.toLowerCase() === "name"),
|
||||||
)
|
)
|
||||||
.map(([key, value]) => {
|
.map(([key, value]) => {
|
||||||
const label = resolveAttributeLabel(key, definitionMap);
|
const rawLabel = definitionMap.get(key) || key;
|
||||||
|
const label = humanizeKey(rawLabel);
|
||||||
return (
|
return (
|
||||||
<SectionCard key={key} title={label}>
|
<SectionCard key={key} title={label}>
|
||||||
<ContentValue value={value} />
|
<ContentValue value={value} />
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import { moderateScale, verticalScale } from "react-native-size-matters";
|
||||||
import { Colors } from "@/theme";
|
import { Colors } from "@/theme";
|
||||||
import { asNumber, asString } from "../helpers/value";
|
import { asNumber, asString } from "../helpers/value";
|
||||||
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
||||||
import { OverviewCard } from "../shared/OverviewCard";
|
|
||||||
import type {
|
import type {
|
||||||
CollectionItemRendererProps,
|
CollectionItemRendererProps,
|
||||||
CollectionRendererProps,
|
CollectionRendererProps,
|
||||||
|
|
@ -25,15 +24,24 @@ export function EightPrinciplesCollectionRenderer(
|
||||||
|
|
||||||
const header = (
|
const header = (
|
||||||
<View style={styles.overviewContainer}>
|
<View style={styles.overviewContainer}>
|
||||||
<OverviewCard
|
<View style={styles.overviewCard}>
|
||||||
style={styles.overviewCard}
|
<View style={styles.overviewHeader}>
|
||||||
paragraphs={[
|
<Ionicons name="information-circle" size={20} color={Colors.primary} />
|
||||||
"The eight principles include exterior, interior, cold, heat, deficiency, excess, yin and yang. Syndrome differentiation (pattern identification) of the eight principles is an essential paradigm in the Chinese medicine system.",
|
<Text style={styles.overviewTitle}>Overview</Text>
|
||||||
"Pattern identification of the eight principles aims to tell about the disease location, the pathogenic nature and the strength between antipathogenic qi and pathogenic factors, thus generalizing the condition into eight categories.",
|
</View>
|
||||||
"The eight principles can be divided into four pairs: interior/exterior for the depth of pathogens; cold/heat for the disease nature; deficiency/excess for the strength between antipathogenic qi and pathogenic factors; and yin/yang for the preponderance of yin and yang. However, yin and yang can also generalize the other six principles: exterior, heat and excess are ascribed to yang, and interior, cold and deficiency to yin.",
|
<Text style={styles.overviewText}>
|
||||||
"Two or more principles may occur concurrently, such as an exterior cold syndrome and an interior deficiency cold syndrome. A combined deficiency and excess may also be present. The principles may transform into each other as well, such as cold transforming into heat, or the exterior entering the interior. Additionally, a true cold may sometimes manifest as a false heat or vice versa.",
|
The eight principles include exterior, interior, cold, heat, deficiency, excess, yin and yang. Syndrome differentiation (pattern identification) of the eight principles is an essential paradigm in the Chinese medicine system.
|
||||||
]}
|
</Text>
|
||||||
/>
|
<Text style={styles.overviewParagraph}>
|
||||||
|
Pattern identification of the eight principles aims to tell about the disease location, the pathogenic nature and the strength between antipathogenic qi and pathogenic factors, thus generalizing the condition into eight categories.
|
||||||
|
</Text>
|
||||||
|
<Text style={styles.overviewParagraph}>
|
||||||
|
The eight principles can be divided into four pairs: interior/exterior for the depth of pathogens; cold/heat for the disease nature; deficiency/excess for the strength between antipathogenic qi and pathogenic factors; and yin/yang for the preponderance of yin and yang. However, yin and yang can also generalize the other six principles: exterior, heat and excess are ascribed to yang, and interior, cold and deficiency to yin.
|
||||||
|
</Text>
|
||||||
|
<Text style={styles.overviewParagraph}>
|
||||||
|
Two or more principles may occur concurrently, such as an exterior cold syndrome and an interior deficiency cold syndrome. A combined deficiency and excess may also be present. The principles may transform into each other as well, such as cold transforming into heat, or the exterior entering the interior. Additionally, a true cold may sometimes manifest as a false heat or vice versa.
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
<Text style={styles.sectionHeading}>Eight Principles</Text>
|
<Text style={styles.sectionHeading}>Eight Principles</Text>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|
@ -103,8 +111,35 @@ const styles = StyleSheet.create({
|
||||||
marginBottom: verticalScale(14),
|
marginBottom: verticalScale(14),
|
||||||
},
|
},
|
||||||
overviewCard: {
|
overviewCard: {
|
||||||
|
backgroundColor: "#FFFFFF",
|
||||||
|
borderRadius: moderateScale(16),
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: "#E2EAE5",
|
||||||
|
padding: moderateScale(16),
|
||||||
marginBottom: verticalScale(14),
|
marginBottom: verticalScale(14),
|
||||||
},
|
},
|
||||||
|
overviewHeader: {
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
marginBottom: verticalScale(8),
|
||||||
|
gap: moderateScale(8),
|
||||||
|
},
|
||||||
|
overviewTitle: {
|
||||||
|
fontSize: moderateScale(16),
|
||||||
|
fontWeight: "700",
|
||||||
|
color: Colors.textPrimary,
|
||||||
|
},
|
||||||
|
overviewText: {
|
||||||
|
fontSize: moderateScale(13),
|
||||||
|
lineHeight: verticalScale(19),
|
||||||
|
color: Colors.textSecondary,
|
||||||
|
},
|
||||||
|
overviewParagraph: {
|
||||||
|
fontSize: moderateScale(13),
|
||||||
|
lineHeight: verticalScale(19),
|
||||||
|
color: Colors.textSecondary,
|
||||||
|
marginTop: verticalScale(10),
|
||||||
|
},
|
||||||
sectionHeading: {
|
sectionHeading: {
|
||||||
fontSize: moderateScale(15),
|
fontSize: moderateScale(15),
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import { Colors } from "@/theme";
|
||||||
import { asNumber, asString } from "../helpers/value";
|
import { asNumber, asString } from "../helpers/value";
|
||||||
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
||||||
import { ContentCountBadge } from "../shared/ContentCountBadge";
|
import { ContentCountBadge } from "../shared/ContentCountBadge";
|
||||||
import { OverviewCard } from "../shared/OverviewCard";
|
|
||||||
import type {
|
import type {
|
||||||
CollectionItemRendererProps,
|
CollectionItemRendererProps,
|
||||||
CollectionRendererProps,
|
CollectionRendererProps,
|
||||||
|
|
@ -16,14 +15,21 @@ import type {
|
||||||
export function FiveElementsCollectionRenderer(props: CollectionRendererProps) {
|
export function FiveElementsCollectionRenderer(props: CollectionRendererProps) {
|
||||||
const header = (
|
const header = (
|
||||||
<View style={styles.overviewContainer}>
|
<View style={styles.overviewContainer}>
|
||||||
<OverviewCard
|
<View style={styles.overviewCard}>
|
||||||
style={styles.overviewCard}
|
<View style={styles.overviewHeader}>
|
||||||
paragraphs={[
|
<Ionicons name="information-circle" size={20} color={Colors.primary} />
|
||||||
"The identification of patterns according to the Five Elements is based on the pathological changes occurring in dysfunctions of the Generating, Overacting and Insulting sequences of the Five Elements.",
|
<Text style={styles.overviewTitle}>Overview</Text>
|
||||||
"These patterns describe clinical conditions which are often expressed by the Internal Organ patterns, but in certain cases, Five-Element patterns describe conditions falling outside their scope (such as Deficient Qi of Wood manifesting with timidity and indecision).",
|
</View>
|
||||||
"The sequences below detail the Generating, Overacting, and Insulting relationships and their specific clinical presentations.",
|
<Text style={styles.overviewText}>
|
||||||
]}
|
The identification of patterns according to the Five Elements is based on the pathological changes occurring in dysfunctions of the Generating, Overacting and Insulting sequences of the Five Elements.
|
||||||
/>
|
</Text>
|
||||||
|
<Text style={styles.overviewParagraph}>
|
||||||
|
These patterns describe clinical conditions which are often expressed by the Internal Organ patterns, but in certain cases, Five-Element patterns describe conditions falling outside their scope (such as Deficient Qi of Wood manifesting with timidity and indecision).
|
||||||
|
</Text>
|
||||||
|
<Text style={styles.overviewParagraph}>
|
||||||
|
The sequences below detail the Generating, Overacting, and Insulting relationships and their specific clinical presentations.
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
<Text style={styles.sectionHeading}>Sequences</Text>
|
<Text style={styles.sectionHeading}>Sequences</Text>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|
@ -45,10 +51,11 @@ export function FiveElementsCardRenderer({
|
||||||
}: CollectionItemRendererProps) {
|
}: CollectionItemRendererProps) {
|
||||||
const attributes = item.attributes;
|
const attributes = item.attributes;
|
||||||
const title = asString(attributes.title) || asString(attributes.name) || item.title;
|
const title = asString(attributes.title) || asString(attributes.name) || item.title;
|
||||||
const subtitle =
|
const label =
|
||||||
asString(attributes.sub_title) ||
|
asString(attributes.content_label) ||
|
||||||
asString(attributes.description) ||
|
asString(attributes.description) ||
|
||||||
(item.summary && item.summary !== "Open sequence" ? item.summary : null);
|
item.summary ||
|
||||||
|
"Open sequence";
|
||||||
|
|
||||||
const sortOrder = asNumber(attributes.sort_order);
|
const sortOrder = asNumber(attributes.sort_order);
|
||||||
const sequenceNumber = typeof sortOrder === "number" ? sortOrder + 1 : undefined;
|
const sequenceNumber = typeof sortOrder === "number" ? sortOrder + 1 : undefined;
|
||||||
|
|
@ -65,11 +72,9 @@ export function FiveElementsCardRenderer({
|
||||||
|
|
||||||
<View style={styles.textContainer}>
|
<View style={styles.textContainer}>
|
||||||
<Text style={styles.title}>{title}</Text>
|
<Text style={styles.title}>{title}</Text>
|
||||||
{subtitle ? (
|
|
||||||
<Text style={styles.description} numberOfLines={1}>
|
<Text style={styles.description} numberOfLines={1}>
|
||||||
{subtitle}
|
{label}
|
||||||
</Text>
|
</Text>
|
||||||
) : null}
|
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<ContentCountBadge
|
<ContentCountBadge
|
||||||
|
|
@ -86,8 +91,35 @@ const styles = StyleSheet.create({
|
||||||
marginBottom: verticalScale(14),
|
marginBottom: verticalScale(14),
|
||||||
},
|
},
|
||||||
overviewCard: {
|
overviewCard: {
|
||||||
|
backgroundColor: "#FFFFFF",
|
||||||
|
borderRadius: moderateScale(16),
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: "#E2EAE5",
|
||||||
|
padding: moderateScale(16),
|
||||||
marginBottom: verticalScale(14),
|
marginBottom: verticalScale(14),
|
||||||
},
|
},
|
||||||
|
overviewHeader: {
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
marginBottom: verticalScale(8),
|
||||||
|
gap: moderateScale(8),
|
||||||
|
},
|
||||||
|
overviewTitle: {
|
||||||
|
fontSize: moderateScale(16),
|
||||||
|
fontWeight: "700",
|
||||||
|
color: Colors.textPrimary,
|
||||||
|
},
|
||||||
|
overviewText: {
|
||||||
|
fontSize: moderateScale(13),
|
||||||
|
lineHeight: verticalScale(19),
|
||||||
|
color: Colors.textSecondary,
|
||||||
|
},
|
||||||
|
overviewParagraph: {
|
||||||
|
fontSize: moderateScale(13),
|
||||||
|
lineHeight: verticalScale(19),
|
||||||
|
color: Colors.textSecondary,
|
||||||
|
marginTop: verticalScale(10),
|
||||||
|
},
|
||||||
sectionHeading: {
|
sectionHeading: {
|
||||||
fontSize: moderateScale(15),
|
fontSize: moderateScale(15),
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import { Colors } from "@/theme";
|
||||||
import { asNumber, asString } from "../helpers/value";
|
import { asNumber, asString } from "../helpers/value";
|
||||||
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
||||||
import { ContentCountBadge } from "../shared/ContentCountBadge";
|
import { ContentCountBadge } from "../shared/ContentCountBadge";
|
||||||
import { OverviewCard } from "../shared/OverviewCard";
|
|
||||||
import type {
|
import type {
|
||||||
CollectionItemRendererProps,
|
CollectionItemRendererProps,
|
||||||
CollectionRendererProps,
|
CollectionRendererProps,
|
||||||
|
|
@ -16,17 +15,30 @@ import type {
|
||||||
export function FourLevelsCollectionRenderer(props: CollectionRendererProps) {
|
export function FourLevelsCollectionRenderer(props: CollectionRendererProps) {
|
||||||
const header = (
|
const header = (
|
||||||
<View style={styles.overviewContainer}>
|
<View style={styles.overviewContainer}>
|
||||||
<OverviewCard
|
<View style={styles.overviewCard}>
|
||||||
style={styles.overviewCard}
|
<View style={styles.overviewHeader}>
|
||||||
paragraphs={[
|
<Ionicons name="information-circle" size={20} color={Colors.primary} />
|
||||||
"The Four Levels of Diagnosis in Traditional Chinese Medicine (TCM) is a framework mainly used in Warm Disease Theory (Wen Bing), which deals with febrile (heat) diseases caused by external pathogens, especially warm pathogens like viruses or bacteria. It helps practitioners understand the progression of the disease and guide treatment.",
|
<Text style={styles.overviewTitle}>Overview</Text>
|
||||||
"The interpretation of clinical manifestations of Warm Diseases according to the Four Levels was formulated by Ye Tian Shi. This is a brilliant theory that provides the most clinically useful tool to diagnose, interpret and treat diseases caused by external Wind-Heat and their consequences, whether they are Warm Diseases or not.",
|
</View>
|
||||||
"The theory of the Four Levels is clinically more relevant than that of the Six Stages. For example, one of the most common consequences of an invasion of Wind-Heat is the transformation of external Wind-Heat into interior Phlegm-Heat in the Lungs, causing a chest infection: this situation is contemplated in the Four Levels (corresponding to Lung-Heat, Qi level), while it is not contemplated in the Six Stages.",
|
<Text style={styles.overviewText}>
|
||||||
"The Qi level contemplates the pattern of Damp-Heat in Stomach and Spleen as a consequence of an invasion of Wind-Heat: this is a very common clinical situation and yet it is one that is not contemplated in the Six Stages.",
|
The Four Levels of Diagnosis in Traditional Chinese Medicine (TCM) is a framework mainly used in Warm Disease Theory (Wen Bing), which deals with febrile (heat) diseases caused by external pathogens, especially warm pathogens like viruses or bacteria. It helps practitioners understand the progression of the disease and guide treatment.
|
||||||
"The Blood level includes patterns which are characterized by convulsions from the development of internal Wind: these are typical complications of children’s diseases such as meningitis but they are not contemplated in the Six Stages.",
|
</Text>
|
||||||
"The Four Levels are the Defensive Qi, Qi, Nutritive Qi and Blood levels (Wei, Qi, Ying, Xue): the first level is the only exterior one characterized by the presence of the external Wind-Heat on the energetic surface of the body. The other three levels are all interior and all characterized by interior Heat; however, the brilliance of this theory lies in its identification of three different depths of penetration of interior pathogenic Heat. Each level has its own distinctive pathology and treatment.",
|
<Text style={styles.overviewParagraph}>
|
||||||
]}
|
The interpretation of clinical manifestations of Warm Diseases according to the Four Levels was formulated by Ye Tian Shi. This is a brilliant theory that provides the most clinically useful tool to diagnose, interpret and treat diseases caused by external Wind-Heat and their consequences, whether they are Warm Diseases or not.
|
||||||
/>
|
</Text>
|
||||||
|
<Text style={styles.overviewParagraph}>
|
||||||
|
The theory of the Four Levels is clinically more relevant than that of the Six Stages. For example, one of the most common consequences of an invasion of Wind-Heat is the transformation of external Wind-Heat into interior Phlegm-Heat in the Lungs, causing a chest infection: this situation is contemplated in the Four Levels (corresponding to Lung-Heat, Qi level), while it is not contemplated in the Six Stages.
|
||||||
|
</Text>
|
||||||
|
<Text style={styles.overviewParagraph}>
|
||||||
|
The Qi level contemplates the pattern of Damp-Heat in Stomach and Spleen as a consequence of an invasion of Wind-Heat: this is a very common clinical situation and yet it is one that is not contemplated in the Six Stages.
|
||||||
|
</Text>
|
||||||
|
<Text style={styles.overviewParagraph}>
|
||||||
|
The Blood level includes patterns which are characterized by convulsions from the development of internal Wind: these are typical complications of children’s diseases such as meningitis but they are not contemplated in the Six Stages.
|
||||||
|
</Text>
|
||||||
|
<Text style={styles.overviewParagraph}>
|
||||||
|
The Four Levels are the Defensive Qi, Qi, Nutritive Qi and Blood levels (Wei, Qi, Ying, Xue): the first level is the only exterior one characterized by the presence of the external Wind-Heat on the energetic surface of the body. The other three levels are all interior and all characterized by interior Heat; however, the brilliance of this theory lies in its identification of three different depths of penetration of interior pathogenic Heat. Each level has its own distinctive pathology and treatment.
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
<Text style={styles.sectionHeading}>Levels</Text>
|
<Text style={styles.sectionHeading}>Levels</Text>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|
@ -48,10 +60,11 @@ export function FourLevelsCardRenderer({
|
||||||
}: CollectionItemRendererProps) {
|
}: CollectionItemRendererProps) {
|
||||||
const attributes = item.attributes;
|
const attributes = item.attributes;
|
||||||
const title = asString(attributes.title) || asString(attributes.name) || item.title;
|
const title = asString(attributes.title) || asString(attributes.name) || item.title;
|
||||||
const subtitle =
|
const label =
|
||||||
asString(attributes.sub_title) ||
|
asString(attributes.content_label) ||
|
||||||
asString(attributes.description) ||
|
asString(attributes.description) ||
|
||||||
(item.summary && item.summary !== "Open content" ? item.summary : null);
|
item.summary ||
|
||||||
|
"Open content";
|
||||||
|
|
||||||
const sortOrder = asNumber(attributes.sort_order);
|
const sortOrder = asNumber(attributes.sort_order);
|
||||||
const levelNumber = typeof sortOrder === "number" ? sortOrder + 1 : undefined;
|
const levelNumber = typeof sortOrder === "number" ? sortOrder + 1 : undefined;
|
||||||
|
|
@ -68,11 +81,9 @@ export function FourLevelsCardRenderer({
|
||||||
|
|
||||||
<View style={styles.textContainer}>
|
<View style={styles.textContainer}>
|
||||||
<Text style={styles.title}>{title}</Text>
|
<Text style={styles.title}>{title}</Text>
|
||||||
{subtitle ? (
|
|
||||||
<Text style={styles.description} numberOfLines={1}>
|
<Text style={styles.description} numberOfLines={1}>
|
||||||
{subtitle}
|
{label}
|
||||||
</Text>
|
</Text>
|
||||||
) : null}
|
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<ContentCountBadge
|
<ContentCountBadge
|
||||||
|
|
@ -89,8 +100,35 @@ const styles = StyleSheet.create({
|
||||||
marginBottom: verticalScale(14),
|
marginBottom: verticalScale(14),
|
||||||
},
|
},
|
||||||
overviewCard: {
|
overviewCard: {
|
||||||
|
backgroundColor: "#FFFFFF",
|
||||||
|
borderRadius: moderateScale(16),
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: "#E2EAE5",
|
||||||
|
padding: moderateScale(16),
|
||||||
marginBottom: verticalScale(14),
|
marginBottom: verticalScale(14),
|
||||||
},
|
},
|
||||||
|
overviewHeader: {
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
marginBottom: verticalScale(8),
|
||||||
|
gap: moderateScale(8),
|
||||||
|
},
|
||||||
|
overviewTitle: {
|
||||||
|
fontSize: moderateScale(16),
|
||||||
|
fontWeight: "700",
|
||||||
|
color: Colors.textPrimary,
|
||||||
|
},
|
||||||
|
overviewText: {
|
||||||
|
fontSize: moderateScale(13),
|
||||||
|
lineHeight: verticalScale(19),
|
||||||
|
color: Colors.textSecondary,
|
||||||
|
},
|
||||||
|
overviewParagraph: {
|
||||||
|
fontSize: moderateScale(13),
|
||||||
|
lineHeight: verticalScale(19),
|
||||||
|
color: Colors.textSecondary,
|
||||||
|
marginTop: verticalScale(10),
|
||||||
|
},
|
||||||
sectionHeading: {
|
sectionHeading: {
|
||||||
fontSize: moderateScale(15),
|
fontSize: moderateScale(15),
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import { Colors } from "@/theme";
|
||||||
import { asString, humanizeKey } from "../helpers/value";
|
import { asString, humanizeKey } from "../helpers/value";
|
||||||
import { Hero } from "../shared/Hero";
|
import { Hero } from "../shared/Hero";
|
||||||
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
||||||
import { OverviewCard } from "../shared/OverviewCard";
|
|
||||||
import type { CollectionRendererProps } from "../../types/renderer.types";
|
import type { CollectionRendererProps } from "../../types/renderer.types";
|
||||||
|
|
||||||
export interface GynecologyDiseaseInfo {
|
export interface GynecologyDiseaseInfo {
|
||||||
|
|
@ -541,21 +540,25 @@ export function GynecologyDiseaseCollectionRenderer(
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{paragraphs.length > 0 ? (
|
{paragraphs.length > 0 ? (
|
||||||
<OverviewCard
|
<View style={styles.overviewCard}>
|
||||||
paragraphs={paragraphs}
|
<View style={styles.overviewHeader}>
|
||||||
style={{ marginTop: verticalScale(12) }}
|
<Ionicons name="information-circle" size={20} color={Colors.primary} />
|
||||||
/>
|
<Text style={styles.overviewTitle}>Overview</Text>
|
||||||
|
</View>
|
||||||
|
{paragraphs.map((para, index) => (
|
||||||
|
<Text
|
||||||
|
key={index}
|
||||||
|
style={index === 0 ? styles.overviewText : styles.overviewParagraph}
|
||||||
|
>
|
||||||
|
{para}
|
||||||
|
</Text>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return <CollectionScaffold {...props} header={header} />;
|
||||||
<CollectionScaffold
|
|
||||||
{...props}
|
|
||||||
header={header}
|
|
||||||
countLabel="Identifications of patterns"
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createGynecologyDiseaseCollectionRenderer(templateCode: string) {
|
export function createGynecologyDiseaseCollectionRenderer(templateCode: string) {
|
||||||
|
|
@ -575,4 +578,34 @@ const styles = StyleSheet.create({
|
||||||
overviewContainer: {
|
overviewContainer: {
|
||||||
marginBottom: verticalScale(14),
|
marginBottom: verticalScale(14),
|
||||||
},
|
},
|
||||||
|
overviewCard: {
|
||||||
|
backgroundColor: "#FFFFFF",
|
||||||
|
borderRadius: moderateScale(16),
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: "#D7E9DE",
|
||||||
|
padding: moderateScale(16),
|
||||||
|
marginTop: verticalScale(12),
|
||||||
|
},
|
||||||
|
overviewHeader: {
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: moderateScale(8),
|
||||||
|
marginBottom: verticalScale(10),
|
||||||
|
},
|
||||||
|
overviewTitle: {
|
||||||
|
fontSize: moderateScale(15),
|
||||||
|
fontWeight: "700",
|
||||||
|
color: Colors.primaryDark,
|
||||||
|
},
|
||||||
|
overviewText: {
|
||||||
|
fontSize: moderateScale(13),
|
||||||
|
lineHeight: moderateScale(20),
|
||||||
|
color: "#374151",
|
||||||
|
},
|
||||||
|
overviewParagraph: {
|
||||||
|
fontSize: moderateScale(13),
|
||||||
|
lineHeight: moderateScale(20),
|
||||||
|
color: "#374151",
|
||||||
|
marginTop: verticalScale(8),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -14,21 +14,13 @@ import { useRouter } from "expo-router";
|
||||||
import { moderateScale, verticalScale } from "react-native-size-matters";
|
import { moderateScale, verticalScale } from "react-native-size-matters";
|
||||||
|
|
||||||
import { Colors } from "@/theme";
|
import { Colors } from "@/theme";
|
||||||
import {
|
import { asNumber, asString, asStringArray, humanizeKey } from "../helpers/value";
|
||||||
asNumber,
|
|
||||||
asString,
|
|
||||||
asStringArray,
|
|
||||||
buildDefinitionLabelMap,
|
|
||||||
humanizeKey,
|
|
||||||
resolveAttributeLabel,
|
|
||||||
} from "../helpers/value";
|
|
||||||
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
||||||
import { ContentCountBadge } from "../shared/ContentCountBadge";
|
import { ContentCountBadge } from "../shared/ContentCountBadge";
|
||||||
import { greenTone } from "../shared/reading-palette";
|
import { greenTone } from "../shared/reading-palette";
|
||||||
import {
|
import {
|
||||||
useModuleContentDetailQuery,
|
useModuleContentDetailQuery,
|
||||||
useModuleTemplateContentDetailsQuery,
|
useModuleTemplateContentDetailsQuery,
|
||||||
useTemplateDefinitionsQuery,
|
|
||||||
} from "../../hooks/use-content-queries";
|
} from "../../hooks/use-content-queries";
|
||||||
import type {
|
import type {
|
||||||
CollectionItemRendererProps,
|
CollectionItemRendererProps,
|
||||||
|
|
@ -43,10 +35,6 @@ export function ModuleCatalogCollectionRenderer(props: CollectionRendererProps)
|
||||||
return <CollectionScaffold {...props} />;
|
return <CollectionScaffold {...props} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
function stripTrailingPeriod(value: string): string {
|
|
||||||
return value.replace(/\s*\.+\s*$/, "").trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
function normalizePointCode(raw: string): string {
|
function normalizePointCode(raw: string): string {
|
||||||
let code = raw.replace(/\s*\([^)]*\)/g, "").trim().toLowerCase();
|
let code = raw.replace(/\s*\([^)]*\)/g, "").trim().toLowerCase();
|
||||||
code = code.replace(/^ren-/, "cv-");
|
code = code.replace(/^ren-/, "cv-");
|
||||||
|
|
@ -82,16 +70,6 @@ export function PatternAccordionCardRenderer({
|
||||||
contentId,
|
contentId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const detailTemplateCode =
|
|
||||||
asString(linkTarget?.template_code) ||
|
|
||||||
asString(detailQuery.data?.content?.metadata?.template_code) ||
|
|
||||||
(moduleCode.toLowerCase() === "m0042" ? "m0042_ct0005" : "");
|
|
||||||
const templateDefsQuery = useTemplateDefinitionsQuery(detailTemplateCode || undefined);
|
|
||||||
const labelMap = useMemo(
|
|
||||||
() => buildDefinitionLabelMap(templateDefsQuery.data?.attributes),
|
|
||||||
[templateDefsQuery.data?.attributes],
|
|
||||||
);
|
|
||||||
|
|
||||||
// Query all acupuncture points from m0001 to resolve links
|
// Query all acupuncture points from m0001 to resolve links
|
||||||
const { data: pointsData } = useModuleTemplateContentDetailsQuery({
|
const { data: pointsData } = useModuleTemplateContentDetailsQuery({
|
||||||
module_code: "m0001",
|
module_code: "m0001",
|
||||||
|
|
@ -160,8 +138,8 @@ export function PatternAccordionCardRenderer({
|
||||||
? rawManifestations.split("\n").map((s) => s.trim()).filter(Boolean)
|
? rawManifestations.split("\n").map((s) => s.trim()).filter(Boolean)
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
const tongue = stripTrailingPeriod(asString(detailData.tongue));
|
const tongue = asString(detailData.tongue);
|
||||||
const pulse = stripTrailingPeriod(asString(detailData.pulse));
|
const pulse = asString(detailData.pulse);
|
||||||
const rawPrinciples = detailData.treatment_principle;
|
const rawPrinciples = detailData.treatment_principle;
|
||||||
const treatmentPrinciples: string[] = Array.isArray(rawPrinciples)
|
const treatmentPrinciples: string[] = Array.isArray(rawPrinciples)
|
||||||
? (rawPrinciples as string[]).map(String).map((s) => s.trim()).filter(Boolean)
|
? (rawPrinciples as string[]).map(String).map((s) => s.trim()).filter(Boolean)
|
||||||
|
|
@ -235,7 +213,7 @@ export function PatternAccordionCardRenderer({
|
||||||
{clinicalManifestations.length > 0 ? (
|
{clinicalManifestations.length > 0 ? (
|
||||||
<View style={accordionStyles.section}>
|
<View style={accordionStyles.section}>
|
||||||
<Text style={accordionStyles.sectionTitle}>
|
<Text style={accordionStyles.sectionTitle}>
|
||||||
{resolveAttributeLabel("clinical_manifestations", labelMap, "Clinical Manifestations")}
|
Clinical Manifestations
|
||||||
</Text>
|
</Text>
|
||||||
<View style={accordionStyles.bulletList}>
|
<View style={accordionStyles.bulletList}>
|
||||||
{clinicalManifestations.map((itemText, idx) => (
|
{clinicalManifestations.map((itemText, idx) => (
|
||||||
|
|
@ -248,23 +226,22 @@ export function PatternAccordionCardRenderer({
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{/* 2. Tongue */}
|
{/* 2. Tongue & Pulse (Side-by-Side as drawn) */}
|
||||||
|
{tongue || pulse ? (
|
||||||
|
<View style={accordionStyles.twoColumnBox}>
|
||||||
{tongue ? (
|
{tongue ? (
|
||||||
<View style={accordionStyles.section}>
|
<View style={accordionStyles.column}>
|
||||||
<Text style={accordionStyles.sectionTitle}>
|
<Text style={accordionStyles.columnLabel}>Tongue</Text>
|
||||||
{resolveAttributeLabel("tongue", labelMap, "Tongue")}
|
<Text style={accordionStyles.columnValue}>{tongue}</Text>
|
||||||
</Text>
|
|
||||||
<Text style={accordionStyles.sectionText}>{tongue}</Text>
|
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
{tongue && pulse ? <View style={accordionStyles.columnDivider} /> : null}
|
||||||
{/* 3. Pulse */}
|
|
||||||
{pulse ? (
|
{pulse ? (
|
||||||
<View style={accordionStyles.section}>
|
<View style={accordionStyles.column}>
|
||||||
<Text style={accordionStyles.sectionTitle}>
|
<Text style={accordionStyles.columnLabel}>Pulse</Text>
|
||||||
{resolveAttributeLabel("pulse", labelMap, "Pulse")}
|
<Text style={accordionStyles.columnValue}>{pulse}</Text>
|
||||||
</Text>
|
</View>
|
||||||
<Text style={accordionStyles.sectionText}>{pulse}</Text>
|
) : null}
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
|
@ -272,7 +249,7 @@ export function PatternAccordionCardRenderer({
|
||||||
{treatmentPrinciples.length > 0 ? (
|
{treatmentPrinciples.length > 0 ? (
|
||||||
<View style={accordionStyles.section}>
|
<View style={accordionStyles.section}>
|
||||||
<Text style={accordionStyles.sectionTitle}>
|
<Text style={accordionStyles.sectionTitle}>
|
||||||
{resolveAttributeLabel("treatment_principle", labelMap, "Treatment Principle")}
|
Treatment Principle
|
||||||
</Text>
|
</Text>
|
||||||
<View style={accordionStyles.bulletList}>
|
<View style={accordionStyles.bulletList}>
|
||||||
{treatmentPrinciples.map((itemText, idx) => (
|
{treatmentPrinciples.map((itemText, idx) => (
|
||||||
|
|
@ -285,12 +262,13 @@ export function PatternAccordionCardRenderer({
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{/* 4. Acupuncture Points */}
|
{/* 4. Acupuncture Points & Method */}
|
||||||
{pointChips.length > 0 ? (
|
{pointChips.length > 0 || acuMethod ? (
|
||||||
<View style={accordionStyles.section}>
|
<View style={accordionStyles.section}>
|
||||||
<Text style={accordionStyles.sectionTitle}>
|
<Text style={accordionStyles.sectionTitle}>
|
||||||
{resolveAttributeLabel("acupuncture", labelMap, "Acupuncture Points")}
|
Acupuncture Points
|
||||||
</Text>
|
</Text>
|
||||||
|
{pointChips.length > 0 ? (
|
||||||
<View style={accordionStyles.chipsContainer}>
|
<View style={accordionStyles.chipsContainer}>
|
||||||
{pointChips.map((pt, idx) => (
|
{pointChips.map((pt, idx) => (
|
||||||
<Pressable
|
<Pressable
|
||||||
|
|
@ -313,16 +291,13 @@ export function PatternAccordionCardRenderer({
|
||||||
</Pressable>
|
</Pressable>
|
||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
|
) : null}
|
||||||
|
{acuMethod ? (
|
||||||
|
<View style={accordionStyles.methodContainer}>
|
||||||
|
<Text style={accordionStyles.subSectionLabel}>Method:</Text>
|
||||||
|
<Text style={accordionStyles.methodText}>{acuMethod}</Text>
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{/* 5. Method */}
|
|
||||||
{acuMethod ? (
|
|
||||||
<View style={accordionStyles.section}>
|
|
||||||
<Text style={accordionStyles.sectionTitle}>
|
|
||||||
{resolveAttributeLabel("acupuncture.method", labelMap, "Method")}
|
|
||||||
</Text>
|
|
||||||
<Text style={accordionStyles.sectionText}>{acuMethod}</Text>
|
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
|
@ -330,7 +305,7 @@ export function PatternAccordionCardRenderer({
|
||||||
{explanations.length > 0 ? (
|
{explanations.length > 0 ? (
|
||||||
<View style={accordionStyles.section}>
|
<View style={accordionStyles.section}>
|
||||||
<Text style={accordionStyles.sectionTitle}>
|
<Text style={accordionStyles.sectionTitle}>
|
||||||
{resolveAttributeLabel("explanation", labelMap, "Explanation")}
|
Explanation
|
||||||
</Text>
|
</Text>
|
||||||
<View style={accordionStyles.explanationList}>
|
<View style={accordionStyles.explanationList}>
|
||||||
{explanations.map((exp, idx) => (
|
{explanations.map((exp, idx) => (
|
||||||
|
|
@ -346,9 +321,7 @@ export function PatternAccordionCardRenderer({
|
||||||
{/* 6. Category */}
|
{/* 6. Category */}
|
||||||
{category ? (
|
{category ? (
|
||||||
<View style={accordionStyles.categoryRow}>
|
<View style={accordionStyles.categoryRow}>
|
||||||
<Text style={accordionStyles.categoryLabel}>
|
<Text style={accordionStyles.categoryLabel}>Category:</Text>
|
||||||
{`${resolveAttributeLabel("category", labelMap, "Category")}:`}
|
|
||||||
</Text>
|
|
||||||
<View style={accordionStyles.categoryBadge}>
|
<View style={accordionStyles.categoryBadge}>
|
||||||
<Text style={accordionStyles.categoryBadgeText}>{category}</Text>
|
<Text style={accordionStyles.categoryBadgeText}>{category}</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
@ -522,7 +495,8 @@ const accordionStyles = StyleSheet.create({
|
||||||
lineHeight: moderateScale(16),
|
lineHeight: moderateScale(16),
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: "#4A6B5B",
|
color: "#4A6B5B",
|
||||||
letterSpacing: 0.15,
|
textTransform: "uppercase",
|
||||||
|
letterSpacing: 0.7,
|
||||||
},
|
},
|
||||||
bulletList: {
|
bulletList: {
|
||||||
gap: verticalScale(8),
|
gap: verticalScale(8),
|
||||||
|
|
@ -545,10 +519,38 @@ const accordionStyles = StyleSheet.create({
|
||||||
lineHeight: moderateScale(21),
|
lineHeight: moderateScale(21),
|
||||||
color: "#334155",
|
color: "#334155",
|
||||||
},
|
},
|
||||||
sectionText: {
|
twoColumnBox: {
|
||||||
|
flexDirection: "row",
|
||||||
|
backgroundColor: greenTone.soft,
|
||||||
|
borderRadius: moderateScale(10),
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: greenTone.border,
|
||||||
|
paddingHorizontal: moderateScale(14),
|
||||||
|
paddingVertical: verticalScale(11),
|
||||||
|
alignItems: "stretch",
|
||||||
|
},
|
||||||
|
column: {
|
||||||
|
flex: 1,
|
||||||
|
gap: verticalScale(3),
|
||||||
|
},
|
||||||
|
columnDivider: {
|
||||||
|
width: StyleSheet.hairlineWidth,
|
||||||
|
backgroundColor: greenTone.border,
|
||||||
|
marginHorizontal: moderateScale(12),
|
||||||
|
},
|
||||||
|
columnLabel: {
|
||||||
|
fontSize: moderateScale(11),
|
||||||
|
lineHeight: moderateScale(15),
|
||||||
|
fontWeight: "700",
|
||||||
|
color: "#597064",
|
||||||
|
textTransform: "uppercase",
|
||||||
|
letterSpacing: 0.5,
|
||||||
|
},
|
||||||
|
columnValue: {
|
||||||
fontSize: moderateScale(14),
|
fontSize: moderateScale(14),
|
||||||
lineHeight: moderateScale(21),
|
lineHeight: moderateScale(20),
|
||||||
color: "#334155",
|
color: "#1E293B",
|
||||||
|
fontWeight: "600",
|
||||||
},
|
},
|
||||||
principleBox: {
|
principleBox: {
|
||||||
backgroundColor: greenTone.soft,
|
backgroundColor: greenTone.soft,
|
||||||
|
|
@ -589,6 +591,23 @@ const accordionStyles = StyleSheet.create({
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: "#35664E",
|
color: "#35664E",
|
||||||
},
|
},
|
||||||
|
methodContainer: {
|
||||||
|
marginTop: verticalScale(4),
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "flex-start",
|
||||||
|
gap: moderateScale(6),
|
||||||
|
},
|
||||||
|
subSectionLabel: {
|
||||||
|
fontSize: moderateScale(13),
|
||||||
|
fontWeight: "700",
|
||||||
|
color: "#597064",
|
||||||
|
},
|
||||||
|
methodText: {
|
||||||
|
flex: 1,
|
||||||
|
fontSize: moderateScale(13),
|
||||||
|
lineHeight: moderateScale(19),
|
||||||
|
color: "#334155",
|
||||||
|
},
|
||||||
explanationList: {
|
explanationList: {
|
||||||
gap: verticalScale(8),
|
gap: verticalScale(8),
|
||||||
},
|
},
|
||||||
|
|
@ -621,7 +640,8 @@ const accordionStyles = StyleSheet.create({
|
||||||
lineHeight: moderateScale(15),
|
lineHeight: moderateScale(15),
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: "#597064",
|
color: "#597064",
|
||||||
letterSpacing: 0.15,
|
textTransform: "uppercase",
|
||||||
|
letterSpacing: 0.5,
|
||||||
},
|
},
|
||||||
categoryBadge: {
|
categoryBadge: {
|
||||||
backgroundColor: "#EEF7F1",
|
backgroundColor: "#EEF7F1",
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import { moderateScale, verticalScale } from "react-native-size-matters";
|
||||||
import { Colors } from "@/theme";
|
import { Colors } from "@/theme";
|
||||||
import { asNumber, asString } from "../helpers/value";
|
import { asNumber, asString } from "../helpers/value";
|
||||||
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
||||||
import { OverviewCard } from "../shared/OverviewCard";
|
|
||||||
import type {
|
import type {
|
||||||
CollectionItemRendererProps,
|
CollectionItemRendererProps,
|
||||||
CollectionRendererProps,
|
CollectionRendererProps,
|
||||||
|
|
@ -17,15 +16,24 @@ export function PathogenicFactorsCollectionRenderer(
|
||||||
) {
|
) {
|
||||||
const header = (
|
const header = (
|
||||||
<View style={styles.overviewContainer}>
|
<View style={styles.overviewContainer}>
|
||||||
<OverviewCard
|
<View style={styles.overviewCard}>
|
||||||
style={styles.overviewCard}
|
<View style={styles.overviewHeader}>
|
||||||
paragraphs={[
|
<Ionicons name="information-circle" size={20} color={Colors.primary} />
|
||||||
"This method of pattern identification is based on the pathological changes occurring when the body is invaded by pathogenic factors such as Wind, Cold, Summer-Heat, Dampness, Dryness and Fire. Each of these pathogenic factors may be exterior or interior.",
|
<Text style={styles.overviewTitle}>Overview</Text>
|
||||||
"They always correspond to a Full pattern according to the Eight Principles. Indeed, from the Eight-Principle point of view, a Full condition is defined as one characterized by the presence of a pathogenic factor while the body’s Qi is still relatively intact.",
|
</View>
|
||||||
"The pathogenic factor is frequently associated with a Deficiency, in which case the condition is a combined Full–Empty condition. With regard to pathogenic factors, a combined Full-Empty condition can arise in one of two ways: a pathogenic factor can give rise to a Deficiency (e.g. Fire weakens Yin) or a Deficiency can give rise to a pathogenic factor (e.g. Spleen-Qi deficiency gives rise to Dampness).",
|
<Text style={styles.overviewText}>
|
||||||
"Generally speaking, pathogenic factors are more relevant as patterns of disharmony than as causes of disease. The diagnosis of a pathogenic factor is made not on the basis of the patient’s history, but on the basis of the pattern of symptoms and signs presented.",
|
This method of pattern identification is based on the pathological changes occurring when the body is invaded by pathogenic factors such as Wind, Cold, Summer-Heat, Dampness, Dryness and Fire. Each of these pathogenic factors may be exterior or interior.
|
||||||
]}
|
</Text>
|
||||||
/>
|
<Text style={styles.overviewParagraph}>
|
||||||
|
They always correspond to a Full pattern according to the Eight Principles. Indeed, from the Eight-Principle point of view, a Full condition is defined as one characterized by the presence of a pathogenic factor while the body’s Qi is still relatively intact.
|
||||||
|
</Text>
|
||||||
|
<Text style={styles.overviewParagraph}>
|
||||||
|
The pathogenic factor is frequently associated with a Deficiency, in which case the condition is a combined Full–Empty condition. With regard to pathogenic factors, a combined Full-Empty condition can arise in one of two ways: a pathogenic factor can give rise to a Deficiency (e.g. Fire weakens Yin) or a Deficiency can give rise to a pathogenic factor (e.g. Spleen-Qi deficiency gives rise to Dampness).
|
||||||
|
</Text>
|
||||||
|
<Text style={styles.overviewParagraph}>
|
||||||
|
Generally speaking, pathogenic factors are more relevant as patterns of disharmony than as causes of disease. The diagnosis of a pathogenic factor is made not on the basis of the patient’s history, but on the basis of the pattern of symptoms and signs presented.
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
<Text style={styles.sectionHeading}>Pathogenic Factors</Text>
|
<Text style={styles.sectionHeading}>Pathogenic Factors</Text>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|
@ -97,8 +105,35 @@ const styles = StyleSheet.create({
|
||||||
marginBottom: verticalScale(14),
|
marginBottom: verticalScale(14),
|
||||||
},
|
},
|
||||||
overviewCard: {
|
overviewCard: {
|
||||||
|
backgroundColor: "#FFFFFF",
|
||||||
|
borderRadius: moderateScale(16),
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: "#E2EAE5",
|
||||||
|
padding: moderateScale(16),
|
||||||
marginBottom: verticalScale(14),
|
marginBottom: verticalScale(14),
|
||||||
},
|
},
|
||||||
|
overviewHeader: {
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
marginBottom: verticalScale(8),
|
||||||
|
gap: moderateScale(8),
|
||||||
|
},
|
||||||
|
overviewTitle: {
|
||||||
|
fontSize: moderateScale(16),
|
||||||
|
fontWeight: "700",
|
||||||
|
color: Colors.textPrimary,
|
||||||
|
},
|
||||||
|
overviewText: {
|
||||||
|
fontSize: moderateScale(13),
|
||||||
|
lineHeight: verticalScale(19),
|
||||||
|
color: Colors.textSecondary,
|
||||||
|
},
|
||||||
|
overviewParagraph: {
|
||||||
|
fontSize: moderateScale(13),
|
||||||
|
lineHeight: verticalScale(19),
|
||||||
|
color: Colors.textSecondary,
|
||||||
|
marginTop: verticalScale(10),
|
||||||
|
},
|
||||||
sectionHeading: {
|
sectionHeading: {
|
||||||
fontSize: moderateScale(15),
|
fontSize: moderateScale(15),
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import { moderateScale, verticalScale } from "react-native-size-matters";
|
||||||
import { Colors } from "@/theme";
|
import { Colors } from "@/theme";
|
||||||
import { asNumber, asString } from "../helpers/value";
|
import { asNumber, asString } from "../helpers/value";
|
||||||
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
||||||
import { OverviewCard } from "../shared/OverviewCard";
|
|
||||||
import { useSingleTemplateContentQuery } from "../../hooks/use-single-template-content-query";
|
import { useSingleTemplateContentQuery } from "../../hooks/use-single-template-content-query";
|
||||||
import type {
|
import type {
|
||||||
CollectionItemRendererProps,
|
CollectionItemRendererProps,
|
||||||
|
|
@ -70,7 +69,15 @@ export function QiBloodCollectionRenderer(props: CollectionRendererProps) {
|
||||||
|
|
||||||
const header = (
|
const header = (
|
||||||
<View style={styles.headerContainer}>
|
<View style={styles.headerContainer}>
|
||||||
{overviewText ? <OverviewCard text={overviewText} /> : null}
|
{overviewText ? (
|
||||||
|
<View style={styles.overviewCard}>
|
||||||
|
<View style={styles.overviewHeader}>
|
||||||
|
<Ionicons name="information-circle" size={20} color={Colors.primary} />
|
||||||
|
<Text style={styles.overviewTitle}>Overview</Text>
|
||||||
|
</View>
|
||||||
|
<Text style={styles.overviewText}>{overviewText}</Text>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
<Text style={styles.sectionHeading}>Categories</Text>
|
<Text style={styles.sectionHeading}>Categories</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
@ -127,6 +134,29 @@ const styles = StyleSheet.create({
|
||||||
paddingBottom: verticalScale(8),
|
paddingBottom: verticalScale(8),
|
||||||
gap: verticalScale(14),
|
gap: verticalScale(14),
|
||||||
},
|
},
|
||||||
|
overviewCard: {
|
||||||
|
backgroundColor: "#FFFFFF",
|
||||||
|
borderRadius: moderateScale(16),
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: "#E2EAE5",
|
||||||
|
padding: moderateScale(18),
|
||||||
|
},
|
||||||
|
overviewHeader: {
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
marginBottom: verticalScale(10),
|
||||||
|
gap: moderateScale(8),
|
||||||
|
},
|
||||||
|
overviewTitle: {
|
||||||
|
fontSize: moderateScale(16),
|
||||||
|
fontWeight: "700",
|
||||||
|
color: Colors.textPrimary,
|
||||||
|
},
|
||||||
|
overviewText: {
|
||||||
|
fontSize: moderateScale(14),
|
||||||
|
lineHeight: moderateScale(22),
|
||||||
|
color: Colors.textSecondary,
|
||||||
|
},
|
||||||
sectionHeading: {
|
sectionHeading: {
|
||||||
fontSize: moderateScale(16),
|
fontSize: moderateScale(16),
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import { moderateScale, verticalScale } from "react-native-size-matters";
|
||||||
import { Colors } from "@/theme";
|
import { Colors } from "@/theme";
|
||||||
import { asNumber, asString, humanizeKey } from "../helpers/value";
|
import { asNumber, asString, humanizeKey } from "../helpers/value";
|
||||||
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
||||||
import { OverviewCard } from "../shared/OverviewCard";
|
import { SectionCard } from "../shared/SectionCard";
|
||||||
import type {
|
import type {
|
||||||
CollectionItemRendererProps,
|
CollectionItemRendererProps,
|
||||||
CollectionRendererProps,
|
CollectionRendererProps,
|
||||||
|
|
@ -17,7 +17,9 @@ export function SixStagesCollectionRenderer(props: CollectionRendererProps) {
|
||||||
|
|
||||||
const header = overviewText ? (
|
const header = overviewText ? (
|
||||||
<View style={styles.overviewContainer}>
|
<View style={styles.overviewContainer}>
|
||||||
<OverviewCard text={overviewText} />
|
<SectionCard title="Overview" defaultExpanded={true}>
|
||||||
|
<Text style={styles.overviewText}>{overviewText}</Text>
|
||||||
|
</SectionCard>
|
||||||
</View>
|
</View>
|
||||||
) : null;
|
) : null;
|
||||||
|
|
||||||
|
|
@ -91,6 +93,11 @@ const styles = StyleSheet.create({
|
||||||
overviewContainer: {
|
overviewContainer: {
|
||||||
marginBottom: verticalScale(14),
|
marginBottom: verticalScale(14),
|
||||||
},
|
},
|
||||||
|
overviewText: {
|
||||||
|
fontSize: moderateScale(14),
|
||||||
|
lineHeight: moderateScale(22),
|
||||||
|
color: "#374151",
|
||||||
|
},
|
||||||
row: {
|
row: {
|
||||||
minHeight: moderateScale(68),
|
minHeight: moderateScale(68),
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { Ionicons } from "@expo/vector-icons";
|
||||||
import { moderateScale } from "react-native-size-matters";
|
import { moderateScale } from "react-native-size-matters";
|
||||||
|
|
||||||
import { Colors } from "@/theme";
|
import { Colors } from "@/theme";
|
||||||
import { asNumber, asString, formatPatternTitle } from "../helpers/value";
|
import { asNumber, asString } from "../helpers/value";
|
||||||
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
||||||
import type {
|
import type {
|
||||||
CollectionItemRendererProps,
|
CollectionItemRendererProps,
|
||||||
|
|
@ -20,8 +20,7 @@ export function ThreeBurnersCardRenderer({
|
||||||
onPress,
|
onPress,
|
||||||
}: CollectionItemRendererProps) {
|
}: CollectionItemRendererProps) {
|
||||||
const a = item.attributes;
|
const a = item.attributes;
|
||||||
const rawTitle = asString(a.name) || asString(a.title) || item.title;
|
const title = asString(a.name) || asString(a.title) || item.title;
|
||||||
const title = formatPatternTitle(rawTitle);
|
|
||||||
const sortOrder = asNumber(a.sort_order);
|
const sortOrder = asNumber(a.sort_order);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -234,7 +234,8 @@ const styles = StyleSheet.create({
|
||||||
lineHeight: 17,
|
lineHeight: 17,
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: "#597064",
|
color: "#597064",
|
||||||
letterSpacing: 0.15,
|
textTransform: "uppercase",
|
||||||
|
letterSpacing: 0.4,
|
||||||
},
|
},
|
||||||
pathway: {
|
pathway: {
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import { Colors } from "@/theme";
|
||||||
import type { DetailRendererProps } from "../../types/renderer.types";
|
import type { DetailRendererProps } from "../../types/renderer.types";
|
||||||
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
||||||
import { Hero } from "../shared/Hero";
|
import { Hero } from "../shared/Hero";
|
||||||
import { OverviewCard } from "../shared/OverviewCard";
|
|
||||||
import { Paragraphs } from "../shared/Paragraphs";
|
import { Paragraphs } from "../shared/Paragraphs";
|
||||||
import { SectionCard } from "../shared/SectionCard";
|
import { SectionCard } from "../shared/SectionCard";
|
||||||
import { asRecordArray, asString, asStringArray } from "../helpers/value";
|
import { asRecordArray, asString, asStringArray } from "../helpers/value";
|
||||||
|
|
@ -97,7 +96,20 @@ export function FiveElementsDetailRenderer({
|
||||||
|
|
||||||
{/* Overview Card (rendered only when overview/content exists in data) */}
|
{/* Overview Card (rendered only when overview/content exists in data) */}
|
||||||
{overviewParagraphs.length > 0 ? (
|
{overviewParagraphs.length > 0 ? (
|
||||||
<OverviewCard paragraphs={overviewParagraphs} />
|
<View style={styles.overviewCard}>
|
||||||
|
<View style={styles.overviewHeader}>
|
||||||
|
<Ionicons name="information-circle" size={20} color={Colors.primary} />
|
||||||
|
<Text style={styles.overviewTitle}>Overview</Text>
|
||||||
|
</View>
|
||||||
|
{overviewParagraphs.map((para, idx) => (
|
||||||
|
<Text
|
||||||
|
key={idx}
|
||||||
|
style={[styles.overviewText, idx > 0 && styles.paragraphSpacing]}
|
||||||
|
>
|
||||||
|
{para}
|
||||||
|
</Text>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{/* Dynamic Sequences List from data.sections */}
|
{/* Dynamic Sequences List from data.sections */}
|
||||||
|
|
@ -169,7 +181,20 @@ export function FiveElementsDetailRenderer({
|
||||||
|
|
||||||
{/* Overview Card (rendered only when overview/content exists in data) */}
|
{/* Overview Card (rendered only when overview/content exists in data) */}
|
||||||
{overviewParagraphs.length > 0 ? (
|
{overviewParagraphs.length > 0 ? (
|
||||||
<OverviewCard paragraphs={overviewParagraphs} />
|
<View style={styles.overviewCard}>
|
||||||
|
<View style={styles.overviewHeader}>
|
||||||
|
<Ionicons name="information-circle" size={20} color={Colors.primary} />
|
||||||
|
<Text style={styles.overviewTitle}>Overview</Text>
|
||||||
|
</View>
|
||||||
|
{overviewParagraphs.map((para, idx) => (
|
||||||
|
<Text
|
||||||
|
key={idx}
|
||||||
|
style={[styles.overviewText, idx > 0 && styles.paragraphSpacing]}
|
||||||
|
>
|
||||||
|
{para}
|
||||||
|
</Text>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{/* Collapsible Pattern Cards from data.sections */}
|
{/* Collapsible Pattern Cards from data.sections */}
|
||||||
|
|
@ -205,6 +230,32 @@ const styles = StyleSheet.create({
|
||||||
paddingBottom: verticalScale(40),
|
paddingBottom: verticalScale(40),
|
||||||
gap: verticalScale(14),
|
gap: verticalScale(14),
|
||||||
},
|
},
|
||||||
|
overviewCard: {
|
||||||
|
backgroundColor: "#FFFFFF",
|
||||||
|
borderRadius: moderateScale(16),
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: "#E2EAE5",
|
||||||
|
padding: moderateScale(16),
|
||||||
|
},
|
||||||
|
overviewHeader: {
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
marginBottom: verticalScale(8),
|
||||||
|
gap: moderateScale(8),
|
||||||
|
},
|
||||||
|
overviewTitle: {
|
||||||
|
fontSize: moderateScale(16),
|
||||||
|
fontWeight: "700",
|
||||||
|
color: Colors.textPrimary,
|
||||||
|
},
|
||||||
|
overviewText: {
|
||||||
|
fontSize: moderateScale(13),
|
||||||
|
lineHeight: verticalScale(19),
|
||||||
|
color: Colors.textSecondary,
|
||||||
|
},
|
||||||
|
paragraphSpacing: {
|
||||||
|
marginTop: verticalScale(10),
|
||||||
|
},
|
||||||
sequencesContainer: {
|
sequencesContainer: {
|
||||||
gap: verticalScale(10),
|
gap: verticalScale(10),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ import { BulletList } from "../shared/BulletList";
|
||||||
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
||||||
import { ContentValue } from "../shared/ContentValue";
|
import { ContentValue } from "../shared/ContentValue";
|
||||||
import { Hero } from "../shared/Hero";
|
import { Hero } from "../shared/Hero";
|
||||||
import { OverviewCard } from "../shared/OverviewCard";
|
|
||||||
import { Paragraphs } from "../shared/Paragraphs";
|
import { Paragraphs } from "../shared/Paragraphs";
|
||||||
import { SectionCard } from "../shared/SectionCard";
|
import { SectionCard } from "../shared/SectionCard";
|
||||||
|
|
||||||
|
|
@ -116,7 +115,15 @@ export function FourLevelsDetailRenderer({
|
||||||
<Hero title={title} />
|
<Hero title={title} />
|
||||||
|
|
||||||
{/* Direct Overview Card matching Four Levels 1st page */}
|
{/* Direct Overview Card matching Four Levels 1st page */}
|
||||||
{overview ? <OverviewCard text={overview} /> : null}
|
{overview ? (
|
||||||
|
<View style={styles.overviewCard}>
|
||||||
|
<View style={styles.overviewHeader}>
|
||||||
|
<Ionicons name="information-circle" size={20} color={Colors.primary} />
|
||||||
|
<Text style={styles.overviewTitle}>Overview</Text>
|
||||||
|
</View>
|
||||||
|
<Text style={styles.overviewText}>{overview}</Text>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
{/* Patterns List with numbered cards matching 1st page */}
|
{/* Patterns List with numbered cards matching 1st page */}
|
||||||
<View style={styles.patternsSection}>
|
<View style={styles.patternsSection}>
|
||||||
|
|
@ -281,6 +288,29 @@ const styles = StyleSheet.create({
|
||||||
paddingBottom: verticalScale(40),
|
paddingBottom: verticalScale(40),
|
||||||
gap: verticalScale(14),
|
gap: verticalScale(14),
|
||||||
},
|
},
|
||||||
|
overviewCard: {
|
||||||
|
backgroundColor: "#FFFFFF",
|
||||||
|
borderRadius: moderateScale(16),
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: "#E2EAE5",
|
||||||
|
padding: moderateScale(16),
|
||||||
|
},
|
||||||
|
overviewHeader: {
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
marginBottom: verticalScale(8),
|
||||||
|
gap: moderateScale(8),
|
||||||
|
},
|
||||||
|
overviewTitle: {
|
||||||
|
fontSize: moderateScale(16),
|
||||||
|
fontWeight: "700",
|
||||||
|
color: Colors.textPrimary,
|
||||||
|
},
|
||||||
|
overviewText: {
|
||||||
|
fontSize: moderateScale(13),
|
||||||
|
lineHeight: verticalScale(19),
|
||||||
|
color: Colors.textSecondary,
|
||||||
|
},
|
||||||
patternsSection: {
|
patternsSection: {
|
||||||
gap: verticalScale(10),
|
gap: verticalScale(10),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -278,6 +278,7 @@ const styles = StyleSheet.create({
|
||||||
lineHeight: 18,
|
lineHeight: 18,
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: "#536F61",
|
color: "#536F61",
|
||||||
letterSpacing: 0.15,
|
textTransform: "uppercase",
|
||||||
|
letterSpacing: 0.35,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,8 @@ const styles = StyleSheet.create({
|
||||||
fontSize: moderateScale(12),
|
fontSize: moderateScale(12),
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: Colors.textSecondary,
|
color: Colors.textSecondary,
|
||||||
letterSpacing: 0.2,
|
textTransform: "uppercase",
|
||||||
|
letterSpacing: 1,
|
||||||
marginBottom: verticalScale(12),
|
marginBottom: verticalScale(12),
|
||||||
marginLeft: moderateScale(4),
|
marginLeft: moderateScale(4),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import type { DetailRendererProps } from "../../types/renderer.types";
|
||||||
import { BackActionContext } from "../../context/BackActionContext";
|
import { BackActionContext } from "../../context/BackActionContext";
|
||||||
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
||||||
import { Hero } from "../shared/Hero";
|
import { Hero } from "../shared/Hero";
|
||||||
import { OverviewCard } from "../shared/OverviewCard";
|
|
||||||
import { SectionCard } from "../shared/SectionCard";
|
import { SectionCard } from "../shared/SectionCard";
|
||||||
import { BulletList } from "../shared/BulletList";
|
import { BulletList } from "../shared/BulletList";
|
||||||
import { Paragraphs } from "../shared/Paragraphs";
|
import { Paragraphs } from "../shared/Paragraphs";
|
||||||
|
|
@ -339,7 +338,15 @@ export function QiBloodDetailRenderer({
|
||||||
<Hero title={categoryTitle} />
|
<Hero title={categoryTitle} />
|
||||||
|
|
||||||
{/* Category Overview Card */}
|
{/* Category Overview Card */}
|
||||||
{categoryOverview ? <OverviewCard text={categoryOverview} /> : null}
|
{categoryOverview ? (
|
||||||
|
<View style={styles.overviewCard}>
|
||||||
|
<View style={styles.overviewHeader}>
|
||||||
|
<Ionicons name="information-circle" size={20} color={Colors.primary} />
|
||||||
|
<Text style={styles.overviewTitle}>Overview</Text>
|
||||||
|
</View>
|
||||||
|
<Text style={styles.overviewText}>{categoryOverview}</Text>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
{/* Numbered Patterns List */}
|
{/* Numbered Patterns List */}
|
||||||
{rootPatterns.length > 0 ? (
|
{rootPatterns.length > 0 ? (
|
||||||
|
|
@ -383,6 +390,29 @@ const styles = StyleSheet.create({
|
||||||
paddingBottom: verticalScale(40),
|
paddingBottom: verticalScale(40),
|
||||||
gap: verticalScale(14),
|
gap: verticalScale(14),
|
||||||
},
|
},
|
||||||
|
overviewCard: {
|
||||||
|
backgroundColor: "#FFFFFF",
|
||||||
|
borderRadius: moderateScale(16),
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: "#E2EAE5",
|
||||||
|
padding: moderateScale(18),
|
||||||
|
},
|
||||||
|
overviewHeader: {
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
marginBottom: verticalScale(10),
|
||||||
|
gap: moderateScale(8),
|
||||||
|
},
|
||||||
|
overviewTitle: {
|
||||||
|
fontSize: moderateScale(16),
|
||||||
|
fontWeight: "700",
|
||||||
|
color: Colors.textPrimary,
|
||||||
|
},
|
||||||
|
overviewText: {
|
||||||
|
fontSize: moderateScale(14),
|
||||||
|
lineHeight: moderateScale(22),
|
||||||
|
color: Colors.textSecondary,
|
||||||
|
},
|
||||||
patternsContainer: {
|
patternsContainer: {
|
||||||
gap: verticalScale(10),
|
gap: verticalScale(10),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,7 @@ import React, { useMemo } from "react";
|
||||||
import { ScrollView, StyleSheet } from "react-native";
|
import { ScrollView, StyleSheet } from "react-native";
|
||||||
|
|
||||||
import type { DetailRendererProps } from "../../types/renderer.types";
|
import type { DetailRendererProps } from "../../types/renderer.types";
|
||||||
import {
|
import { asString, humanizeKey } from "../helpers/value";
|
||||||
asString,
|
|
||||||
buildDefinitionLabelMap,
|
|
||||||
humanizeKey,
|
|
||||||
resolveAttributeLabel,
|
|
||||||
} from "../helpers/value";
|
|
||||||
import {
|
import {
|
||||||
findAttributePresentationRule,
|
findAttributePresentationRule,
|
||||||
isEmptyValue,
|
isEmptyValue,
|
||||||
|
|
@ -46,7 +41,9 @@ export function SixStagesDetailRenderer({
|
||||||
const title = humanizeKey(rawTitle);
|
const title = humanizeKey(rawTitle);
|
||||||
|
|
||||||
const orderedSections = useMemo(() => {
|
const orderedSections = useMemo(() => {
|
||||||
const definitionByLabel = buildDefinitionLabelMap(definitions);
|
const definitionByLabel = new Map(
|
||||||
|
(definitions ?? []).map((d) => [d.code, d.label]),
|
||||||
|
);
|
||||||
|
|
||||||
return Object.entries(data)
|
return Object.entries(data)
|
||||||
.filter(
|
.filter(
|
||||||
|
|
@ -58,7 +55,8 @@ export function SixStagesDetailRenderer({
|
||||||
.map(([key, value]) => {
|
.map(([key, value]) => {
|
||||||
const rule = findAttributePresentationRule(key, presentationAttributes);
|
const rule = findAttributePresentationRule(key, presentationAttributes);
|
||||||
const order = presentationDisplayOrder(rule);
|
const order = presentationDisplayOrder(rule);
|
||||||
const label = resolveAttributeLabel(key, definitionByLabel);
|
const rawLabel = definitionByLabel.get(key) || key;
|
||||||
|
const label = humanizeKey(rawLabel);
|
||||||
return { key, value, order, label };
|
return { key, value, order, label };
|
||||||
})
|
})
|
||||||
.sort((a, b) => a.order - b.order || a.label.localeCompare(b.label));
|
.sort((a, b) => a.order - b.order || a.label.localeCompare(b.label));
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,7 @@ import React, { useMemo } from "react";
|
||||||
import { ScrollView, StyleSheet } from "react-native";
|
import { ScrollView, StyleSheet } from "react-native";
|
||||||
|
|
||||||
import type { DetailRendererProps } from "../../types/renderer.types";
|
import type { DetailRendererProps } from "../../types/renderer.types";
|
||||||
import {
|
import { asString, humanizeKey } from "../helpers/value";
|
||||||
asString,
|
|
||||||
buildDefinitionLabelMap,
|
|
||||||
humanizeKey,
|
|
||||||
resolveAttributeLabel,
|
|
||||||
} from "../helpers/value";
|
|
||||||
import {
|
import {
|
||||||
findAttributePresentationRule,
|
findAttributePresentationRule,
|
||||||
isEmptyValue,
|
isEmptyValue,
|
||||||
|
|
@ -41,7 +36,9 @@ export function TcmPatternDetailRenderer({
|
||||||
const title = humanizeKey(rawTitle);
|
const title = humanizeKey(rawTitle);
|
||||||
|
|
||||||
const orderedSections = useMemo(() => {
|
const orderedSections = useMemo(() => {
|
||||||
const definitionByLabel = buildDefinitionLabelMap(definitions);
|
const definitionByLabel = new Map(
|
||||||
|
(definitions ?? []).map((d) => [d.code, d.label]),
|
||||||
|
);
|
||||||
|
|
||||||
return Object.entries(data)
|
return Object.entries(data)
|
||||||
.filter(
|
.filter(
|
||||||
|
|
@ -52,7 +49,8 @@ export function TcmPatternDetailRenderer({
|
||||||
.map(([key, value]) => {
|
.map(([key, value]) => {
|
||||||
const rule = findAttributePresentationRule(key, presentationAttributes);
|
const rule = findAttributePresentationRule(key, presentationAttributes);
|
||||||
const order = presentationDisplayOrder(rule);
|
const order = presentationDisplayOrder(rule);
|
||||||
const label = resolveAttributeLabel(key, definitionByLabel);
|
const rawLabel = definitionByLabel.get(key) || key;
|
||||||
|
const label = humanizeKey(rawLabel);
|
||||||
return { key, value, order, label };
|
return { key, value, order, label };
|
||||||
})
|
})
|
||||||
.sort((a, b) => a.order - b.order || a.label.localeCompare(b.label));
|
.sort((a, b) => a.order - b.order || a.label.localeCompare(b.label));
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,11 @@ import { Colors } from "@/theme";
|
||||||
import type { DetailRendererProps } from "../../types/renderer.types";
|
import type { DetailRendererProps } from "../../types/renderer.types";
|
||||||
import { BackActionContext } from "../../context/BackActionContext";
|
import { BackActionContext } from "../../context/BackActionContext";
|
||||||
import { Hero } from "../shared/Hero";
|
import { Hero } from "../shared/Hero";
|
||||||
import { OverviewCard } from "../shared/OverviewCard";
|
|
||||||
import { SectionCard } from "../shared/SectionCard";
|
import { SectionCard } from "../shared/SectionCard";
|
||||||
import { Paragraphs } from "../shared/Paragraphs";
|
import { Paragraphs } from "../shared/Paragraphs";
|
||||||
import { BulletList } from "../shared/BulletList";
|
import { BulletList } from "../shared/BulletList";
|
||||||
import { ContentValue } from "../shared/ContentValue";
|
import { ContentValue } from "../shared/ContentValue";
|
||||||
import { asString, asStringArray, formatPatternTitle } from "../helpers/value";
|
import { asString, asStringArray } from "../helpers/value";
|
||||||
import { useContentSearchInfiniteQuery } from "../../hooks/use-content-search-infinite-query";
|
import { useContentSearchInfiniteQuery } from "../../hooks/use-content-search-infinite-query";
|
||||||
|
|
||||||
interface PatternData {
|
interface PatternData {
|
||||||
|
|
@ -73,7 +72,7 @@ const BURNER_CONFIGS: Array<{ key: string; title: string }> = [
|
||||||
// Embedded fallback patterns for guaranteed zero-latency / offline rendering
|
// Embedded fallback patterns for guaranteed zero-latency / offline rendering
|
||||||
const FALLBACK_PATTERNS: Record<string, PatternData> = {
|
const FALLBACK_PATTERNS: Record<string, PatternData> = {
|
||||||
"wind_heat_in_the_lungs_defensive_qi_portion": {
|
"wind_heat_in_the_lungs_defensive_qi_portion": {
|
||||||
name: "Wind-Heat in the Lung's Defensive Qi portion",
|
name: "Wind-Heat in the Lungs’ Defensive Qi portion",
|
||||||
clinicalManifestation:
|
clinicalManifestation:
|
||||||
"Fever, aversion to cold, headache, sore throat, slight sweating, runny nose with yellow discharge, swollen tonsils, body aches, slight thirst",
|
"Fever, aversion to cold, headache, sore throat, slight sweating, runny nose with yellow discharge, swollen tonsils, body aches, slight thirst",
|
||||||
pathology:
|
pathology:
|
||||||
|
|
@ -155,9 +154,7 @@ function extractBurnerList(data: Record<string, unknown>, burnerKey: string): st
|
||||||
for (const [k, v] of Object.entries(data)) {
|
for (const [k, v] of Object.entries(data)) {
|
||||||
const normK = normalizeKey(k);
|
const normK = normalizeKey(k);
|
||||||
if (normK === normTarget && Array.isArray(v)) {
|
if (normK === normTarget && Array.isArray(v)) {
|
||||||
return v
|
return v.map((item) => asString(item).trim()).filter((item) => item.length > 0);
|
||||||
.map((item) => formatPatternTitle(asString(item).trim()))
|
|
||||||
.filter((item) => item.length > 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
|
|
@ -230,9 +227,8 @@ export function ThreeBurnersDetailRenderer({
|
||||||
const items = patternsQuery.data?.pages?.flatMap((p) => p.items) ?? [];
|
const items = patternsQuery.data?.pages?.flatMap((p) => p.items) ?? [];
|
||||||
for (const it of items) {
|
for (const it of items) {
|
||||||
const a = it.attributes as Record<string, unknown>;
|
const a = it.attributes as Record<string, unknown>;
|
||||||
const rawName = asString(a.name) || it.title;
|
const name = asString(a.name) || it.title;
|
||||||
if (!rawName) continue;
|
if (!name) continue;
|
||||||
const name = formatPatternTitle(rawName);
|
|
||||||
|
|
||||||
const clinicalRaw =
|
const clinicalRaw =
|
||||||
a["clinical menifestation"] ??
|
a["clinical menifestation"] ??
|
||||||
|
|
@ -288,8 +284,7 @@ export function ThreeBurnersDetailRenderer({
|
||||||
|
|
||||||
const activePatternData: PatternData | null = useMemo(() => {
|
const activePatternData: PatternData | null = useMemo(() => {
|
||||||
if (isDirectLeafPattern) {
|
if (isDirectLeafPattern) {
|
||||||
const rawName = asString(data.name) || content.title || "Three Burners Pattern";
|
const name = asString(data.name) || content.title || "Three Burners Pattern";
|
||||||
const name = formatPatternTitle(rawName);
|
|
||||||
const clinicalRaw =
|
const clinicalRaw =
|
||||||
data["clinical menifestation"] ??
|
data["clinical menifestation"] ??
|
||||||
data["clinical manifestation"] ??
|
data["clinical manifestation"] ??
|
||||||
|
|
@ -314,16 +309,11 @@ export function ThreeBurnersDetailRenderer({
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!selectedPatternName) return null;
|
if (!selectedPatternName) return null;
|
||||||
const found = patternMap.get(normalizeKey(selectedPatternName));
|
return (
|
||||||
if (found) {
|
patternMap.get(normalizeKey(selectedPatternName)) || {
|
||||||
return {
|
name: selectedPatternName,
|
||||||
...found,
|
|
||||||
name: formatPatternTitle(found.name),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
return {
|
);
|
||||||
name: formatPatternTitle(selectedPatternName),
|
|
||||||
};
|
|
||||||
}, [isDirectLeafPattern, data, content.title, selectedPatternName, patternMap]);
|
}, [isDirectLeafPattern, data, content.title, selectedPatternName, patternMap]);
|
||||||
|
|
||||||
// Connect drilldown navigation to the top-header back button
|
// Connect drilldown navigation to the top-header back button
|
||||||
|
|
@ -424,13 +414,11 @@ export function ThreeBurnersDetailRenderer({
|
||||||
|
|
||||||
<View style={styles.patternsContainer}>
|
<View style={styles.patternsContainer}>
|
||||||
<Text style={styles.sectionHeading}>Patterns</Text>
|
<Text style={styles.sectionHeading}>Patterns</Text>
|
||||||
{selectedBurner.patterns.map((patternName, idx) => {
|
{selectedBurner.patterns.map((patternName, idx) => (
|
||||||
const formattedTitle = formatPatternTitle(patternName);
|
|
||||||
return (
|
|
||||||
<Pressable
|
<Pressable
|
||||||
key={patternName}
|
key={patternName}
|
||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
accessibilityLabel={`Open ${formattedTitle}`}
|
accessibilityLabel={`Open ${patternName}`}
|
||||||
onPress={() => setSelectedPatternName(patternName)}
|
onPress={() => setSelectedPatternName(patternName)}
|
||||||
style={({ pressed }) => [styles.patternRow, pressed && styles.pressed]}
|
style={({ pressed }) => [styles.patternRow, pressed && styles.pressed]}
|
||||||
>
|
>
|
||||||
|
|
@ -439,13 +427,12 @@ export function ThreeBurnersDetailRenderer({
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<View style={styles.patternTitleContainer}>
|
<View style={styles.patternTitleContainer}>
|
||||||
<Text style={styles.patternTitle}>{formattedTitle}</Text>
|
<Text style={styles.patternTitle}>{patternName}</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<Ionicons name="chevron-forward" size={20} color="#9CA3AF" />
|
<Ionicons name="chevron-forward" size={20} color="#9CA3AF" />
|
||||||
</Pressable>
|
</Pressable>
|
||||||
);
|
))}
|
||||||
})}
|
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
@ -470,7 +457,15 @@ export function ThreeBurnersDetailRenderer({
|
||||||
<Hero title="Three Burners" />
|
<Hero title="Three Burners" />
|
||||||
|
|
||||||
{/* Overview Card */}
|
{/* Overview Card */}
|
||||||
{overviewText ? <OverviewCard text={overviewText} /> : null}
|
{overviewText ? (
|
||||||
|
<View style={styles.overviewCard}>
|
||||||
|
<View style={styles.overviewHeader}>
|
||||||
|
<Ionicons name="information-circle" size={20} color={Colors.primary} />
|
||||||
|
<Text style={styles.overviewTitle}>Overview</Text>
|
||||||
|
</View>
|
||||||
|
<Text style={styles.overviewText}>{overviewText}</Text>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
{/* Burner Categories (1. Upper Burner, 2. Middle Burner, 3. Lower Burner) */}
|
{/* Burner Categories (1. Upper Burner, 2. Middle Burner, 3. Lower Burner) */}
|
||||||
<View style={styles.patternsContainer}>
|
<View style={styles.patternsContainer}>
|
||||||
|
|
@ -510,6 +505,29 @@ const styles = StyleSheet.create({
|
||||||
paddingBottom: verticalScale(40),
|
paddingBottom: verticalScale(40),
|
||||||
gap: verticalScale(14),
|
gap: verticalScale(14),
|
||||||
},
|
},
|
||||||
|
overviewCard: {
|
||||||
|
backgroundColor: "#FFFFFF",
|
||||||
|
borderRadius: moderateScale(16),
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: "#E2EAE5",
|
||||||
|
padding: moderateScale(16),
|
||||||
|
},
|
||||||
|
overviewHeader: {
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
marginBottom: verticalScale(8),
|
||||||
|
gap: moderateScale(8),
|
||||||
|
},
|
||||||
|
overviewTitle: {
|
||||||
|
fontSize: moderateScale(16),
|
||||||
|
fontWeight: "700",
|
||||||
|
color: Colors.textPrimary,
|
||||||
|
},
|
||||||
|
overviewText: {
|
||||||
|
fontSize: moderateScale(13),
|
||||||
|
lineHeight: verticalScale(20),
|
||||||
|
color: Colors.textSecondary,
|
||||||
|
},
|
||||||
patternsContainer: {
|
patternsContainer: {
|
||||||
gap: verticalScale(10),
|
gap: verticalScale(10),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import { Colors } from "@/theme";
|
||||||
import type { DetailRendererProps } from "../../types/renderer.types";
|
import type { DetailRendererProps } from "../../types/renderer.types";
|
||||||
import { BackActionContext } from "../../context/BackActionContext";
|
import { BackActionContext } from "../../context/BackActionContext";
|
||||||
import { Hero } from "../shared/Hero";
|
import { Hero } from "../shared/Hero";
|
||||||
import { OverviewCard } from "../shared/OverviewCard";
|
|
||||||
import { SectionCard } from "../shared/SectionCard";
|
import { SectionCard } from "../shared/SectionCard";
|
||||||
import { Paragraphs } from "../shared/Paragraphs";
|
import { Paragraphs } from "../shared/Paragraphs";
|
||||||
import { BulletList } from "../shared/BulletList";
|
import { BulletList } from "../shared/BulletList";
|
||||||
|
|
@ -614,7 +613,15 @@ export function TwelveChannelsDetailRenderer({
|
||||||
<Hero title="Twelve Channels" />
|
<Hero title="Twelve Channels" />
|
||||||
|
|
||||||
{/* 1. Overview Card */}
|
{/* 1. Overview Card */}
|
||||||
{overviewText ? <OverviewCard text={overviewText} /> : null}
|
{overviewText ? (
|
||||||
|
<View style={styles.overviewCard}>
|
||||||
|
<View style={styles.overviewHeader}>
|
||||||
|
<Ionicons name="information-circle" size={20} color={Colors.primary} />
|
||||||
|
<Text style={styles.overviewTitle}>Overview</Text>
|
||||||
|
</View>
|
||||||
|
<Text style={styles.overviewText}>{overviewText}</Text>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
{/* 2. Organ vs Channel Card */}
|
{/* 2. Organ vs Channel Card */}
|
||||||
{organVsChannelText ? (
|
{organVsChannelText ? (
|
||||||
|
|
@ -749,6 +756,29 @@ const styles = StyleSheet.create({
|
||||||
paddingBottom: verticalScale(40),
|
paddingBottom: verticalScale(40),
|
||||||
gap: verticalScale(14),
|
gap: verticalScale(14),
|
||||||
},
|
},
|
||||||
|
overviewCard: {
|
||||||
|
backgroundColor: "#F0FDF4",
|
||||||
|
borderRadius: moderateScale(14),
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: "#DCFCE7",
|
||||||
|
padding: moderateScale(16),
|
||||||
|
},
|
||||||
|
overviewHeader: {
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
marginBottom: moderateScale(8),
|
||||||
|
gap: moderateScale(6),
|
||||||
|
},
|
||||||
|
overviewTitle: {
|
||||||
|
fontSize: moderateScale(15),
|
||||||
|
fontWeight: "700",
|
||||||
|
color: Colors.primaryDark,
|
||||||
|
},
|
||||||
|
overviewText: {
|
||||||
|
fontSize: moderateScale(14),
|
||||||
|
color: Colors.textSecondary,
|
||||||
|
lineHeight: moderateScale(21),
|
||||||
|
},
|
||||||
infoCard: {
|
infoCard: {
|
||||||
backgroundColor: "#FFFFFF",
|
backgroundColor: "#FFFFFF",
|
||||||
borderRadius: moderateScale(14),
|
borderRadius: moderateScale(14),
|
||||||
|
|
|
||||||
|
|
@ -1,482 +1,8 @@
|
||||||
import React, { useMemo, useState } from "react";
|
import React from "react";
|
||||||
import {
|
import { ScrollView } from "react-native";
|
||||||
LayoutAnimation,
|
|
||||||
Platform,
|
|
||||||
Pressable,
|
|
||||||
ScrollView,
|
|
||||||
StyleSheet,
|
|
||||||
Text,
|
|
||||||
UIManager,
|
|
||||||
View,
|
|
||||||
} from "react-native";
|
|
||||||
import { Ionicons } from "@expo/vector-icons";
|
|
||||||
import { useRouter } from "expo-router";
|
|
||||||
import { moderateScale, verticalScale } from "react-native-size-matters";
|
|
||||||
|
|
||||||
import { Colors, Radius } from "@/theme";
|
|
||||||
import { useSettingsStore } from "@/store/settings.store";
|
|
||||||
import type { DetailRendererProps } from "../../types/renderer.types";
|
import type { DetailRendererProps } from "../../types/renderer.types";
|
||||||
import { useModuleTemplateContentDetailsQuery } from "../../hooks/use-content-queries";
|
|
||||||
import {
|
|
||||||
buildContentReferenceRoute,
|
|
||||||
parseNavigableContentReference,
|
|
||||||
} from "../../utils/content-reference";
|
|
||||||
import {
|
|
||||||
asRecord,
|
|
||||||
asRecordArray,
|
|
||||||
asString,
|
|
||||||
asStringArray,
|
|
||||||
} from "../helpers/value";
|
|
||||||
import { BulletList } from "../shared/BulletList";
|
|
||||||
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
||||||
|
import { asString } from "../helpers/value";
|
||||||
import { Hero } from "../shared/Hero";
|
import { Hero } from "../shared/Hero";
|
||||||
import { OverviewCard } from "../shared/OverviewCard";
|
import { DescriptionList, Images, ObjectArrayCards, ObjectArrayTable, ObjectCard, PointCodes, Strings } from "./categoryParts";
|
||||||
import { Images } from "./categoryParts";
|
export function YuanSourceDetailRenderer({content,data,definitions,presentationAttributes}:DetailRendererProps){ return <ScrollView contentContainerStyle={{paddingHorizontal:18,paddingTop:16,paddingBottom:40,gap:14}}><Hero title={asString(data.title)||asString(data.name)||content.title}/><Images data={data}/><PointCodes data={data}/><ObjectArrayTable title="Source Points" value={data.source_point} columns={["meridian","point"]}/><Strings title="Key Clinical Features" value={data.key_clinical_feature}/><Strings title="Yin vs Yang" value={data.yin_vs_yang}/><Strings title="Functions" value={data.functions}/><Strings title="Diagnostic Utility" value={data.diagnostic_utility}/><ContentLinkAttributeSections data={data} definitions={definitions} presentationAttributes={presentationAttributes}/></ScrollView>; }
|
||||||
|
|
||||||
if (Platform.OS === "android" && UIManager.setLayoutAnimationEnabledExperimental) {
|
|
||||||
UIManager.setLayoutAnimationEnabledExperimental(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
interface PointItemProps {
|
|
||||||
key?: React.Key;
|
|
||||||
item: Record<string, unknown>;
|
|
||||||
defaultExpanded: boolean;
|
|
||||||
moduleCode: string;
|
|
||||||
pointsCatalogMap?: Map<string, { contentId: string; title: string }>;
|
|
||||||
}
|
|
||||||
|
|
||||||
function sanitizeMeridianHeading(meridian: string, chineseName: string): string {
|
|
||||||
const cleanChinese = chineseName.replace(/^\((.*)\)$/, "$1").trim();
|
|
||||||
|
|
||||||
// Strip meridian abbreviation codes or point codes in parentheses,
|
|
||||||
// e.g. (ST), (LU-9), (LI), (LV), (LR), (PC), (GB), (HT), etc.
|
|
||||||
const cleanedMeridian = meridian
|
|
||||||
.replace(/\s*\(\s*[A-Z]{1,4}(?:[\s\-_]*\d+)?\s*\)\s*/g, " ")
|
|
||||||
.replace(/\s+/g, " ")
|
|
||||||
.trim();
|
|
||||||
|
|
||||||
if (cleanedMeridian && cleanChinese) {
|
|
||||||
if (cleanedMeridian.toLowerCase().includes(cleanChinese.toLowerCase())) {
|
|
||||||
return cleanedMeridian;
|
|
||||||
}
|
|
||||||
return `${cleanedMeridian} (${cleanChinese})`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return cleanedMeridian || cleanChinese || "Point";
|
|
||||||
}
|
|
||||||
|
|
||||||
function PointAccordionCard({
|
|
||||||
item,
|
|
||||||
defaultExpanded,
|
|
||||||
moduleCode,
|
|
||||||
pointsCatalogMap,
|
|
||||||
}: PointItemProps) {
|
|
||||||
const router = useRouter();
|
|
||||||
const [expanded, setExpanded] = useState(defaultExpanded);
|
|
||||||
|
|
||||||
const meridian = asString(item.meridian).trim();
|
|
||||||
const chineseName = asString(item.chinese_name).trim();
|
|
||||||
const element = asString(item.element).trim();
|
|
||||||
const caution = asString(item.caution).trim();
|
|
||||||
const cautionList = asStringArray(item.caution);
|
|
||||||
|
|
||||||
const actions = asStringArray(item.actions);
|
|
||||||
const indications = asStringArray(item.indications);
|
|
||||||
|
|
||||||
// Format header title: e.g. "Stomach (Chongyang)", "Lung (Taiyuan)"
|
|
||||||
const title = useMemo(() => {
|
|
||||||
return sanitizeMeridianHeading(meridian, chineseName);
|
|
||||||
}, [meridian, chineseName]);
|
|
||||||
|
|
||||||
// Resolve point reference for linkable button
|
|
||||||
const rawPoint = asRecord(item.point);
|
|
||||||
const directRef = parseNavigableContentReference(item.point);
|
|
||||||
|
|
||||||
// Extract candidate point codes/labels: e.g. "LU 9", "LU-9"
|
|
||||||
const pointLabel =
|
|
||||||
directRef?.label?.trim() ||
|
|
||||||
asString(rawPoint.label).trim() ||
|
|
||||||
(rawPoint.target && typeof rawPoint.target === "object"
|
|
||||||
? asString((rawPoint.target as Record<string, unknown>).source_code).trim()
|
|
||||||
: "") ||
|
|
||||||
"";
|
|
||||||
|
|
||||||
// Construct button display label: e.g. "LU-9 (Taiyuan)" or "LU 9 (Taiyuan)"
|
|
||||||
const pointButtonLabel = useMemo(() => {
|
|
||||||
const baseCode = pointLabel || "Point Details";
|
|
||||||
if (chineseName && !baseCode.toLowerCase().includes(chineseName.toLowerCase())) {
|
|
||||||
return `${baseCode} (${chineseName})`;
|
|
||||||
}
|
|
||||||
return baseCode;
|
|
||||||
}, [pointLabel, chineseName]);
|
|
||||||
|
|
||||||
// Resolve navigation destination
|
|
||||||
const navigateToPoint = () => {
|
|
||||||
if (directRef) {
|
|
||||||
router.push(buildContentReferenceRoute(directRef) as never);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rawPoint.target && typeof rawPoint.target === "object") {
|
|
||||||
const target = rawPoint.target as Record<string, unknown>;
|
|
||||||
const targetModule = asString(target.module_code).trim() || moduleCode || "m0001";
|
|
||||||
const targetTemplate = asString(target.template_code).trim() || "m0001_ct0003";
|
|
||||||
const contentId = asString(target.content_id).trim();
|
|
||||||
const sourceCode = asString(target.source_code).trim();
|
|
||||||
|
|
||||||
if (contentId) {
|
|
||||||
router.push(
|
|
||||||
`/modules/${encodeURIComponent(targetModule)}/${encodeURIComponent(targetTemplate)}/${encodeURIComponent(contentId)}` as never,
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback: match by catalog map (from m0001_ct0003) using sourceCode or label
|
|
||||||
if (pointsCatalogMap && sourceCode) {
|
|
||||||
const found =
|
|
||||||
pointsCatalogMap.get(sourceCode.toLowerCase()) ||
|
|
||||||
pointsCatalogMap.get(sourceCode.replace(/[- ]/g, "").toLowerCase());
|
|
||||||
if (found) {
|
|
||||||
router.push(
|
|
||||||
`/modules/${encodeURIComponent(targetModule)}/${encodeURIComponent(targetTemplate)}/${encodeURIComponent(found.contentId)}` as never,
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Secondary fallback matching by pointLabel in catalog
|
|
||||||
if (pointsCatalogMap && pointLabel) {
|
|
||||||
const found =
|
|
||||||
pointsCatalogMap.get(pointLabel.toLowerCase()) ||
|
|
||||||
pointsCatalogMap.get(pointLabel.replace(/[- ]/g, "").toLowerCase());
|
|
||||||
if (found) {
|
|
||||||
router.push(
|
|
||||||
`/modules/${encodeURIComponent(moduleCode || "m0001")}/m0001_ct0003/${encodeURIComponent(found.contentId)}` as never,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const toggle = () => {
|
|
||||||
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
|
|
||||||
setExpanded((prev) => !prev);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<View style={styles.card}>
|
|
||||||
{/* Accordion Header */}
|
|
||||||
<Pressable
|
|
||||||
accessibilityRole="button"
|
|
||||||
accessibilityState={{ expanded }}
|
|
||||||
accessibilityLabel={`${expanded ? "Collapse" : "Expand"} ${title}`}
|
|
||||||
onPress={toggle}
|
|
||||||
style={({ pressed }) => [
|
|
||||||
styles.cardHeader,
|
|
||||||
expanded && styles.cardHeaderExpanded,
|
|
||||||
pressed && styles.pressed,
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<View style={styles.headerLeft}>
|
|
||||||
<View style={styles.headerAccent} />
|
|
||||||
<Text style={styles.headerTitle} numberOfLines={2}>
|
|
||||||
{title}
|
|
||||||
</Text>
|
|
||||||
</View>
|
|
||||||
|
|
||||||
<View style={styles.headerRight}>
|
|
||||||
{element ? (
|
|
||||||
<View style={styles.elementBadge}>
|
|
||||||
<Text style={styles.elementBadgeText}>{element}</Text>
|
|
||||||
</View>
|
|
||||||
) : null}
|
|
||||||
<View style={styles.chevron}>
|
|
||||||
<Ionicons
|
|
||||||
name={expanded ? "chevron-up" : "chevron-down"}
|
|
||||||
size={moderateScale(16)}
|
|
||||||
color={Colors.primary}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
</Pressable>
|
|
||||||
|
|
||||||
{/* Accordion Body (Expanded State) */}
|
|
||||||
{expanded ? (
|
|
||||||
<View style={styles.cardBody}>
|
|
||||||
{/* Actions */}
|
|
||||||
{actions.length > 0 ? (
|
|
||||||
<View style={styles.sectionRow}>
|
|
||||||
<Text style={styles.sectionLabel}>ACTIONS</Text>
|
|
||||||
{actions.length === 1 ? (
|
|
||||||
<Text style={styles.sectionValue}>{actions[0]}</Text>
|
|
||||||
) : (
|
|
||||||
<BulletList items={actions} />
|
|
||||||
)}
|
|
||||||
</View>
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
{/* Indications */}
|
|
||||||
{indications.length > 0 ? (
|
|
||||||
<View style={styles.sectionRow}>
|
|
||||||
<Text style={styles.sectionLabel}>INDICATIONS</Text>
|
|
||||||
<BulletList items={indications} />
|
|
||||||
</View>
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
{/* Caution (same UI as Actions and Indications) */}
|
|
||||||
{caution ? (
|
|
||||||
<View style={styles.sectionRow}>
|
|
||||||
<Text style={styles.sectionLabel}>CAUTION</Text>
|
|
||||||
{cautionList.length > 1 ? (
|
|
||||||
<BulletList items={cautionList} />
|
|
||||||
) : (
|
|
||||||
<Text style={styles.sectionValue}>{caution}</Text>
|
|
||||||
)}
|
|
||||||
</View>
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
{/* Linkable Point Button (matching standard ReferenceChipList styling) */}
|
|
||||||
{pointLabel ? (
|
|
||||||
<Pressable
|
|
||||||
accessibilityRole="link"
|
|
||||||
accessibilityLabel={`View point ${pointButtonLabel}`}
|
|
||||||
onPress={navigateToPoint}
|
|
||||||
style={({ pressed }) => [
|
|
||||||
styles.pointLinkButton,
|
|
||||||
pressed && styles.pressed,
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Text style={styles.pointLinkLabel}>{pointButtonLabel}</Text>
|
|
||||||
<Ionicons
|
|
||||||
name="chevron-forward"
|
|
||||||
size={moderateScale(14)}
|
|
||||||
color={Colors.primaryDark}
|
|
||||||
/>
|
|
||||||
</Pressable>
|
|
||||||
) : null}
|
|
||||||
</View>
|
|
||||||
) : null}
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function YuanSourceDetailRenderer({
|
|
||||||
moduleCode = "m0001",
|
|
||||||
content,
|
|
||||||
data,
|
|
||||||
definitions,
|
|
||||||
presentationAttributes,
|
|
||||||
}: DetailRendererProps) {
|
|
||||||
const accordionDefaultExpanded = useSettingsStore(
|
|
||||||
(state) => state.accordionDefaultExpanded,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Fetch points from m0001_ct0003 for robust ID navigation fallback
|
|
||||||
const { data: pointsCatalog } = useModuleTemplateContentDetailsQuery({
|
|
||||||
module_code: moduleCode || "m0001",
|
|
||||||
template_code: "m0001_ct0003",
|
|
||||||
});
|
|
||||||
|
|
||||||
const pointsCatalogMap = useMemo(() => {
|
|
||||||
const map = new Map<string, { contentId: string; title: string }>();
|
|
||||||
if (pointsCatalog?.items) {
|
|
||||||
for (const item of pointsCatalog.items) {
|
|
||||||
const id = item.content.id;
|
|
||||||
const title = item.content.title;
|
|
||||||
const code = asString(item.data.code).trim().toLowerCase();
|
|
||||||
const name = asString(item.data.name).trim().toLowerCase();
|
|
||||||
if (code) {
|
|
||||||
map.set(code, { contentId: id, title });
|
|
||||||
map.set(code.replace(/[- ]/g, ""), { contentId: id, title });
|
|
||||||
}
|
|
||||||
if (name) {
|
|
||||||
map.set(name, { contentId: id, title });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}, [pointsCatalog]);
|
|
||||||
|
|
||||||
const rawTitle =
|
|
||||||
asString(data.title) || asString(data.name) || content.title || "Yuan Source";
|
|
||||||
const altNames = asStringArray(data.alt_name);
|
|
||||||
const descriptionParagraphs = asStringArray(data.description);
|
|
||||||
const points = asRecordArray(data.points);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ScrollView
|
|
||||||
contentContainerStyle={styles.container}
|
|
||||||
showsVerticalScrollIndicator={false}
|
|
||||||
>
|
|
||||||
{/* Screen Title & Subtitle */}
|
|
||||||
<Hero
|
|
||||||
title={rawTitle}
|
|
||||||
subtitle={altNames.length > 0 ? altNames.join(" · ") : undefined}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Visual images (if any assigned) */}
|
|
||||||
<Images data={data} />
|
|
||||||
|
|
||||||
{/* Overview Section */}
|
|
||||||
{descriptionParagraphs.length > 0 ? (
|
|
||||||
<OverviewCard
|
|
||||||
title="Overview"
|
|
||||||
paragraphs={descriptionParagraphs}
|
|
||||||
/>
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
{/* Points Accordion List */}
|
|
||||||
{points.length > 0 ? (
|
|
||||||
<View style={styles.pointsList}>
|
|
||||||
{points.map((pointItem, index) => (
|
|
||||||
<PointAccordionCard
|
|
||||||
key={index}
|
|
||||||
item={pointItem}
|
|
||||||
defaultExpanded={accordionDefaultExpanded}
|
|
||||||
moduleCode={moduleCode}
|
|
||||||
pointsCatalogMap={pointsCatalogMap}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</View>
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
{/* Generic content link attributes (excluding points already rendered above) */}
|
|
||||||
<ContentLinkAttributeSections
|
|
||||||
data={data}
|
|
||||||
definitions={definitions}
|
|
||||||
presentationAttributes={presentationAttributes}
|
|
||||||
excludeAttributeKeys={["points", "m0001_ct0009.points"]}
|
|
||||||
/>
|
|
||||||
</ScrollView>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
container: {
|
|
||||||
paddingHorizontal: moderateScale(16),
|
|
||||||
paddingTop: verticalScale(14),
|
|
||||||
paddingBottom: verticalScale(40),
|
|
||||||
gap: verticalScale(14),
|
|
||||||
},
|
|
||||||
pointsList: {
|
|
||||||
gap: verticalScale(12),
|
|
||||||
},
|
|
||||||
card: {
|
|
||||||
backgroundColor: "#FFFFFF",
|
|
||||||
borderRadius: moderateScale(16),
|
|
||||||
borderWidth: 1,
|
|
||||||
borderColor: "#E2E8F0",
|
|
||||||
overflow: "hidden",
|
|
||||||
},
|
|
||||||
cardHeader: {
|
|
||||||
minHeight: verticalScale(54),
|
|
||||||
paddingHorizontal: moderateScale(14),
|
|
||||||
paddingVertical: verticalScale(12),
|
|
||||||
flexDirection: "row",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "space-between",
|
|
||||||
backgroundColor: "#FFFFFF",
|
|
||||||
gap: moderateScale(10),
|
|
||||||
},
|
|
||||||
cardHeaderExpanded: {
|
|
||||||
backgroundColor: "#F0F7F3",
|
|
||||||
borderBottomWidth: 1,
|
|
||||||
borderBottomColor: "#E2E8F0",
|
|
||||||
},
|
|
||||||
pressed: {
|
|
||||||
opacity: 0.75,
|
|
||||||
},
|
|
||||||
headerLeft: {
|
|
||||||
flex: 1,
|
|
||||||
flexDirection: "row",
|
|
||||||
alignItems: "center",
|
|
||||||
gap: moderateScale(10),
|
|
||||||
},
|
|
||||||
headerAccent: {
|
|
||||||
width: moderateScale(4),
|
|
||||||
height: verticalScale(22),
|
|
||||||
borderRadius: moderateScale(2),
|
|
||||||
backgroundColor: Colors.primary,
|
|
||||||
},
|
|
||||||
headerTitle: {
|
|
||||||
flex: 1,
|
|
||||||
fontSize: moderateScale(15),
|
|
||||||
lineHeight: moderateScale(21),
|
|
||||||
fontWeight: "700",
|
|
||||||
color: "#1E293B",
|
|
||||||
},
|
|
||||||
headerRight: {
|
|
||||||
flexDirection: "row",
|
|
||||||
alignItems: "center",
|
|
||||||
gap: moderateScale(8),
|
|
||||||
},
|
|
||||||
elementBadge: {
|
|
||||||
paddingHorizontal: moderateScale(9),
|
|
||||||
paddingVertical: verticalScale(3),
|
|
||||||
borderRadius: moderateScale(10),
|
|
||||||
backgroundColor: "#E8F5E9",
|
|
||||||
borderWidth: 1,
|
|
||||||
borderColor: "#C6E4CE",
|
|
||||||
},
|
|
||||||
elementBadgeText: {
|
|
||||||
fontSize: 11,
|
|
||||||
lineHeight: 16,
|
|
||||||
fontWeight: "600",
|
|
||||||
color: "#285A44",
|
|
||||||
},
|
|
||||||
chevron: {
|
|
||||||
width: moderateScale(28),
|
|
||||||
height: moderateScale(28),
|
|
||||||
borderRadius: moderateScale(14),
|
|
||||||
backgroundColor: "#FFFFFFB8",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
borderWidth: 1,
|
|
||||||
borderColor: "#E2E8F0",
|
|
||||||
},
|
|
||||||
cardBody: {
|
|
||||||
paddingHorizontal: moderateScale(16),
|
|
||||||
paddingTop: verticalScale(14),
|
|
||||||
paddingBottom: verticalScale(16),
|
|
||||||
gap: verticalScale(12),
|
|
||||||
backgroundColor: "#FFFFFF",
|
|
||||||
},
|
|
||||||
sectionRow: {
|
|
||||||
gap: verticalScale(6),
|
|
||||||
paddingBottom: verticalScale(10),
|
|
||||||
borderBottomWidth: StyleSheet.hairlineWidth,
|
|
||||||
borderBottomColor: "#E8ECEF",
|
|
||||||
},
|
|
||||||
sectionLabel: {
|
|
||||||
fontSize: 12,
|
|
||||||
lineHeight: 17,
|
|
||||||
fontWeight: "700",
|
|
||||||
color: "#597064",
|
|
||||||
letterSpacing: 0.15,
|
|
||||||
},
|
|
||||||
sectionValue: {
|
|
||||||
fontSize: 16,
|
|
||||||
lineHeight: 25,
|
|
||||||
color: "#334155",
|
|
||||||
},
|
|
||||||
pointLinkButton: {
|
|
||||||
alignSelf: "flex-start",
|
|
||||||
minHeight: verticalScale(34),
|
|
||||||
paddingHorizontal: moderateScale(12),
|
|
||||||
paddingVertical: verticalScale(6),
|
|
||||||
borderRadius: Radius.full,
|
|
||||||
backgroundColor: "#E8F5E9",
|
|
||||||
borderWidth: 1,
|
|
||||||
borderColor: "#CDE5D0",
|
|
||||||
flexDirection: "row",
|
|
||||||
alignItems: "center",
|
|
||||||
gap: moderateScale(6),
|
|
||||||
marginTop: verticalScale(6),
|
|
||||||
},
|
|
||||||
pointLinkLabel: {
|
|
||||||
fontSize: moderateScale(13),
|
|
||||||
lineHeight: moderateScale(18),
|
|
||||||
fontWeight: "700",
|
|
||||||
color: Colors.primaryDark,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,6 @@ import { ObjectSections } from "../shared/ObjectSections";
|
||||||
import { RecordCards } from "../shared/RecordCards";
|
import { RecordCards } from "../shared/RecordCards";
|
||||||
import { RecordTable } from "../shared/RecordTable";
|
import { RecordTable } from "../shared/RecordTable";
|
||||||
import { SectionCard } from "../shared/SectionCard";
|
import { SectionCard } from "../shared/SectionCard";
|
||||||
import { useRelationalContentMedia } from "../../media/ContentMediaContext";
|
|
||||||
import { ContentMediaGallery } from "../../media/ContentMediaGallery";
|
|
||||||
|
|
||||||
export const PointCodes = ({ data }: { data: Record<string, unknown> }) => (
|
export const PointCodes = ({ data }: { data: Record<string, unknown> }) => (
|
||||||
<SectionCard title="Points"><ChipList items={asStringArray(data.point_codes)} /></SectionCard>
|
<SectionCard title="Points"><ChipList items={asStringArray(data.point_codes)} /></SectionCard>
|
||||||
|
|
@ -25,36 +23,9 @@ export const DescriptionList = ({ data }: { data: Record<string, unknown> }) =>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const extractCategoryImages = (data: Record<string, unknown>): Record<string, unknown>[] => {
|
export const Images = ({ data }: { data: Record<string, unknown> }) => (
|
||||||
const images = asRecordArray(data.images);
|
<ImageGallery images={asRecordArray(data.images)} />
|
||||||
if (images.length > 0) return images;
|
);
|
||||||
|
|
||||||
const single = asRecord(data.default_image || data.image);
|
|
||||||
if (Object.keys(single).length > 0) {
|
|
||||||
return [single];
|
|
||||||
}
|
|
||||||
|
|
||||||
return [];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const Images = ({ data }: { data: Record<string, unknown> }) => {
|
|
||||||
const directImages = extractCategoryImages(data);
|
|
||||||
const relationalMedia = useRelationalContentMedia();
|
|
||||||
|
|
||||||
// If direct images are explicitly defined in category data attributes, display them
|
|
||||||
if (directImages.length > 0) {
|
|
||||||
return <ImageGallery images={directImages} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If direct media was assigned directly to this category (e.g. primary image in CMS)
|
|
||||||
const directMedia = relationalMedia.filter((m) => m.media_role === "primary");
|
|
||||||
if (directMedia.length > 0) {
|
|
||||||
return <ContentMediaGallery media={directMedia} title="Visual Reference" />;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do not show inherited media from referenced points/meridians for categories without direct images
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const ObjectCard = ({ title, value }: { title: string; value: unknown }) => {
|
export const ObjectCard = ({ title, value }: { title: string; value: unknown }) => {
|
||||||
const obj = asRecord(value);
|
const obj = asRecord(value);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
import type { AttributeDefinitionResponse } from "../../types/content.types";
|
|
||||||
|
|
||||||
export function asString(value: unknown): string {
|
export function asString(value: unknown): string {
|
||||||
if (typeof value === "string") return value;
|
if (typeof value === "string") return value;
|
||||||
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
||||||
|
|
@ -46,63 +44,3 @@ export function humanizeKey(value: string): string {
|
||||||
.replace(/\b\w/g, (letter) => letter.toUpperCase())
|
.replace(/\b\w/g, (letter) => letter.toUpperCase())
|
||||||
.replace(/(['’‘ʼ])s\b/gi, (match) => match[0] + "s");
|
.replace(/(['’‘ʼ])s\b/gi, (match) => match[0] + "s");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Normalizes pattern titles, correcting misplaced apostrophes in singular possessive organ names
|
|
||||||
* (e.g. "Lungs’" / "Lungs'" / "Lunges'" -> "Lung's").
|
|
||||||
*/
|
|
||||||
export function formatPatternTitle(value: string): string {
|
|
||||||
if (!value) return "";
|
|
||||||
return value.replace(/\bLung(?:es|s)['’]/gi, "Lung's");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indexes template attribute definitions (and nested children) by code so
|
|
||||||
* renderers can display exact template labels and casing without hardcoding.
|
|
||||||
*/
|
|
||||||
export function buildDefinitionLabelMap(
|
|
||||||
attributes?: readonly AttributeDefinitionResponse[] | null,
|
|
||||||
): Map<string, string> {
|
|
||||||
const map = new Map<string, string>();
|
|
||||||
if (!attributes) return map;
|
|
||||||
|
|
||||||
const visit = (attrs: readonly AttributeDefinitionResponse[], prefix?: string) => {
|
|
||||||
for (const attr of attrs) {
|
|
||||||
const code = attr.code?.trim();
|
|
||||||
const label = attr.label?.trim();
|
|
||||||
if (code && label) {
|
|
||||||
map.set(code, label);
|
|
||||||
map.set(code.toLowerCase(), label);
|
|
||||||
if (prefix) {
|
|
||||||
map.set(`${prefix}.${code}`, label);
|
|
||||||
map.set(`${prefix}.${code}`.toLowerCase(), label);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Array.isArray(attr.children) && attr.children.length > 0) {
|
|
||||||
visit(attr.children, code || prefix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
visit(attributes);
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the exact template label when defined, falling back to a provided label or humanized key.
|
|
||||||
*/
|
|
||||||
export function resolveAttributeLabel(
|
|
||||||
code: string,
|
|
||||||
labelMap?: ReadonlyMap<string, string>,
|
|
||||||
fallback?: string,
|
|
||||||
): string {
|
|
||||||
const trimmed = code.trim();
|
|
||||||
const fromMap =
|
|
||||||
labelMap?.get(trimmed) || labelMap?.get(trimmed.toLowerCase());
|
|
||||||
if (fromMap && fromMap.trim().length > 0) {
|
|
||||||
return fromMap.trim();
|
|
||||||
}
|
|
||||||
return fallback ?? humanizeKey(trimmed);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,15 +20,11 @@ if (Platform.OS === "android" && UIManager.setLayoutAnimationEnabledExperimental
|
||||||
export interface AccordionSectionProps {
|
export interface AccordionSectionProps {
|
||||||
title: string;
|
title: string;
|
||||||
defaultExpanded?: boolean;
|
defaultExpanded?: boolean;
|
||||||
icon?: keyof typeof Ionicons.glyphMap;
|
|
||||||
iconColor?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function AccordionSection({
|
export function AccordionSection({
|
||||||
title,
|
title,
|
||||||
defaultExpanded = true,
|
defaultExpanded = true,
|
||||||
icon,
|
|
||||||
iconColor,
|
|
||||||
children,
|
children,
|
||||||
}: PropsWithChildren<AccordionSectionProps>) {
|
}: PropsWithChildren<AccordionSectionProps>) {
|
||||||
const [expanded, setExpanded] = useState(defaultExpanded);
|
const [expanded, setExpanded] = useState(defaultExpanded);
|
||||||
|
|
@ -57,13 +53,6 @@ export function AccordionSection({
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<View style={[styles.accent, { backgroundColor: tone.accent }]} />
|
<View style={[styles.accent, { backgroundColor: tone.accent }]} />
|
||||||
{icon ? (
|
|
||||||
<Ionicons
|
|
||||||
name={icon}
|
|
||||||
size={moderateScale(18)}
|
|
||||||
color={iconColor ?? tone.accent}
|
|
||||||
/>
|
|
||||||
) : null}
|
|
||||||
<Text style={[styles.title, { color: tone.title }]}>{title}</Text>
|
<Text style={[styles.title, { color: tone.title }]}>{title}</Text>
|
||||||
<View style={styles.chevron}>
|
<View style={styles.chevron}>
|
||||||
<Ionicons
|
<Ionicons
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import { Colors } from "@/theme";
|
||||||
import type { CollectionRendererProps } from "../../types/renderer.types";
|
import type { CollectionRendererProps } from "../../types/renderer.types";
|
||||||
|
|
||||||
export function CollectionScaffold(
|
export function CollectionScaffold(
|
||||||
props: CollectionRendererProps & { header?: React.ReactNode; countLabel?: string },
|
props: CollectionRendererProps & { header?: React.ReactNode },
|
||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<FlatList
|
<FlatList
|
||||||
|
|
@ -30,7 +30,7 @@ export function CollectionScaffold(
|
||||||
<>
|
<>
|
||||||
{props.header}
|
{props.header}
|
||||||
<Text style={styles.resultCount} accessibilityLiveRegion="polite">
|
<Text style={styles.resultCount} accessibilityLiveRegion="polite">
|
||||||
{props.countLabel ?? `${props.total} ${props.total === 1 ? "result" : "results"}`}
|
{props.total} {props.total === 1 ? "result" : "results"}
|
||||||
</Text>
|
</Text>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|
@ -86,7 +86,8 @@ const styles = StyleSheet.create({
|
||||||
fontSize: moderateScale(12),
|
fontSize: moderateScale(12),
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: Colors.textSecondary,
|
color: Colors.textSecondary,
|
||||||
letterSpacing: 0.2,
|
textTransform: "uppercase",
|
||||||
|
letterSpacing: 1,
|
||||||
marginBottom: verticalScale(8),
|
marginBottom: verticalScale(8),
|
||||||
marginLeft: moderateScale(4),
|
marginLeft: moderateScale(4),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -217,6 +217,7 @@ const styles = StyleSheet.create({
|
||||||
lineHeight: 17,
|
lineHeight: 17,
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: Colors.textSecondary,
|
color: Colors.textSecondary,
|
||||||
letterSpacing: 0.15,
|
textTransform: "uppercase",
|
||||||
|
letterSpacing: 0.35,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -7,26 +7,19 @@ import { asString } from "../helpers/value";
|
||||||
|
|
||||||
import type { ContentMediaItem } from "../../types/media.types";
|
import type { ContentMediaItem } from "../../types/media.types";
|
||||||
|
|
||||||
const getImagePath = (item: Record<string, unknown>): string => {
|
|
||||||
return asString(
|
|
||||||
item.image_path || item.url || item.image_url || item.uri || item.path
|
|
||||||
).trim();
|
|
||||||
};
|
|
||||||
|
|
||||||
const getImageName = (item: Record<string, unknown>): string => {
|
|
||||||
return asString(item.image_name || item.name || item.title || item.caption).trim();
|
|
||||||
};
|
|
||||||
|
|
||||||
export function ImageGallery({ images }: { images: Record<string, unknown>[] }) {
|
export function ImageGallery({ images }: { images: Record<string, unknown>[] }) {
|
||||||
const relationalMedia = useRelationalContentMedia();
|
const relationalMedia = useRelationalContentMedia();
|
||||||
|
|
||||||
const visible = images.filter((item) => getImagePath(item).length > 0);
|
if (relationalMedia.length > 0) {
|
||||||
|
return <ContentMediaGallery media={relationalMedia} title="Visual Reference" />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const visible = images.filter((item) => asString(item.image_path).trim().length > 0);
|
||||||
|
if (!visible.length) return null;
|
||||||
|
|
||||||
// Explicit direct images passed via props take priority over relational media
|
|
||||||
if (visible.length > 0) {
|
|
||||||
const fallbackMedia: ContentMediaItem[] = visible.map((item, index) => {
|
const fallbackMedia: ContentMediaItem[] = visible.map((item, index) => {
|
||||||
const path = getImagePath(item);
|
const path = asString(item.image_path).trim();
|
||||||
const name = getImageName(item);
|
const name = asString(item.image_name).trim();
|
||||||
return {
|
return {
|
||||||
id: `${path}-${index}`,
|
id: `${path}-${index}`,
|
||||||
media_asset_id: `${path}-${index}`,
|
media_asset_id: `${path}-${index}`,
|
||||||
|
|
@ -47,14 +40,6 @@ export function ImageGallery({ images }: { images: Record<string, unknown>[] })
|
||||||
return <ContentMediaGallery media={fallbackMedia} title="Visual Reference" />;
|
return <ContentMediaGallery media={fallbackMedia} title="Visual Reference" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback to relational content media when no direct images are provided
|
|
||||||
if (relationalMedia.length > 0) {
|
|
||||||
return <ContentMediaGallery media={relationalMedia} title="Visual Reference" />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
root: { gap: 14 },
|
root: { gap: 14 },
|
||||||
item: { gap: 7 },
|
item: { gap: 7 },
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,8 @@ const styles = StyleSheet.create({
|
||||||
lineHeight: 17,
|
lineHeight: 17,
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: "#597064",
|
color: "#597064",
|
||||||
letterSpacing: 0.15,
|
textTransform: "uppercase",
|
||||||
|
letterSpacing: 0.4,
|
||||||
},
|
},
|
||||||
value: { fontSize: 16, lineHeight: 25, color: "#334155" },
|
value: { fontSize: 16, lineHeight: 25, color: "#334155" },
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ const styles = StyleSheet.create({
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
lineHeight: 18,
|
lineHeight: 18,
|
||||||
color: "#536F61",
|
color: "#536F61",
|
||||||
letterSpacing: 0.15,
|
textTransform: "uppercase",
|
||||||
|
letterSpacing: 0.35,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,115 +0,0 @@
|
||||||
import React from "react";
|
|
||||||
import {
|
|
||||||
StyleProp,
|
|
||||||
StyleSheet,
|
|
||||||
Text,
|
|
||||||
TextStyle,
|
|
||||||
View,
|
|
||||||
ViewStyle,
|
|
||||||
} from "react-native";
|
|
||||||
import { Ionicons } from "@expo/vector-icons";
|
|
||||||
import { moderateScale, verticalScale } from "react-native-size-matters";
|
|
||||||
|
|
||||||
import { Colors } from "@/theme";
|
|
||||||
|
|
||||||
export interface OverviewCardProps {
|
|
||||||
title?: string;
|
|
||||||
icon?: keyof typeof Ionicons.glyphMap;
|
|
||||||
iconColor?: string;
|
|
||||||
iconSize?: number;
|
|
||||||
text?: string | null;
|
|
||||||
paragraphs?: Array<string | null | undefined>;
|
|
||||||
children?: React.ReactNode;
|
|
||||||
style?: StyleProp<ViewStyle>;
|
|
||||||
titleStyle?: StyleProp<TextStyle>;
|
|
||||||
textStyle?: StyleProp<TextStyle>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function OverviewCard({
|
|
||||||
title = "Overview",
|
|
||||||
icon = "information-circle",
|
|
||||||
iconColor = Colors.primary,
|
|
||||||
iconSize = moderateScale(20),
|
|
||||||
text,
|
|
||||||
paragraphs,
|
|
||||||
children,
|
|
||||||
style,
|
|
||||||
titleStyle,
|
|
||||||
textStyle,
|
|
||||||
}: OverviewCardProps) {
|
|
||||||
const filteredParagraphs = paragraphs?.filter(
|
|
||||||
(p): p is string => typeof p === "string" && p.trim().length > 0,
|
|
||||||
);
|
|
||||||
|
|
||||||
const hasText = typeof text === "string" && text.trim().length > 0;
|
|
||||||
const hasParagraphs =
|
|
||||||
Array.isArray(filteredParagraphs) && filteredParagraphs.length > 0;
|
|
||||||
|
|
||||||
if (!hasText && !hasParagraphs && !children) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<View style={[styles.card, style]}>
|
|
||||||
<View style={styles.header}>
|
|
||||||
{icon ? (
|
|
||||||
<Ionicons name={icon} size={iconSize} color={iconColor} />
|
|
||||||
) : null}
|
|
||||||
<Text style={[styles.title, titleStyle]}>{title}</Text>
|
|
||||||
</View>
|
|
||||||
|
|
||||||
{hasText ? (
|
|
||||||
<Text style={[styles.text, textStyle]}>{text}</Text>
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
{hasParagraphs
|
|
||||||
? filteredParagraphs.map((para, index) => (
|
|
||||||
<Text
|
|
||||||
key={index}
|
|
||||||
style={[
|
|
||||||
index === 0 && !hasText ? styles.text : styles.paragraph,
|
|
||||||
textStyle,
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
{para}
|
|
||||||
</Text>
|
|
||||||
))
|
|
||||||
: null}
|
|
||||||
|
|
||||||
{children}
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
card: {
|
|
||||||
backgroundColor: Colors.surface,
|
|
||||||
borderRadius: moderateScale(12),
|
|
||||||
padding: moderateScale(14),
|
|
||||||
borderWidth: 1,
|
|
||||||
borderColor: Colors.border,
|
|
||||||
},
|
|
||||||
header: {
|
|
||||||
flexDirection: "row",
|
|
||||||
alignItems: "center",
|
|
||||||
gap: moderateScale(8),
|
|
||||||
marginBottom: verticalScale(8),
|
|
||||||
},
|
|
||||||
title: {
|
|
||||||
fontSize: moderateScale(16),
|
|
||||||
fontWeight: "700",
|
|
||||||
color: Colors.textPrimary,
|
|
||||||
},
|
|
||||||
text: {
|
|
||||||
fontSize: moderateScale(13),
|
|
||||||
lineHeight: moderateScale(20),
|
|
||||||
color: Colors.textSecondary,
|
|
||||||
},
|
|
||||||
paragraph: {
|
|
||||||
fontSize: moderateScale(13),
|
|
||||||
lineHeight: moderateScale(20),
|
|
||||||
color: Colors.textSecondary,
|
|
||||||
marginTop: verticalScale(8),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
@ -53,7 +53,8 @@ const styles = StyleSheet.create({
|
||||||
lineHeight: 17,
|
lineHeight: 17,
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: "#617468",
|
color: "#617468",
|
||||||
letterSpacing: 0.15,
|
textTransform: "uppercase",
|
||||||
|
letterSpacing: 0.35,
|
||||||
},
|
},
|
||||||
value: { fontSize: 15, lineHeight: 23, color: "#334155" },
|
value: { fontSize: 15, lineHeight: 23, color: "#334155" },
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import React, { type PropsWithChildren, isValidElement } from "react";
|
import React, { type PropsWithChildren, isValidElement } from "react";
|
||||||
import { Ionicons } from "@expo/vector-icons";
|
|
||||||
|
|
||||||
import { isEmptyValue } from "../../utils/attribute-presentation";
|
import { isEmptyValue } from "../../utils/attribute-presentation";
|
||||||
import { AccordionSection } from "./AccordionSection";
|
import { AccordionSection } from "./AccordionSection";
|
||||||
|
|
@ -8,8 +7,6 @@ import { useSettingsStore } from "@/store/settings.store";
|
||||||
export interface SectionCardProps {
|
export interface SectionCardProps {
|
||||||
title: string;
|
title: string;
|
||||||
defaultExpanded?: boolean;
|
defaultExpanded?: boolean;
|
||||||
icon?: keyof typeof Ionicons.glyphMap;
|
|
||||||
iconColor?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasRenderableContent(node: React.ReactNode): boolean {
|
function hasRenderableContent(node: React.ReactNode): boolean {
|
||||||
|
|
@ -40,8 +37,6 @@ function hasRenderableContent(node: React.ReactNode): boolean {
|
||||||
export function SectionCard({
|
export function SectionCard({
|
||||||
title,
|
title,
|
||||||
defaultExpanded,
|
defaultExpanded,
|
||||||
icon,
|
|
||||||
iconColor,
|
|
||||||
children,
|
children,
|
||||||
}: PropsWithChildren<SectionCardProps>) {
|
}: PropsWithChildren<SectionCardProps>) {
|
||||||
if (!hasRenderableContent(children)) return null;
|
if (!hasRenderableContent(children)) return null;
|
||||||
|
|
@ -53,19 +48,8 @@ export function SectionCard({
|
||||||
const isExpanded =
|
const isExpanded =
|
||||||
defaultExpanded !== undefined ? defaultExpanded : accordionDefaultExpanded;
|
defaultExpanded !== undefined ? defaultExpanded : accordionDefaultExpanded;
|
||||||
|
|
||||||
const resolvedIcon =
|
|
||||||
icon ??
|
|
||||||
(title.trim().toLowerCase() === "overview"
|
|
||||||
? ("information-circle" as const)
|
|
||||||
: undefined);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AccordionSection
|
<AccordionSection title={title} defaultExpanded={isExpanded}>
|
||||||
title={title}
|
|
||||||
defaultExpanded={isExpanded}
|
|
||||||
icon={resolvedIcon}
|
|
||||||
iconColor={iconColor}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</AccordionSection>
|
</AccordionSection>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ export interface ModuleResponse extends ModuleSummary {
|
||||||
release_version: string | null;
|
release_version: string | null;
|
||||||
expected_release_date: string | null;
|
expected_release_date: string | null;
|
||||||
release_notes: string | null;
|
release_notes: string | null;
|
||||||
plan_code?: string | null;
|
|
||||||
metadata: Record<string, unknown>;
|
metadata: Record<string, unknown>;
|
||||||
created_by: string | null;
|
created_by: string | null;
|
||||||
updated_by: string | null;
|
updated_by: string | null;
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ const MODULE_VISUALS: Record<string, ModuleVisualConfig> = {
|
||||||
icon: "body-outline",
|
icon: "body-outline",
|
||||||
color: "#8B5CF6",
|
color: "#8B5CF6",
|
||||||
isDefaultFree: false,
|
isDefaultFree: false,
|
||||||
planCode: "THERAPEUTICS_EAR",
|
planCode: "LIFETIME_ALL",
|
||||||
},
|
},
|
||||||
m0042: {
|
m0042: {
|
||||||
icon: "woman-outline",
|
icon: "woman-outline",
|
||||||
|
|
@ -224,7 +224,6 @@ export function toModuleIndexItem(module: ModuleResponse): ModuleIndexItem {
|
||||||
const visual = MODULE_VISUALS[module.code.toLowerCase()];
|
const visual = MODULE_VISUALS[module.code.toLowerCase()];
|
||||||
const metadataIcon = readMetadataString(module, "icon");
|
const metadataIcon = readMetadataString(module, "icon");
|
||||||
const metadataColor = readMetadataString(module, "color");
|
const metadataColor = readMetadataString(module, "color");
|
||||||
const apiPlanCode = asNonBlankString(module.plan_code);
|
|
||||||
const metadataPlanCode = readMetadataString(module, "plan_code");
|
const metadataPlanCode = readMetadataString(module, "plan_code");
|
||||||
const metadataIsDefaultFree = readMetadataBoolean(module, "is_default_free");
|
const metadataIsDefaultFree = readMetadataBoolean(module, "is_default_free");
|
||||||
|
|
||||||
|
|
@ -242,7 +241,7 @@ export function toModuleIndexItem(module: ModuleResponse): ModuleIndexItem {
|
||||||
icon: metadataIcon ?? visual?.icon ?? "folder-outline",
|
icon: metadataIcon ?? visual?.icon ?? "folder-outline",
|
||||||
color: metadataColor ?? visual?.color ?? "#4F46E5",
|
color: metadataColor ?? visual?.color ?? "#4F46E5",
|
||||||
isDefaultFree: metadataIsDefaultFree ?? visual?.isDefaultFree ?? false,
|
isDefaultFree: metadataIsDefaultFree ?? visual?.isDefaultFree ?? false,
|
||||||
planCode: apiPlanCode ?? metadataPlanCode ?? visual?.planCode ?? "",
|
planCode: metadataPlanCode ?? visual?.planCode ?? "",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
import React, { useState, useEffect, useMemo } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import {
|
import {
|
||||||
Modal,
|
Modal,
|
||||||
Pressable,
|
Pressable,
|
||||||
ScrollView,
|
ScrollView,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
Text,
|
Text,
|
||||||
TextInput,
|
|
||||||
View,
|
View,
|
||||||
} from "react-native";
|
} from "react-native";
|
||||||
import { Ionicons } from "@expo/vector-icons";
|
import { Ionicons } from "@expo/vector-icons";
|
||||||
|
|
@ -21,13 +20,9 @@ import FieldLabel from "@/components/forms/FieldLabel";
|
||||||
import PrimaryButton from "@/components/buttons/PrimaryButton";
|
import PrimaryButton from "@/components/buttons/PrimaryButton";
|
||||||
import { Colors } from "@/theme";
|
import { Colors } from "@/theme";
|
||||||
import {
|
import {
|
||||||
SORTED_COUNTRY_CODES,
|
|
||||||
getCountryRuleByName,
|
getCountryRuleByName,
|
||||||
|
updatePhoneDialCode,
|
||||||
validatePhoneNumber,
|
validatePhoneNumber,
|
||||||
isValidPhoneNumber,
|
|
||||||
parsePhoneNumber,
|
|
||||||
formatE164Phone,
|
|
||||||
cleanPhoneInput,
|
|
||||||
} from "@/constants/countries";
|
} from "@/constants/countries";
|
||||||
|
|
||||||
interface EditProfileFormProps {
|
interface EditProfileFormProps {
|
||||||
|
|
@ -39,6 +34,53 @@ interface EditProfileFormProps {
|
||||||
isLoading?: boolean;
|
isLoading?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const COMMON_COUNTRIES = [
|
||||||
|
"Australia",
|
||||||
|
"Canada",
|
||||||
|
"France",
|
||||||
|
"Germany",
|
||||||
|
"India",
|
||||||
|
"Ireland",
|
||||||
|
"Malaysia",
|
||||||
|
"Netherlands",
|
||||||
|
"New Zealand",
|
||||||
|
"Singapore",
|
||||||
|
"South Africa",
|
||||||
|
"Spain",
|
||||||
|
"Switzerland",
|
||||||
|
"United Arab Emirates",
|
||||||
|
"United Kingdom",
|
||||||
|
"United States",
|
||||||
|
];
|
||||||
|
|
||||||
|
export const isValidPhoneNumber = (val?: string, country?: string): boolean => {
|
||||||
|
if (!val || !val.trim()) return true;
|
||||||
|
return validatePhoneNumber(val, undefined, country) === null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const cleanPhoneInput = (text: string, maxLength = 16): string => {
|
||||||
|
const trimmedStart = text.trimStart();
|
||||||
|
const hasPlus = trimmedStart.startsWith("+");
|
||||||
|
const rest = hasPlus ? trimmedStart.slice(1) : text;
|
||||||
|
// Disallow all non-digits except a single separating space after country code
|
||||||
|
// Specifically strip hyphens, dashes, parentheses, underscores, and letters
|
||||||
|
const noDashes = rest.replace(/[\-()_a-zA-Z]/g, "");
|
||||||
|
const normalized = noDashes.replace(/\s+/g, " ");
|
||||||
|
let digitCount = 0;
|
||||||
|
let result = "";
|
||||||
|
for (const ch of normalized) {
|
||||||
|
if (/\d/.test(ch)) {
|
||||||
|
if (digitCount < maxLength) {
|
||||||
|
digitCount++;
|
||||||
|
result += ch;
|
||||||
|
}
|
||||||
|
} else if (ch === " " && digitCount > 0 && !result.includes(" ")) {
|
||||||
|
result += ch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hasPlus ? `+${result}` : result;
|
||||||
|
};
|
||||||
|
|
||||||
export default function EditProfileForm({
|
export default function EditProfileForm({
|
||||||
initialName = "User Name",
|
initialName = "User Name",
|
||||||
initialEmail = "user@example.com",
|
initialEmail = "user@example.com",
|
||||||
|
|
@ -53,21 +95,9 @@ export default function EditProfileForm({
|
||||||
const [nameError, setNameError] = useState("");
|
const [nameError, setNameError] = useState("");
|
||||||
const [phoneError, setPhoneError] = useState("");
|
const [phoneError, setPhoneError] = useState("");
|
||||||
const [showCountryModal, setShowCountryModal] = useState(false);
|
const [showCountryModal, setShowCountryModal] = useState(false);
|
||||||
const [countrySearch, setCountrySearch] = useState("");
|
|
||||||
|
|
||||||
const activeRule = getCountryRuleByName(country);
|
const activeRule = getCountryRuleByName(country);
|
||||||
|
|
||||||
const filteredCountries = useMemo(() => {
|
|
||||||
const q = countrySearch.trim().toLowerCase();
|
|
||||||
if (!q) return SORTED_COUNTRY_CODES;
|
|
||||||
return SORTED_COUNTRY_CODES.filter(
|
|
||||||
(c) =>
|
|
||||||
c.country.toLowerCase().includes(q) ||
|
|
||||||
c.code.toLowerCase().includes(q) ||
|
|
||||||
c.label.toLowerCase().includes(q)
|
|
||||||
);
|
|
||||||
}, [countrySearch]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setFullName(initialName);
|
setFullName(initialName);
|
||||||
}, [initialName]);
|
}, [initialName]);
|
||||||
|
|
@ -88,10 +118,10 @@ export default function EditProfileForm({
|
||||||
};
|
};
|
||||||
|
|
||||||
const handlePhoneChange = (text: string) => {
|
const handlePhoneChange = (text: string) => {
|
||||||
const cleaned = cleanPhoneInput(text, activeRule.maxLength + activeRule.code.length + 2);
|
const cleaned = cleanPhoneInput(text);
|
||||||
setPhone(cleaned);
|
setPhone(cleaned);
|
||||||
if (phoneError) {
|
if (phoneError) {
|
||||||
if (!cleaned.trim() || isValidPhoneNumber(cleaned, activeRule.code, country)) {
|
if (!cleaned.trim() || isValidPhoneNumber(cleaned, country)) {
|
||||||
setPhoneError("");
|
setPhoneError("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -99,12 +129,12 @@ export default function EditProfileForm({
|
||||||
|
|
||||||
const handleCountrySelect = (newCountry: string) => {
|
const handleCountrySelect = (newCountry: string) => {
|
||||||
if (newCountry !== country) {
|
if (newCountry !== country) {
|
||||||
setPhone("");
|
const updatedPhone = updatePhoneDialCode(phone, country, newCountry);
|
||||||
|
setPhone(updatedPhone);
|
||||||
setCountry(newCountry);
|
setCountry(newCountry);
|
||||||
if (phoneError) setPhoneError("");
|
if (phoneError) setPhoneError("");
|
||||||
}
|
}
|
||||||
setShowCountryModal(false);
|
setShowCountryModal(false);
|
||||||
setCountrySearch("");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
|
|
@ -134,8 +164,13 @@ export default function EditProfileForm({
|
||||||
let normalizedPhone = "";
|
let normalizedPhone = "";
|
||||||
if (trimmedPhone) {
|
if (trimmedPhone) {
|
||||||
const rule = getCountryRuleByName(country);
|
const rule = getCountryRuleByName(country);
|
||||||
const parsed = parsePhoneNumber(trimmedPhone, country);
|
const digitsOnly = trimmedPhone.replace(/\D/g, "");
|
||||||
normalizedPhone = formatE164Phone(rule.code, parsed.localDigits, country);
|
const dialDigits = rule.code.replace(/\D/g, "");
|
||||||
|
let localDigits = digitsOnly;
|
||||||
|
if (digitsOnly.startsWith(dialDigits) && digitsOnly.length > dialDigits.length) {
|
||||||
|
localDigits = digitsOnly.slice(dialDigits.length);
|
||||||
|
}
|
||||||
|
normalizedPhone = `${rule.code}${localDigits}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
onSave?.(trimmedName, normalizedPhone, country);
|
onSave?.(trimmedName, normalizedPhone, country);
|
||||||
|
|
@ -214,27 +249,18 @@ export default function EditProfileForm({
|
||||||
visible={showCountryModal}
|
visible={showCountryModal}
|
||||||
transparent
|
transparent
|
||||||
animationType="slide"
|
animationType="slide"
|
||||||
onRequestClose={() => {
|
onRequestClose={() => setShowCountryModal(false)}
|
||||||
setShowCountryModal(false);
|
|
||||||
setCountrySearch("");
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<Pressable
|
<Pressable
|
||||||
style={styles.modalOverlay}
|
style={styles.modalOverlay}
|
||||||
onPress={() => {
|
onPress={() => setShowCountryModal(false)}
|
||||||
setShowCountryModal(false);
|
|
||||||
setCountrySearch("");
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<Pressable style={styles.modalSheet} onPress={() => {}}>
|
<View style={styles.modalSheet}>
|
||||||
<View style={styles.modalHeader}>
|
<View style={styles.modalHeader}>
|
||||||
<Text style={styles.modalTitle}>Select Country</Text>
|
<Text style={styles.modalTitle}>Select Country</Text>
|
||||||
<Pressable
|
<Pressable
|
||||||
hitSlop={8}
|
hitSlop={8}
|
||||||
onPress={() => {
|
onPress={() => setShowCountryModal(false)}
|
||||||
setShowCountryModal(false);
|
|
||||||
setCountrySearch("");
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<Ionicons
|
<Ionicons
|
||||||
name="close"
|
name="close"
|
||||||
|
|
@ -244,69 +270,30 @@ export default function EditProfileForm({
|
||||||
</Pressable>
|
</Pressable>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
{/* Country Search Bar */}
|
|
||||||
<View style={styles.modalSearchContainer}>
|
|
||||||
<Ionicons
|
|
||||||
name="search-outline"
|
|
||||||
size={moderateScale(17)}
|
|
||||||
color={Colors.textSecondary}
|
|
||||||
/>
|
|
||||||
<TextInput
|
|
||||||
value={countrySearch}
|
|
||||||
onChangeText={setCountrySearch}
|
|
||||||
placeholder="Search country or code..."
|
|
||||||
placeholderTextColor={Colors.textSecondary}
|
|
||||||
style={styles.modalSearchInput}
|
|
||||||
autoCapitalize="none"
|
|
||||||
autoCorrect={false}
|
|
||||||
/>
|
|
||||||
{countrySearch.length > 0 && (
|
|
||||||
<Pressable
|
|
||||||
hitSlop={8}
|
|
||||||
onPress={() => setCountrySearch("")}
|
|
||||||
>
|
|
||||||
<Ionicons
|
|
||||||
name="close-circle"
|
|
||||||
size={moderateScale(17)}
|
|
||||||
color={Colors.textSecondary}
|
|
||||||
/>
|
|
||||||
</Pressable>
|
|
||||||
)}
|
|
||||||
</View>
|
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
contentContainerStyle={styles.countryList}
|
contentContainerStyle={styles.countryList}
|
||||||
keyboardShouldPersistTaps="handled"
|
|
||||||
>
|
>
|
||||||
{filteredCountries.length === 0 ? (
|
{COMMON_COUNTRIES.map((c) => {
|
||||||
<View style={styles.emptyContainer}>
|
const isSelected = country === c;
|
||||||
<Text style={styles.emptyText}>No countries found</Text>
|
|
||||||
</View>
|
|
||||||
) : (
|
|
||||||
filteredCountries.map((c) => {
|
|
||||||
const isSelected = country === c.country;
|
|
||||||
return (
|
return (
|
||||||
<Pressable
|
<Pressable
|
||||||
key={c.iso2 + c.country}
|
key={c}
|
||||||
style={({ pressed }) => [
|
style={({ pressed }) => [
|
||||||
styles.countryItem,
|
styles.countryItem,
|
||||||
isSelected && styles.countryItemSelected,
|
isSelected && styles.countryItemSelected,
|
||||||
pressed && styles.countryItemPressed,
|
pressed && styles.countryItemPressed,
|
||||||
]}
|
]}
|
||||||
onPress={() => handleCountrySelect(c.country)}
|
onPress={() => handleCountrySelect(c)}
|
||||||
>
|
>
|
||||||
<View style={styles.countryRow}>
|
|
||||||
<Text style={styles.countryDialCode}>{c.code}</Text>
|
|
||||||
<Text
|
<Text
|
||||||
style={[
|
style={[
|
||||||
styles.countryName,
|
styles.countryName,
|
||||||
isSelected && styles.countryNameSelected,
|
isSelected && styles.countryNameSelected,
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
{c.country}
|
{c}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
|
||||||
{isSelected && (
|
{isSelected && (
|
||||||
<Ionicons
|
<Ionicons
|
||||||
name="checkmark"
|
name="checkmark"
|
||||||
|
|
@ -316,10 +303,9 @@ export default function EditProfileForm({
|
||||||
)}
|
)}
|
||||||
</Pressable>
|
</Pressable>
|
||||||
);
|
);
|
||||||
})
|
})}
|
||||||
)}
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</Pressable>
|
</View>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
</Modal>
|
</Modal>
|
||||||
</View>
|
</View>
|
||||||
|
|
@ -377,52 +363,6 @@ const styles = StyleSheet.create({
|
||||||
color: Colors.textPrimary,
|
color: Colors.textPrimary,
|
||||||
},
|
},
|
||||||
|
|
||||||
modalSearchContainer: {
|
|
||||||
flexDirection: "row",
|
|
||||||
alignItems: "center",
|
|
||||||
marginHorizontal: scale(16),
|
|
||||||
marginTop: verticalScale(10),
|
|
||||||
marginBottom: verticalScale(4),
|
|
||||||
paddingHorizontal: scale(12),
|
|
||||||
paddingVertical: verticalScale(8),
|
|
||||||
backgroundColor: "#F8FAFC",
|
|
||||||
borderRadius: moderateScale(10),
|
|
||||||
borderWidth: 1,
|
|
||||||
borderColor: "#E2E8F0",
|
|
||||||
gap: scale(8),
|
|
||||||
},
|
|
||||||
|
|
||||||
modalSearchInput: {
|
|
||||||
flex: 1,
|
|
||||||
fontSize: moderateScale(14),
|
|
||||||
color: Colors.textPrimary,
|
|
||||||
padding: 0,
|
|
||||||
},
|
|
||||||
|
|
||||||
emptyContainer: {
|
|
||||||
paddingVertical: verticalScale(24),
|
|
||||||
alignItems: "center",
|
|
||||||
},
|
|
||||||
|
|
||||||
emptyText: {
|
|
||||||
fontSize: moderateScale(14),
|
|
||||||
color: Colors.textSecondary,
|
|
||||||
},
|
|
||||||
|
|
||||||
countryRow: {
|
|
||||||
flexDirection: "row",
|
|
||||||
alignItems: "center",
|
|
||||||
gap: scale(10),
|
|
||||||
flex: 1,
|
|
||||||
},
|
|
||||||
|
|
||||||
countryDialCode: {
|
|
||||||
fontSize: moderateScale(13),
|
|
||||||
fontWeight: "700",
|
|
||||||
color: Colors.textSecondary,
|
|
||||||
minWidth: scale(46),
|
|
||||||
},
|
|
||||||
|
|
||||||
countryList: {
|
countryList: {
|
||||||
paddingHorizontal: scale(16),
|
paddingHorizontal: scale(16),
|
||||||
paddingTop: verticalScale(8),
|
paddingTop: verticalScale(8),
|
||||||
|
|
|
||||||
|
|
@ -65,9 +65,8 @@ export default function HomeScreen() {
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
void modulesQuery.refetch().catch((error) => console.warn("Unable to refresh modules:", error));
|
|
||||||
void refreshSession().catch((error) => console.warn("Unable to refresh session:", error));
|
void refreshSession().catch((error) => console.warn("Unable to refresh session:", error));
|
||||||
}, [modulesQuery.refetch, refreshSession]),
|
}, [refreshSession]),
|
||||||
);
|
);
|
||||||
|
|
||||||
const unlockedModules = useMemo(() => {
|
const unlockedModules = useMemo(() => {
|
||||||
|
|
|
||||||
|
|
@ -77,15 +77,12 @@ export default function ModulesIndexScreen() {
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
isNavigatingRef.current = false;
|
isNavigatingRef.current = false;
|
||||||
void modulesQuery.refetch().catch((error) => {
|
|
||||||
console.warn("Unable to refresh modules:", error);
|
|
||||||
});
|
|
||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
void refreshAccess().catch((error) => {
|
void refreshAccess().catch((error) => {
|
||||||
console.warn("Unable to refresh module access:", error);
|
console.warn("Unable to refresh module access:", error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [accessToken, modulesQuery.refetch, refreshAccess]),
|
}, [accessToken, refreshAccess]),
|
||||||
);
|
);
|
||||||
|
|
||||||
const items = useMemo(
|
const items = useMemo(
|
||||||
|
|
|
||||||
|
|
@ -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 handleLogout = () => {
|
||||||
const doLogout = () => {
|
const doLogout = () => {
|
||||||
setLogoutModalVisible(false);
|
|
||||||
logout();
|
logout();
|
||||||
router.replace("/login");
|
router.replace("/login");
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleLogout = () => {
|
if (Platform.OS === "web") {
|
||||||
setLogoutModalVisible(true);
|
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 handleLogout = () => {
|
||||||
const doLogout = () => {
|
const doLogout = () => {
|
||||||
setLogoutModalVisible(false);
|
|
||||||
logout();
|
logout();
|
||||||
router.replace("/login");
|
router.replace("/login");
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleLogout = () => {
|
if (Platform.OS === "web") {
|
||||||
setLogoutModalVisible(true);
|
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