Compare commits
No commits in common. "main" and "fix/auriculotherapy-plan-code" have entirely different histories.
main
...
fix/auricu
|
|
@ -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(
|
||||||
|
|
|
||||||
|
|
@ -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",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
@ -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,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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} />
|
||||||
|
|
|
||||||
|
|
@ -549,13 +549,7 @@ export function GynecologyDiseaseCollectionRenderer(
|
||||||
</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) {
|
||||||
|
|
|
||||||
|
|
@ -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",
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -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),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -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));
|
||||||
|
|
|
||||||
|
|
@ -452,7 +452,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,
|
||||||
},
|
},
|
||||||
sectionValue: {
|
sectionValue: {
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
@ -56,53 +54,3 @@ export function formatPatternTitle(value: string): string {
|
||||||
return value.replace(/\bLung(?:es|s)['’]/gi, "Lung's");
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -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" },
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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,8 +20,8 @@ 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,
|
isValidPhoneNumber,
|
||||||
parsePhoneNumber,
|
parsePhoneNumber,
|
||||||
|
|
@ -39,6 +38,25 @@ 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 default function EditProfileForm({
|
export default function EditProfileForm({
|
||||||
initialName = "User Name",
|
initialName = "User Name",
|
||||||
initialEmail = "user@example.com",
|
initialEmail = "user@example.com",
|
||||||
|
|
@ -53,21 +71,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]);
|
||||||
|
|
@ -99,12 +105,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 = () => {
|
||||||
|
|
@ -214,27 +220,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 +241,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 +274,9 @@ export default function EditProfileForm({
|
||||||
)}
|
)}
|
||||||
</Pressable>
|
</Pressable>
|
||||||
);
|
);
|
||||||
})
|
})}
|
||||||
)}
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</Pressable>
|
</View>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
</Modal>
|
</Modal>
|
||||||
</View>
|
</View>
|
||||||
|
|
@ -377,52 +334,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