From 45933ddca6a1233b779bd27774eabcc128db1a66 Mon Sep 17 00:00:00 2001 From: ShivaniKhaire Date: Sat, 7 Nov 2026 16:56:36 +0530 Subject: [PATCH 1/7] fix(renderers): add generic OverviewCard, fix missing info icon and redundant subtitle (issue #93) - Create reusable OverviewCard component with default information-circle icon - Replace inconsistent SectionCard in SixStagesCollectionRenderer with OverviewCard - Standardize OverviewCard across collection and detail renderers - Add icon prop support to AccordionSection and SectionCard with auto-resolution for Overview - Remove redundant patterns subtitle under FourLevels and FiveElements cards --- .../collections/EightPrinciplesRenderers.tsx | 55 ++------- .../collections/FiveElementsRenderers.tsx | 66 +++------- .../collections/FourLevelsRenderers.tsx | 78 +++--------- .../collections/GynecologyRenderers.tsx | 49 +------- .../PathogenicFactorsRenderers.tsx | 55 ++------- .../collections/QiBloodRenderers.tsx | 34 +----- .../collections/SixStagesRenderers.tsx | 11 +- .../details/FiveElementsDetailRenderer.tsx | 57 +-------- .../details/FourLevelsDetailRenderer.tsx | 34 +----- .../details/QiBloodDetailRenderer.tsx | 34 +----- .../details/ThreeBurnersDetailRenderer.tsx | 34 +----- .../details/TwelveChannelsDetailRenderer.tsx | 34 +----- .../renderers/shared/AccordionSection.tsx | 11 ++ .../content/renderers/shared/OverviewCard.tsx | 115 ++++++++++++++++++ .../content/renderers/shared/SectionCard.tsx | 18 ++- 15 files changed, 220 insertions(+), 465 deletions(-) create mode 100644 src/features/content/renderers/shared/OverviewCard.tsx diff --git a/src/features/content/renderers/collections/EightPrinciplesRenderers.tsx b/src/features/content/renderers/collections/EightPrinciplesRenderers.tsx index 2df4882..9206290 100644 --- a/src/features/content/renderers/collections/EightPrinciplesRenderers.tsx +++ b/src/features/content/renderers/collections/EightPrinciplesRenderers.tsx @@ -6,6 +6,7 @@ import { moderateScale, verticalScale } from "react-native-size-matters"; import { Colors } from "@/theme"; import { asNumber, asString } from "../helpers/value"; import { CollectionScaffold } from "../shared/CollectionScaffold"; +import { OverviewCard } from "../shared/OverviewCard"; import type { CollectionItemRendererProps, CollectionRendererProps, @@ -24,24 +25,15 @@ export function EightPrinciplesCollectionRenderer( const header = ( - - - - Overview - - - 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. - - - 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. - - - 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. - - - 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. - - + Eight Principles ); @@ -111,35 +103,8 @@ const styles = StyleSheet.create({ marginBottom: verticalScale(14), }, overviewCard: { - backgroundColor: "#FFFFFF", - borderRadius: moderateScale(16), - borderWidth: 1, - borderColor: "#E2EAE5", - padding: moderateScale(16), 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: { fontSize: moderateScale(15), fontWeight: "700", diff --git a/src/features/content/renderers/collections/FiveElementsRenderers.tsx b/src/features/content/renderers/collections/FiveElementsRenderers.tsx index 7830396..8f05805 100644 --- a/src/features/content/renderers/collections/FiveElementsRenderers.tsx +++ b/src/features/content/renderers/collections/FiveElementsRenderers.tsx @@ -7,6 +7,7 @@ import { Colors } from "@/theme"; import { asNumber, asString } from "../helpers/value"; import { CollectionScaffold } from "../shared/CollectionScaffold"; import { ContentCountBadge } from "../shared/ContentCountBadge"; +import { OverviewCard } from "../shared/OverviewCard"; import type { CollectionItemRendererProps, CollectionRendererProps, @@ -15,21 +16,14 @@ import type { export function FiveElementsCollectionRenderer(props: CollectionRendererProps) { const header = ( - - - - Overview - - - 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. - - - 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). - - - The sequences below detail the Generating, Overacting, and Insulting relationships and their specific clinical presentations. - - + Sequences ); @@ -51,11 +45,10 @@ export function FiveElementsCardRenderer({ }: CollectionItemRendererProps) { const attributes = item.attributes; const title = asString(attributes.title) || asString(attributes.name) || item.title; - const label = - asString(attributes.content_label) || + const subtitle = + asString(attributes.sub_title) || asString(attributes.description) || - item.summary || - "Open sequence"; + (item.summary && item.summary !== "Open sequence" ? item.summary : null); const sortOrder = asNumber(attributes.sort_order); const sequenceNumber = typeof sortOrder === "number" ? sortOrder + 1 : undefined; @@ -72,9 +65,11 @@ export function FiveElementsCardRenderer({ {title} - - {label} - + {subtitle ? ( + + {subtitle} + + ) : null} - - - - Overview - - - 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 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. - - - 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. - - - 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 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. - - - 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. - - + Levels ); @@ -60,11 +48,10 @@ export function FourLevelsCardRenderer({ }: CollectionItemRendererProps) { const attributes = item.attributes; const title = asString(attributes.title) || asString(attributes.name) || item.title; - const label = - asString(attributes.content_label) || + const subtitle = + asString(attributes.sub_title) || asString(attributes.description) || - item.summary || - "Open content"; + (item.summary && item.summary !== "Open content" ? item.summary : null); const sortOrder = asNumber(attributes.sort_order); const levelNumber = typeof sortOrder === "number" ? sortOrder + 1 : undefined; @@ -81,9 +68,11 @@ export function FourLevelsCardRenderer({ {title} - - {label} - + {subtitle ? ( + + {subtitle} + + ) : null} {paragraphs.length > 0 ? ( - - - - Overview - - {paragraphs.map((para, index) => ( - - {para} - - ))} - + ) : null} ); @@ -578,34 +569,4 @@ const styles = StyleSheet.create({ overviewContainer: { 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), - }, }); diff --git a/src/features/content/renderers/collections/PathogenicFactorsRenderers.tsx b/src/features/content/renderers/collections/PathogenicFactorsRenderers.tsx index 8f202c4..e052083 100644 --- a/src/features/content/renderers/collections/PathogenicFactorsRenderers.tsx +++ b/src/features/content/renderers/collections/PathogenicFactorsRenderers.tsx @@ -6,6 +6,7 @@ import { moderateScale, verticalScale } from "react-native-size-matters"; import { Colors } from "@/theme"; import { asNumber, asString } from "../helpers/value"; import { CollectionScaffold } from "../shared/CollectionScaffold"; +import { OverviewCard } from "../shared/OverviewCard"; import type { CollectionItemRendererProps, CollectionRendererProps, @@ -16,24 +17,15 @@ export function PathogenicFactorsCollectionRenderer( ) { const header = ( - - - - Overview - - - 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. - - - 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. - - - 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). - - - 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. - - + Pathogenic Factors ); @@ -105,35 +97,8 @@ const styles = StyleSheet.create({ marginBottom: verticalScale(14), }, overviewCard: { - backgroundColor: "#FFFFFF", - borderRadius: moderateScale(16), - borderWidth: 1, - borderColor: "#E2EAE5", - padding: moderateScale(16), 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: { fontSize: moderateScale(15), fontWeight: "700", diff --git a/src/features/content/renderers/collections/QiBloodRenderers.tsx b/src/features/content/renderers/collections/QiBloodRenderers.tsx index 77b78b4..64b4e0d 100644 --- a/src/features/content/renderers/collections/QiBloodRenderers.tsx +++ b/src/features/content/renderers/collections/QiBloodRenderers.tsx @@ -6,6 +6,7 @@ import { moderateScale, verticalScale } from "react-native-size-matters"; import { Colors } from "@/theme"; import { asNumber, asString } from "../helpers/value"; import { CollectionScaffold } from "../shared/CollectionScaffold"; +import { OverviewCard } from "../shared/OverviewCard"; import { useSingleTemplateContentQuery } from "../../hooks/use-single-template-content-query"; import type { CollectionItemRendererProps, @@ -69,15 +70,7 @@ export function QiBloodCollectionRenderer(props: CollectionRendererProps) { const header = ( - {overviewText ? ( - - - - Overview - - {overviewText} - - ) : null} + {overviewText ? : null} Categories @@ -134,29 +127,6 @@ const styles = StyleSheet.create({ paddingBottom: verticalScale(8), 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: { fontSize: moderateScale(16), fontWeight: "700", diff --git a/src/features/content/renderers/collections/SixStagesRenderers.tsx b/src/features/content/renderers/collections/SixStagesRenderers.tsx index c316664..d759010 100644 --- a/src/features/content/renderers/collections/SixStagesRenderers.tsx +++ b/src/features/content/renderers/collections/SixStagesRenderers.tsx @@ -6,7 +6,7 @@ import { moderateScale, verticalScale } from "react-native-size-matters"; import { Colors } from "@/theme"; import { asNumber, asString, humanizeKey } from "../helpers/value"; import { CollectionScaffold } from "../shared/CollectionScaffold"; -import { SectionCard } from "../shared/SectionCard"; +import { OverviewCard } from "../shared/OverviewCard"; import type { CollectionItemRendererProps, CollectionRendererProps, @@ -17,9 +17,7 @@ export function SixStagesCollectionRenderer(props: CollectionRendererProps) { const header = overviewText ? ( - - {overviewText} - + ) : null; @@ -93,11 +91,6 @@ const styles = StyleSheet.create({ overviewContainer: { marginBottom: verticalScale(14), }, - overviewText: { - fontSize: moderateScale(14), - lineHeight: moderateScale(22), - color: "#374151", - }, row: { minHeight: moderateScale(68), flexDirection: "row", diff --git a/src/features/content/renderers/details/FiveElementsDetailRenderer.tsx b/src/features/content/renderers/details/FiveElementsDetailRenderer.tsx index f331079..4da5f38 100644 --- a/src/features/content/renderers/details/FiveElementsDetailRenderer.tsx +++ b/src/features/content/renderers/details/FiveElementsDetailRenderer.tsx @@ -8,6 +8,7 @@ import { Colors } from "@/theme"; import type { DetailRendererProps } from "../../types/renderer.types"; import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections"; import { Hero } from "../shared/Hero"; +import { OverviewCard } from "../shared/OverviewCard"; import { Paragraphs } from "../shared/Paragraphs"; import { SectionCard } from "../shared/SectionCard"; import { asRecordArray, asString, asStringArray } from "../helpers/value"; @@ -96,20 +97,7 @@ export function FiveElementsDetailRenderer({ {/* Overview Card (rendered only when overview/content exists in data) */} {overviewParagraphs.length > 0 ? ( - - - - Overview - - {overviewParagraphs.map((para, idx) => ( - 0 && styles.paragraphSpacing]} - > - {para} - - ))} - + ) : null} {/* Dynamic Sequences List from data.sections */} @@ -181,20 +169,7 @@ export function FiveElementsDetailRenderer({ {/* Overview Card (rendered only when overview/content exists in data) */} {overviewParagraphs.length > 0 ? ( - - - - Overview - - {overviewParagraphs.map((para, idx) => ( - 0 && styles.paragraphSpacing]} - > - {para} - - ))} - + ) : null} {/* Collapsible Pattern Cards from data.sections */} @@ -230,32 +205,6 @@ const styles = StyleSheet.create({ paddingBottom: verticalScale(40), 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: { gap: verticalScale(10), }, diff --git a/src/features/content/renderers/details/FourLevelsDetailRenderer.tsx b/src/features/content/renderers/details/FourLevelsDetailRenderer.tsx index 9b704a9..736885b 100644 --- a/src/features/content/renderers/details/FourLevelsDetailRenderer.tsx +++ b/src/features/content/renderers/details/FourLevelsDetailRenderer.tsx @@ -15,6 +15,7 @@ import { BulletList } from "../shared/BulletList"; import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections"; import { ContentValue } from "../shared/ContentValue"; import { Hero } from "../shared/Hero"; +import { OverviewCard } from "../shared/OverviewCard"; import { Paragraphs } from "../shared/Paragraphs"; import { SectionCard } from "../shared/SectionCard"; @@ -115,15 +116,7 @@ export function FourLevelsDetailRenderer({ {/* Direct Overview Card matching Four Levels 1st page */} - {overview ? ( - - - - Overview - - {overview} - - ) : null} + {overview ? : null} {/* Patterns List with numbered cards matching 1st page */} @@ -288,29 +281,6 @@ const styles = StyleSheet.create({ paddingBottom: verticalScale(40), 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: { gap: verticalScale(10), }, diff --git a/src/features/content/renderers/details/QiBloodDetailRenderer.tsx b/src/features/content/renderers/details/QiBloodDetailRenderer.tsx index 61dcec1..1eeb250 100644 --- a/src/features/content/renderers/details/QiBloodDetailRenderer.tsx +++ b/src/features/content/renderers/details/QiBloodDetailRenderer.tsx @@ -8,6 +8,7 @@ import type { DetailRendererProps } from "../../types/renderer.types"; import { BackActionContext } from "../../context/BackActionContext"; import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections"; import { Hero } from "../shared/Hero"; +import { OverviewCard } from "../shared/OverviewCard"; import { SectionCard } from "../shared/SectionCard"; import { BulletList } from "../shared/BulletList"; import { Paragraphs } from "../shared/Paragraphs"; @@ -338,15 +339,7 @@ export function QiBloodDetailRenderer({ {/* Category Overview Card */} - {categoryOverview ? ( - - - - Overview - - {categoryOverview} - - ) : null} + {categoryOverview ? : null} {/* Numbered Patterns List */} {rootPatterns.length > 0 ? ( @@ -390,29 +383,6 @@ const styles = StyleSheet.create({ paddingBottom: verticalScale(40), 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: { gap: verticalScale(10), }, diff --git a/src/features/content/renderers/details/ThreeBurnersDetailRenderer.tsx b/src/features/content/renderers/details/ThreeBurnersDetailRenderer.tsx index 1c901ee..aeab482 100644 --- a/src/features/content/renderers/details/ThreeBurnersDetailRenderer.tsx +++ b/src/features/content/renderers/details/ThreeBurnersDetailRenderer.tsx @@ -7,6 +7,7 @@ import { Colors } from "@/theme"; import type { DetailRendererProps } from "../../types/renderer.types"; import { BackActionContext } from "../../context/BackActionContext"; import { Hero } from "../shared/Hero"; +import { OverviewCard } from "../shared/OverviewCard"; import { SectionCard } from "../shared/SectionCard"; import { Paragraphs } from "../shared/Paragraphs"; import { BulletList } from "../shared/BulletList"; @@ -457,15 +458,7 @@ export function ThreeBurnersDetailRenderer({ {/* Overview Card */} - {overviewText ? ( - - - - Overview - - {overviewText} - - ) : null} + {overviewText ? : null} {/* Burner Categories (1. Upper Burner, 2. Middle Burner, 3. Lower Burner) */} @@ -505,29 +498,6 @@ const styles = StyleSheet.create({ paddingBottom: verticalScale(40), 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: { gap: verticalScale(10), }, diff --git a/src/features/content/renderers/details/TwelveChannelsDetailRenderer.tsx b/src/features/content/renderers/details/TwelveChannelsDetailRenderer.tsx index f192a18..b6cce47 100644 --- a/src/features/content/renderers/details/TwelveChannelsDetailRenderer.tsx +++ b/src/features/content/renderers/details/TwelveChannelsDetailRenderer.tsx @@ -7,6 +7,7 @@ import { Colors } from "@/theme"; import type { DetailRendererProps } from "../../types/renderer.types"; import { BackActionContext } from "../../context/BackActionContext"; import { Hero } from "../shared/Hero"; +import { OverviewCard } from "../shared/OverviewCard"; import { SectionCard } from "../shared/SectionCard"; import { Paragraphs } from "../shared/Paragraphs"; import { BulletList } from "../shared/BulletList"; @@ -613,15 +614,7 @@ export function TwelveChannelsDetailRenderer({ {/* 1. Overview Card */} - {overviewText ? ( - - - - Overview - - {overviewText} - - ) : null} + {overviewText ? : null} {/* 2. Organ vs Channel Card */} {organVsChannelText ? ( @@ -756,29 +749,6 @@ const styles = StyleSheet.create({ paddingBottom: verticalScale(40), 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: { backgroundColor: "#FFFFFF", borderRadius: moderateScale(14), diff --git a/src/features/content/renderers/shared/AccordionSection.tsx b/src/features/content/renderers/shared/AccordionSection.tsx index e0308db..e3972e9 100644 --- a/src/features/content/renderers/shared/AccordionSection.tsx +++ b/src/features/content/renderers/shared/AccordionSection.tsx @@ -20,11 +20,15 @@ if (Platform.OS === "android" && UIManager.setLayoutAnimationEnabledExperimental export interface AccordionSectionProps { title: string; defaultExpanded?: boolean; + icon?: keyof typeof Ionicons.glyphMap; + iconColor?: string; } export function AccordionSection({ title, defaultExpanded = true, + icon, + iconColor, children, }: PropsWithChildren) { const [expanded, setExpanded] = useState(defaultExpanded); @@ -53,6 +57,13 @@ export function AccordionSection({ ]} > + {icon ? ( + + ) : null} {title} ; + children?: React.ReactNode; + style?: StyleProp; + titleStyle?: StyleProp; + textStyle?: StyleProp; +} + +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 ( + + + {icon ? ( + + ) : null} + {title} + + + {hasText ? ( + {text} + ) : null} + + {hasParagraphs + ? filteredParagraphs.map((para, index) => ( + + {para} + + )) + : null} + + {children} + + ); +} + +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), + }, +}); + diff --git a/src/features/content/renderers/shared/SectionCard.tsx b/src/features/content/renderers/shared/SectionCard.tsx index 3e6259f..72b9846 100644 --- a/src/features/content/renderers/shared/SectionCard.tsx +++ b/src/features/content/renderers/shared/SectionCard.tsx @@ -1,4 +1,5 @@ import React, { type PropsWithChildren, isValidElement } from "react"; +import { Ionicons } from "@expo/vector-icons"; import { isEmptyValue } from "../../utils/attribute-presentation"; import { AccordionSection } from "./AccordionSection"; @@ -7,6 +8,8 @@ import { useSettingsStore } from "@/store/settings.store"; export interface SectionCardProps { title: string; defaultExpanded?: boolean; + icon?: keyof typeof Ionicons.glyphMap; + iconColor?: string; } function hasRenderableContent(node: React.ReactNode): boolean { @@ -37,6 +40,8 @@ function hasRenderableContent(node: React.ReactNode): boolean { export function SectionCard({ title, defaultExpanded, + icon, + iconColor, children, }: PropsWithChildren) { if (!hasRenderableContent(children)) return null; @@ -48,8 +53,19 @@ export function SectionCard({ const isExpanded = defaultExpanded !== undefined ? defaultExpanded : accordionDefaultExpanded; + const resolvedIcon = + icon ?? + (title.trim().toLowerCase() === "overview" + ? ("information-circle" as const) + : undefined); + return ( - + {children} ); From 52fc20927431dcdd7dc04b51d1d90e71fd5fac25 Mon Sep 17 00:00:00 2001 From: ShivaniKhaire Date: Sat, 7 Nov 2026 17:18:00 +0530 Subject: [PATCH 2/7] feat(auth): sort country selection alphabetically in registration and profile (issue #110) - Export SORTED_COUNTRY_CODES sorted by country name in constants/countries.ts - Use SORTED_COUNTRY_CODES in SignUpForm to sort countries alphabetically in the Select Country modal - Sort COMMON_COUNTRIES in EditProfileForm alphabetically for consistent UX --- src/constants/countries.ts | 4 +++ src/features/auth/components/SignUpForm.tsx | 6 ++--- .../profile/components/EditProfileForm.tsx | 26 +++++++++---------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/constants/countries.ts b/src/constants/countries.ts index 7b227e6..7537b48 100644 --- a/src/constants/countries.ts +++ b/src/constants/countries.ts @@ -98,6 +98,10 @@ export const COUNTRY_CODES: CountryCode[] = [ export const DEFAULT_COUNTRY = COUNTRY_CODES[0]; // India (+91) +export const SORTED_COUNTRY_CODES: CountryCode[] = [...COUNTRY_CODES].sort((a, b) => + a.country.localeCompare(b.country) +); + export const getCountryRuleByDialCode = (dialCode: string): CountryCode => { return ( COUNTRY_CODES.find((c) => c.code === dialCode) || { diff --git a/src/features/auth/components/SignUpForm.tsx b/src/features/auth/components/SignUpForm.tsx index cf851be..f2f3f71 100644 --- a/src/features/auth/components/SignUpForm.tsx +++ b/src/features/auth/components/SignUpForm.tsx @@ -24,9 +24,9 @@ import PrimaryButton from "@/components/buttons/PrimaryButton"; import { AuthColors } from "../constants/colors"; import { Colors } from "@/theme"; import { - COUNTRY_CODES, CountryCode, DEFAULT_COUNTRY, + SORTED_COUNTRY_CODES, validatePhoneNumber, validateEmail, } from "@/constants/countries"; @@ -55,8 +55,8 @@ export default function SignUpForm() { const filteredCountries = useMemo(() => { const q = countrySearch.trim().toLowerCase(); - if (!q) return COUNTRY_CODES; - return COUNTRY_CODES.filter( + if (!q) return SORTED_COUNTRY_CODES; + return SORTED_COUNTRY_CODES.filter( (c) => c.country.toLowerCase().includes(q) || c.code.includes(q) || diff --git a/src/features/profile/components/EditProfileForm.tsx b/src/features/profile/components/EditProfileForm.tsx index 488156d..18d0a83 100644 --- a/src/features/profile/components/EditProfileForm.tsx +++ b/src/features/profile/components/EditProfileForm.tsx @@ -35,22 +35,22 @@ interface EditProfileFormProps { } const COMMON_COUNTRIES = [ - "India", - "United States", - "United Kingdom", - "Canada", "Australia", - "Germany", - "Singapore", - "Malaysia", - "New Zealand", - "United Arab Emirates", - "South Africa", - "Ireland", - "Netherlands", - "Switzerland", + "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 => { From 77d38472809a79be8ee69398a4c43fc6987055e7 Mon Sep 17 00:00:00 2001 From: ShivaniKhaire Date: Sat, 7 Nov 2026 17:22:02 +0530 Subject: [PATCH 3/7] fix(settings): remove duplicate alert popup on change password error (issue #111) - Prevent displaying duplicate error messages when entering an incorrect password - Rely on inline error display below the input fields instead of showing redundant alert dialogs --- src/app/profile/change-password.tsx | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/app/profile/change-password.tsx b/src/app/profile/change-password.tsx index c4b5772..33b4759 100644 --- a/src/app/profile/change-password.tsx +++ b/src/app/profile/change-password.tsx @@ -100,11 +100,6 @@ export default function ChangePasswordScreen() { } else { setCurrentError(errMsg); } - if (Platform.OS === "web") { - window.alert(errMsg); - } else { - Alert.alert("Error", errMsg); - } } finally { setIsLoading(false); } From 947ca339e554732426b4d2dda419a075aa34d436 Mon Sep 17 00:00:00 2001 From: Urvish Date: Wed, 11 Nov 2026 15:19:13 +0530 Subject: [PATCH 4/7] fix(auth): enforce strict national phone length and prevent country code combining in mobile app --- src/constants/countries.ts | 94 +++++++++++++++++-- src/features/auth/components/SignUpForm.tsx | 31 ++++++ .../profile/components/EditProfileForm.tsx | 45 ++------- 3 files changed, 126 insertions(+), 44 deletions(-) diff --git a/src/constants/countries.ts b/src/constants/countries.ts index 7b227e6..982d02e 100644 --- a/src/constants/countries.ts +++ b/src/constants/countries.ts @@ -164,6 +164,11 @@ export const validatePhoneNumber = ( if ((!rule || rule.country === "Other") && country) { rule = getCountryRuleByName(country); } + // If still not found and input starts with '+', match from COUNTRY_CODES + if (!rule && trimmed.startsWith("+")) { + const sorted = [...COUNTRY_CODES].sort((a, b) => b.code.length - a.code.length); + rule = sorted.find((c) => trimmed.startsWith(c.code)); + } if (!rule || rule.country === "Other") { if (dialCode === "+91" || (country && country.toLowerCase() === "india")) { rule = getCountryRuleByDialCode("+91"); @@ -174,12 +179,14 @@ export const validatePhoneNumber = ( const dialDigits = rule.code.replace(/\D/g, ""); let localDigits = allDigits; - // If formatted with country code (e.g. +919876543210 or 919876543210 where total length > rule.maxLength), strip country prefix - if ( - (trimmed.startsWith("+") || allDigits.length > rule.maxLength) && - allDigits.startsWith(dialDigits) && - allDigits.length === dialDigits.length + rule.minLength - ) { + if (trimmed.startsWith("+")) { + // Input includes country code prefix (e.g. +919876543210 or +9198765432) + // Must strip the dial code to extract the actual local number + if (allDigits.startsWith(dialDigits)) { + localDigits = allDigits.slice(dialDigits.length); + } + } else if (allDigits.length > rule.maxLength && allDigits.startsWith(dialDigits)) { + // Input was formatted with dial digits without '+' and exceeds local maxLength (e.g. 919876543210) localDigits = allDigits.slice(dialDigits.length); } @@ -195,6 +202,14 @@ export const validatePhoneNumber = ( return `${rule.country} phone number cannot exceed ${rule.maxLength} digits.`; } } + + // Specific country telecom prefix rules + if (dialDigits === "91" || rule.country === "India") { + if (!/^[6-9]/.test(localDigits)) { + return "India mobile number must begin with 6, 7, 8, or 9."; + } + } + return null; } @@ -216,6 +231,71 @@ export const isValidPhoneNumber = ( 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 } => { + const defaultRule = getCountryRuleByName(fallbackCountry) || getCountryRuleByDialCode("+91"); + if (!fullPhone || !fullPhone.trim()) { + return { country: defaultRule.country, dialCode: defaultRule.code, localDigits: "" }; + } + const trimmed = fullPhone.trim(); + + // Try matching dial code prefixes from longest to shortest + 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), + }; + } + + // If no '+' prefix, check if digits start with fallback country dial digits and exceed national length + const dialDigits = defaultRule.code.replace(/\D/g, ""); + const rawDigits = trimmed.replace(/\D/g, ""); + let local = rawDigits; + if ( + dialDigits && + rawDigits.startsWith(dialDigits) && + rawDigits.length > defaultRule.maxLength + ) { + local = rawDigits.slice(dialDigits.length); + } + return { + country: defaultRule.country, + dialCode: defaultRule.code, + localDigits: local.slice(0, defaultRule.maxLength), + }; +}; + +/** + * Formats full phone number cleanly as E.164 without spaces (+) + */ +export const formatE164Phone = (dialCode: string, localDigits: string): string => { + const digits = localDigits.replace(/\D/g, ""); + const code = dialCode.startsWith("+") ? dialCode : `+${dialCode}`; + return digits ? `${code}${digits}` : ""; +}; + +/** + * 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. @@ -246,7 +326,7 @@ export const updatePhoneDialCode = ( } else { const oldDialDigits = oldRule.code.replace(/\D/g, ""); const rawDigits = trimmed.replace(/\D/g, ""); - if (oldDialDigits && rawDigits.startsWith(oldDialDigits) && rawDigits.length > oldDialDigits.length) { + if (oldDialDigits && rawDigits.startsWith(oldDialDigits) && rawDigits.length > oldRule.maxLength) { nationalDigits = rawDigits.slice(oldDialDigits.length); } else { nationalDigits = rawDigits; diff --git a/src/features/auth/components/SignUpForm.tsx b/src/features/auth/components/SignUpForm.tsx index cf851be..20ce84d 100644 --- a/src/features/auth/components/SignUpForm.tsx +++ b/src/features/auth/components/SignUpForm.tsx @@ -65,6 +65,37 @@ export default function SignUpForm() { }, [countrySearch]); 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, ""); setPhone(digits.slice(0, selectedCountry.maxLength)); if (phoneError) setPhoneError(""); diff --git a/src/features/profile/components/EditProfileForm.tsx b/src/features/profile/components/EditProfileForm.tsx index 488156d..503626b 100644 --- a/src/features/profile/components/EditProfileForm.tsx +++ b/src/features/profile/components/EditProfileForm.tsx @@ -23,6 +23,10 @@ import { getCountryRuleByName, updatePhoneDialCode, validatePhoneNumber, + isValidPhoneNumber, + parsePhoneNumber, + formatE164Phone, + cleanPhoneInput, } from "@/constants/countries"; interface EditProfileFormProps { @@ -53,34 +57,6 @@ const COMMON_COUNTRIES = [ "Spain", ]; -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({ initialName = "User Name", initialEmail = "user@example.com", @@ -118,10 +94,10 @@ export default function EditProfileForm({ }; const handlePhoneChange = (text: string) => { - const cleaned = cleanPhoneInput(text); + const cleaned = cleanPhoneInput(text, activeRule.maxLength + activeRule.code.length + 2); setPhone(cleaned); if (phoneError) { - if (!cleaned.trim() || isValidPhoneNumber(cleaned, country)) { + if (!cleaned.trim() || isValidPhoneNumber(cleaned, activeRule.code, country)) { setPhoneError(""); } } @@ -164,13 +140,8 @@ export default function EditProfileForm({ let normalizedPhone = ""; if (trimmedPhone) { const rule = getCountryRuleByName(country); - const digitsOnly = trimmedPhone.replace(/\D/g, ""); - 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}`; + const parsed = parsePhoneNumber(trimmedPhone, country); + normalizedPhone = formatE164Phone(rule.code, parsed.localDigits); } onSave?.(trimmedName, normalizedPhone, country); From 78fbfe29cf1f874ecc84957f1e98d14b5b6eed90 Mon Sep 17 00:00:00 2001 From: Urvish Date: Wed, 11 Nov 2026 15:48:23 +0530 Subject: [PATCH 5/7] fix(auth): update change password confirm mismatch error message --- src/app/profile/change-password.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/profile/change-password.tsx b/src/app/profile/change-password.tsx index c4b5772..5cf3fb6 100644 --- a/src/app/profile/change-password.tsx +++ b/src/app/profile/change-password.tsx @@ -66,7 +66,7 @@ export default function ChangePasswordScreen() { setConfirmError("Please confirm your new password"); hasError = true; } else if (newPassword !== confirmPassword) { - setConfirmError("Passwords do not match"); + setConfirmError("Confirm password do not match."); hasError = true; } From 0c60b835a0d2cbe929500ecf1b952894c42da6cf Mon Sep 17 00:00:00 2001 From: Urvish Date: Mon, 16 Nov 2026 16:10:35 +0530 Subject: [PATCH 6/7] fix(validation): add country-specific mobile phone validation and libphonenumber-js - Integrate libphonenumber-js to validate country mobile numbering plans (e.g., France 06/07, India 6-9, UK 07) - Add ISO-2 country codes to eliminate dropdown collisions between countries sharing dial codes (+1 for US and Canada) - Automatically strip leading national trunk zero (0) when converting to standard international E.164 format - Ensure new dependency is registered in package.json and package-lock.json for npm install --- package-lock.json | 7 + package.json | 1 + src/constants/countries.ts | 392 ++++++++++-------- src/features/auth/components/SignUpForm.tsx | 4 +- .../profile/components/EditProfileForm.tsx | 2 +- 5 files changed, 226 insertions(+), 180 deletions(-) diff --git a/package-lock.json b/package-lock.json index 19cc7d8..756f88d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,6 +32,7 @@ "expo-symbols": "~1.0.7", "expo-system-ui": "~6.0.9", "expo-web-browser": "~15.0.11", + "libphonenumber-js": "^1.13.16", "react": "19.1.0", "react-dom": "19.1.0", "react-native": "0.81.5", @@ -6170,6 +6171,12 @@ "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": { "version": "1.4.2", "resolved": "https://registry.npmjs.org/lighthouse-logger/-/lighthouse-logger-1.4.2.tgz", diff --git a/package.json b/package.json index f46a3a2..9a70bc8 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "expo-symbols": "~1.0.7", "expo-system-ui": "~6.0.9", "expo-web-browser": "~15.0.11", + "libphonenumber-js": "^1.13.16", "react": "19.1.0", "react-dom": "19.1.0", "react-native": "0.81.5", diff --git a/src/constants/countries.ts b/src/constants/countries.ts index cb2cd42..5f290c5 100644 --- a/src/constants/countries.ts +++ b/src/constants/countries.ts @@ -1,4 +1,7 @@ +import { parsePhoneNumberFromString, validatePhoneNumberLength, type CountryCode as LibCountryCode } from "libphonenumber-js/max"; + export interface CountryCode { + iso2: LibCountryCode; code: string; label: string; country: string; @@ -10,121 +13,115 @@ export interface CountryCode { export const COUNTRY_CODES: CountryCode[] = [ // South Asia - { code: "+91", label: "🇮🇳 +91", country: "India", currency: "INR", 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" }, - { code: "+880", label: "🇧🇩 +880", country: "Bangladesh", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" }, - { code: "+94", label: "🇱🇰 +94", country: "Sri Lanka", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" }, - { code: "+977", label: "🇳🇵 +977", country: "Nepal", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" }, - { code: "+975", label: "🇧🇹 +975", country: "Bhutan", currency: "USD", minLength: 8, maxLength: 8, placeholder: "8-digit mobile number" }, - { code: "+960", label: "🇲🇻 +960", country: "Maldives", currency: "USD", minLength: 7, maxLength: 7, placeholder: "7-digit mobile number" }, + { iso2: "IN", 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" }, + { iso2: "BD", 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" }, + { iso2: "NP", 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" }, + { iso2: "MV", code: "+960", label: "🇲🇻 +960", country: "Maldives", currency: "USD", minLength: 7, maxLength: 7, placeholder: "7-digit mobile number" }, // North America - { code: "+1", label: "🇺🇸 +1", country: "United States", 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" }, - { code: "+52", label: "🇲🇽 +52", country: "Mexico", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" }, + { iso2: "US", 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" }, + { iso2: "MX", code: "+52", label: "🇲🇽 +52", country: "Mexico", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" }, // Europe & UK - { code: "+44", label: "🇬🇧 +44", country: "United Kingdom", currency: "USD", 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" }, - { code: "+33", label: "🇫🇷 +33", country: "France", 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" }, - { code: "+34", label: "🇪🇸 +34", country: "Spain", 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" }, - { code: "+41", label: "🇨🇭 +41", country: "Switzerland", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" }, - { code: "+32", label: "🇧🇪 +32", country: "Belgium", currency: "EUR", minLength: 8, maxLength: 9, placeholder: "8 to 9 digits" }, - { code: "+43", label: "🇦🇹 +43", country: "Austria", currency: "EUR", minLength: 10, maxLength: 11, placeholder: "10 to 11 digits" }, - { code: "+353", label: "🇮🇪 +353", country: "Ireland", currency: "EUR", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" }, - { code: "+46", label: "🇸🇪 +46", country: "Sweden", currency: "EUR", minLength: 7, maxLength: 10, placeholder: "7 to 10 digits" }, - { code: "+47", label: "🇳🇴 +47", country: "Norway", currency: "USD", 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" }, - { code: "+358", label: "🇫🇮 +358", country: "Finland", currency: "EUR", minLength: 6, maxLength: 10, placeholder: "6 to 10 digits" }, - { code: "+351", label: "🇵🇹 +351", country: "Portugal", currency: "EUR", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" }, - { code: "+30", label: "🇬🇷 +30", country: "Greece", currency: "EUR", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" }, - { code: "+48", label: "🇵🇱 +48", country: "Poland", 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" }, - { code: "+36", label: "🇭🇺 +36", country: "Hungary", currency: "EUR", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" }, - { code: "+40", label: "🇷🇴 +40", country: "Romania", currency: "EUR", minLength: 9, maxLength: 10, placeholder: "9 to 10 digits" }, - { code: "+380", label: "🇺🇦 +380", country: "Ukraine", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" }, - { code: "+354", label: "🇮🇸 +354", country: "Iceland", currency: "EUR", minLength: 7, maxLength: 9, placeholder: "7 to 9 digits" }, - { code: "+352", label: "🇱🇺 +352", country: "Luxembourg", currency: "EUR", minLength: 8, maxLength: 10, placeholder: "8 to 10 digits" }, - { code: "+385", label: "🇭🇷 +385", country: "Croatia", currency: "EUR", minLength: 8, maxLength: 9, placeholder: "8 to 9 digits" }, - { code: "+421", label: "🇸🇰 +421", country: "Slovakia", currency: "EUR", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" }, - { code: "+359", label: "🇧🇬 +359", country: "Bulgaria", currency: "EUR", minLength: 8, maxLength: 9, placeholder: "8 to 9 digits" }, - { code: "+7", label: "🇷🇺 +7", country: "Russia", 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" }, + { iso2: "GB", 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" }, + { iso2: "FR", 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" }, + { iso2: "ES", 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" }, + { iso2: "CH", 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" }, + { iso2: "AT", 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" }, + { iso2: "SE", 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" }, + { iso2: "DK", 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" }, + { iso2: "PT", 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" }, + { iso2: "PL", 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" }, + { iso2: "HU", 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" }, + { iso2: "UA", 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" }, + { iso2: "LU", 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" }, + { iso2: "SK", 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" }, + { iso2: "RU", 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" }, // Asia-Pacific - { code: "+61", label: "🇦🇺 +61", country: "Australia", currency: "USD", minLength: 9, maxLength: 10, placeholder: "9 to 10 digits" }, - { code: "+64", label: "🇳🇿 +64", country: "New Zealand", currency: "USD", minLength: 8, maxLength: 10, placeholder: "8 to 10 digits" }, - { code: "+81", label: "🇯🇵 +81", country: "Japan", currency: "USD", minLength: 10, maxLength: 11, placeholder: "10 to 11 digits" }, - { code: "+86", label: "🇨🇳 +86", country: "China", currency: "USD", minLength: 11, maxLength: 11, placeholder: "11-digit mobile number" }, - { code: "+82", label: "🇰🇷 +82", country: "South Korea", currency: "USD", minLength: 9, maxLength: 11, placeholder: "9 to 11 digits" }, - { code: "+852", label: "🇭🇰 +852", country: "Hong Kong", currency: "USD", minLength: 8, maxLength: 8, placeholder: "8-digit mobile number" }, - { code: "+886", label: "🇹🇼 +886", country: "Taiwan", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" }, - { code: "+65", label: "🇸🇬 +65", country: "Singapore", currency: "USD", minLength: 8, maxLength: 8, placeholder: "8-digit mobile number" }, - { code: "+60", label: "🇲🇾 +60", country: "Malaysia", currency: "USD", minLength: 9, maxLength: 10, placeholder: "9 to 10 digits" }, - { code: "+62", label: "🇮🇩 +62", country: "Indonesia", currency: "USD", minLength: 9, maxLength: 12, placeholder: "9 to 12 digits" }, - { code: "+63", label: "🇵🇭 +63", country: "Philippines", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" }, - { code: "+66", label: "🇹🇭 +66", country: "Thailand", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" }, - { code: "+84", label: "🇻🇳 +84", country: "Vietnam", currency: "USD", minLength: 9, maxLength: 10, placeholder: "9 to 10 digits" }, + { iso2: "AU", 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" }, + { iso2: "JP", 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" }, + { iso2: "KR", 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" }, + { iso2: "TW", 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" }, + { iso2: "MY", 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" }, + { iso2: "PH", 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" }, + { iso2: "VN", code: "+84", label: "🇻🇳 +84", country: "Vietnam", currency: "USD", minLength: 9, maxLength: 10, placeholder: "9 to 10 digits" }, // Middle East - { code: "+971", label: "🇦🇪 +971", country: "UAE", 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" }, - { code: "+974", label: "🇶🇦 +974", country: "Qatar", 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" }, - { code: "+968", label: "🇴🇲 +968", country: "Oman", 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" }, - { code: "+972", label: "🇮🇱 +972", country: "Israel", 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" }, - { code: "+961", label: "🇱🇧 +961", country: "Lebanon", currency: "USD", minLength: 7, maxLength: 8, placeholder: "7 to 8 digits" }, + { iso2: "AE", 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" }, + { iso2: "QA", 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" }, + { iso2: "OM", 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" }, + { iso2: "IL", 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" }, + { iso2: "LB", code: "+961", label: "🇱🇧 +961", country: "Lebanon", currency: "USD", minLength: 7, maxLength: 8, placeholder: "7 to 8 digits" }, // Latin America - { code: "+55", label: "🇧🇷 +55", country: "Brazil", 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" }, - { code: "+56", label: "🇨🇱 +56", country: "Chile", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" }, - { code: "+57", label: "🇨🇴 +57", country: "Colombia", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" }, - { code: "+51", label: "🇵🇪 +51", country: "Peru", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" }, + { iso2: "BR", 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" }, + { iso2: "CL", 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" }, + { iso2: "PE", code: "+51", label: "🇵🇪 +51", country: "Peru", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" }, // Africa - { code: "+27", label: "🇿🇦 +27", country: "South Africa", currency: "USD", minLength: 9, maxLength: 10, placeholder: "9 to 10 digits" }, - { code: "+234", label: "🇳🇬 +234", country: "Nigeria", currency: "USD", minLength: 10, maxLength: 11, placeholder: "10 to 11 digits" }, - { code: "+254", label: "🇰🇪 +254", country: "Kenya", 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" }, - { code: "+20", label: "🇪🇬 +20", country: "Egypt", currency: "USD", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" }, - { code: "+212", label: "🇲🇦 +212", country: "Morocco", currency: "USD", minLength: 9, maxLength: 9, placeholder: "9-digit mobile number" }, - { code: "+230", label: "🇲🇺 +230", country: "Mauritius", currency: "USD", minLength: 7, maxLength: 8, placeholder: "7 to 8 digits" }, + { iso2: "ZA", 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" }, + { iso2: "KE", 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" }, + { iso2: "EG", 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" }, + { iso2: "MU", 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) => a.country.localeCompare(b.country) ); -export const getCountryRuleByDialCode = (dialCode: string): CountryCode => { - return ( - COUNTRY_CODES.find((c) => c.code === dialCode) || { - code: dialCode, - label: dialCode, - country: "Other", - currency: "USD", - minLength: 7, - maxLength: 15, - placeholder: "Phone number", - } - ); +export const DEFAULT_COUNTRY = COUNTRY_CODES[0]; // India (+91) + +export const getCountryRuleByIso = (iso?: string | null): CountryCode => { + if (!iso) return DEFAULT_COUNTRY; + const upper = iso.toUpperCase().trim(); + return COUNTRY_CODES.find((c) => c.iso2 === upper) || DEFAULT_COUNTRY; }; -export const getCountryRuleByName = (countryName: string): CountryCode => { +export const getCountryRuleByName = (countryName?: string | null): CountryCode => { if (!countryName) return DEFAULT_COUNTRY; const normalized = countryName.toLowerCase().trim(); return ( COUNTRY_CODES.find( (c) => c.country.toLowerCase() === normalized || + c.iso2.toLowerCase() === normalized || normalized.includes(c.country.toLowerCase()) ) || { + iso2: "IN", code: "+91", label: "🇮🇳 +91", country: countryName, @@ -136,6 +133,32 @@ export const getCountryRuleByName = (countryName: string): 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 = ( val?: string | null, dialCode?: string, @@ -149,8 +172,8 @@ export const validatePhoneNumber = ( return "Phone number cannot contain alphabetic characters."; } - // Strictly disallow hyphens, dashes, and invalid characters - if (/[\-()_]/.test(trimmed)) { + // Strictly disallow hyphens, dashes, and invalid symbols + if (/[\-_()/[\]]/.test(trimmed)) { return "Phone number cannot contain hyphens or special symbols."; } @@ -164,67 +187,79 @@ export const validatePhoneNumber = ( return "Please enter a valid phone number with numeric digits."; } - let rule = dialCode ? getCountryRuleByDialCode(dialCode) : undefined; - if ((!rule || rule.country === "Other") && country) { - rule = getCountryRuleByName(country); + let rule = country ? getCountryRuleByName(country) : undefined; + if (!rule && dialCode) { + rule = getCountryRuleByDialCode(dialCode, country); } - // If still not found and input starts with '+', match from COUNTRY_CODES - if (!rule && trimmed.startsWith("+")) { - const sorted = [...COUNTRY_CODES].sort((a, b) => b.code.length - a.code.length); - rule = sorted.find((c) => trimmed.startsWith(c.code)); - } - if (!rule || rule.country === "Other") { - if (dialCode === "+91" || (country && country.toLowerCase() === "india")) { - rule = getCountryRuleByDialCode("+91"); - } + if (!rule) { + rule = DEFAULT_COUNTRY; } - if (rule && rule.country !== "Other") { + const iso2 = rule.iso2 || "IN"; + + // Format candidate string for libphonenumber-js + let fullToParse = trimmed; + if (!fullToParse.startsWith("+")) { const dialDigits = rule.code.replace(/\D/g, ""); - let localDigits = allDigits; - - if (trimmed.startsWith("+")) { - // Input includes country code prefix (e.g. +919876543210 or +9198765432) - // Must strip the dial code to extract the actual local number - if (allDigits.startsWith(dialDigits)) { - localDigits = allDigits.slice(dialDigits.length); - } - } else if (allDigits.length > rule.maxLength && allDigits.startsWith(dialDigits)) { - // Input was formatted with dial digits without '+' and exceeds local maxLength (e.g. 919876543210) - localDigits = allDigits.slice(dialDigits.length); - } - - if (rule.minLength === rule.maxLength) { - if (localDigits.length !== rule.minLength) { - return `${rule.country} phone number must be exactly ${rule.minLength} digits.`; - } + if (allDigits.startsWith(dialDigits) && allDigits.length > rule.maxLength) { + fullToParse = `+${allDigits}`; } else { - if (localDigits.length < rule.minLength) { - return `${rule.country} phone number must be at least ${rule.minLength} digits.`; - } - if (localDigits.length > rule.maxLength) { - return `${rule.country} phone number cannot exceed ${rule.maxLength} digits.`; - } + fullToParse = `${rule.code}${allDigits}`; } + } - // Specific country telecom prefix rules - if (dialDigits === "91" || rule.country === "India") { - if (!/^[6-9]/.test(localDigits)) { + const parsed = parsePhoneNumberFromString(fullToParse, iso2); + + if (parsed && parsed.isValid()) { + const numberType = parsed.getType(); + + if (iso2 === "IN") { + if (!/^[6-9]/.test(parsed.nationalNumber)) { return "India mobile number must begin with 6, 7, 8, or 9."; } + } else if (iso2 === "FR") { + if (numberType === "FIXED_LINE" || !/^[67]/.test(parsed.nationalNumber)) { + return "France mobile number must begin with 06 or 07 (or 6 or 7)."; + } + } else if (iso2 === "GB") { + if (numberType === "FIXED_LINE" || !/^7/.test(parsed.nationalNumber)) { + return "United Kingdom mobile number must begin with 07 (or 7)."; + } + } else if (numberType === "FIXED_LINE") { + return `Please enter a valid mobile number for ${rule.country}.`; } return null; } - // General fallback ITU E.164 - if (allDigits.length < 7) { - return "Phone number must contain at least 7 digits."; + const nationalDigitsOnly = allDigits.startsWith(rule.code.replace(/\D/g, "")) + ? allDigits.slice(rule.code.replace(/\D/g, "").length) + : allDigits; + + const lenStatus = validatePhoneNumberLength(nationalDigitsOnly, iso2); + if (lenStatus === "TOO_SHORT") { + return `${rule.country} phone number is too short (min ${rule.minLength} digits).`; } - if (allDigits.length > 15) { - return "Phone number cannot exceed 15 digits."; + if (lenStatus === "TOO_LONG") { + return `${rule.country} phone number cannot exceed ${rule.maxLength} digits.`; } - return null; + if (lenStatus === "INVALID_LENGTH") { + return rule.minLength === rule.maxLength + ? `${rule.country} phone number must be exactly ${rule.minLength} digits.` + : `${rule.country} phone number must be between ${rule.minLength} and ${rule.maxLength} digits.`; + } + + if (iso2 === "FR") { + return "France mobile number must begin with 06 or 07 (or 6 or 7)."; + } + if (iso2 === "IN") { + return "India mobile number must begin with 6, 7, 8, or 9."; + } + if (iso2 === "GB") { + return "United Kingdom mobile number must begin with 07 (or 7)."; + } + + return `Please enter a valid mobile number for ${rule.country} (e.g. ${rule.placeholder}).`; }; export const isValidPhoneNumber = ( @@ -241,14 +276,28 @@ export const isValidPhoneNumber = ( export const parsePhoneNumber = ( fullPhone?: string | null, fallbackCountry = "India" -): { country: string; dialCode: string; localDigits: string } => { - const defaultRule = getCountryRuleByName(fallbackCountry) || getCountryRuleByDialCode("+91"); +): { 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: "" }; + 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 trimmed = fullPhone.trim(); - // Try matching dial code prefixes from longest to shortest const sorted = [...COUNTRY_CODES].sort((a, b) => b.code.length - a.code.length); const matched = sorted.find((c) => trimmed.startsWith(c.code)); if (matched) { @@ -257,34 +306,43 @@ export const parsePhoneNumber = ( country: matched.country, dialCode: matched.code, localDigits: rawLocal.slice(0, matched.maxLength), + iso2: matched.iso2, }; } - // If no '+' prefix, check if digits start with fallback country dial digits and exceed national length - const dialDigits = defaultRule.code.replace(/\D/g, ""); const rawDigits = trimmed.replace(/\D/g, ""); - let local = rawDigits; - if ( - dialDigits && - rawDigits.startsWith(dialDigits) && - rawDigits.length > defaultRule.maxLength - ) { - local = rawDigits.slice(dialDigits.length); - } return { country: defaultRule.country, dialCode: defaultRule.code, - localDigits: local.slice(0, defaultRule.maxLength), + localDigits: rawDigits.slice(0, defaultRule.maxLength), + iso2: defaultRule.iso2, }; }; /** - * Formats full phone number cleanly as E.164 without spaces (+) + * Formats full phone number cleanly as E.164 without spaces (+), + * automatically stripping any national trunk '0' where appropriate. */ -export const formatE164Phone = (dialCode: string, localDigits: string): string => { - const digits = localDigits.replace(/\D/g, ""); +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}`; - return digits ? `${code}${digits}` : ""; + 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}`; }; /** @@ -316,35 +374,13 @@ export const updatePhoneDialCode = ( const oldRule = getCountryRuleByName(oldCountry); const newRule = getCountryRuleByName(newCountry); - // Extract national digits without any dial code - 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 > oldRule.maxLength) { - nationalDigits = rawDigits.slice(oldDialDigits.length); - } else { - nationalDigits = rawDigits; - } - } - - const bounded = nationalDigits.slice(0, newRule.maxLength); + const parsed = parsePhoneNumber(trimmed, oldRule.country); + const bounded = parsed.localDigits.slice(0, newRule.maxLength); return bounded ? `${newRule.code} ${bounded}` : `${newRule.code} `; }; /** * 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,}$/; diff --git a/src/features/auth/components/SignUpForm.tsx b/src/features/auth/components/SignUpForm.tsx index a433da0..7e04514 100644 --- a/src/features/auth/components/SignUpForm.tsx +++ b/src/features/auth/components/SignUpForm.tsx @@ -25,9 +25,11 @@ import { AuthColors } from "../constants/colors"; import { Colors } from "@/theme"; import { CountryCode, + COUNTRY_CODES, DEFAULT_COUNTRY, SORTED_COUNTRY_CODES, validatePhoneNumber, + formatE164Phone, validateEmail, } from "@/constants/countries"; import { useAuthStore } from "@/store/auth.store"; @@ -175,7 +177,7 @@ export default function SignUpForm() { setIsLoading(true); try { const formattedPhone = phone.trim() - ? `${selectedCountry.code}${phone.trim()}` + ? formatE164Phone(selectedCountry.code, phone.trim(), selectedCountry.country) : undefined; const response = await register({ diff --git a/src/features/profile/components/EditProfileForm.tsx b/src/features/profile/components/EditProfileForm.tsx index 2dba791..fe2f7cc 100644 --- a/src/features/profile/components/EditProfileForm.tsx +++ b/src/features/profile/components/EditProfileForm.tsx @@ -141,7 +141,7 @@ export default function EditProfileForm({ if (trimmedPhone) { const rule = getCountryRuleByName(country); const parsed = parsePhoneNumber(trimmedPhone, country); - normalizedPhone = formatE164Phone(rule.code, parsed.localDigits); + normalizedPhone = formatE164Phone(rule.code, parsed.localDigits, country); } onSave?.(trimmedName, normalizedPhone, country); From b2fe1e635e5de2283754b397ac4432a09041b35b Mon Sep 17 00:00:00 2001 From: Urvish Date: Mon, 16 Nov 2026 16:30:50 +0530 Subject: [PATCH 7/7] fix(validation): prioritize length errors over prefix errors in phone validation --- src/constants/countries.ts | 111 ++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 51 deletions(-) diff --git a/src/constants/countries.ts b/src/constants/countries.ts index 5f290c5..9f17821 100644 --- a/src/constants/countries.ts +++ b/src/constants/countries.ts @@ -1,4 +1,4 @@ -import { parsePhoneNumberFromString, validatePhoneNumberLength, type CountryCode as LibCountryCode } from "libphonenumber-js/max"; +import { parsePhoneNumberFromString, type CountryCode as LibCountryCode } from "libphonenumber-js/max"; export interface CountryCode { iso2: LibCountryCode; @@ -197,68 +197,77 @@ export const validatePhoneNumber = ( const iso2 = rule.iso2 || "IN"; - // Format candidate string for libphonenumber-js - let fullToParse = trimmed; - if (!fullToParse.startsWith("+")) { - const dialDigits = rule.code.replace(/\D/g, ""); - if (allDigits.startsWith(dialDigits) && allDigits.length > rule.maxLength) { - fullToParse = `+${allDigits}`; + // Extract national digits without dial code prefix + let nationalDigits = allDigits; + const dialDigits = rule.code.replace(/\D/g, ""); + if (trimmed.startsWith("+")) { + if (allDigits.startsWith(dialDigits)) { + nationalDigits = allDigits.slice(dialDigits.length); + } + } else if (allDigits.startsWith(dialDigits) && allDigits.length > rule.maxLength) { + nationalDigits = 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 (digitsWithoutTrunk0.length !== rule.minLength && nationalDigits.length !== rule.minLength) { + return `${rule.country} mobile number must be exactly ${rule.minLength} digits.`; + } } else { - fullToParse = `${rule.code}${allDigits}`; + if (digitsWithoutTrunk0.length < rule.minLength && nationalDigits.length < rule.minLength) { + return `${rule.country} mobile number is too short (min ${rule.minLength} digits).`; + } + if (digitsWithoutTrunk0.length > rule.maxLength) { + return `${rule.country} mobile number cannot exceed ${rule.maxLength} digits.`; + } } } - const parsed = parsePhoneNumberFromString(fullToParse, iso2); + // 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 (iso2 === "IN") { - if (!/^[6-9]/.test(parsed.nationalNumber)) { - return "India mobile number must begin with 6, 7, 8, or 9."; - } - } else if (iso2 === "FR") { - if (numberType === "FIXED_LINE" || !/^[67]/.test(parsed.nationalNumber)) { - return "France mobile number must begin with 06 or 07 (or 6 or 7)."; - } - } else if (iso2 === "GB") { - if (numberType === "FIXED_LINE" || !/^7/.test(parsed.nationalNumber)) { - return "United Kingdom mobile number must begin with 07 (or 7)."; - } - } else if (numberType === "FIXED_LINE") { + if (numberType === "FIXED_LINE") { return `Please enter a valid mobile number for ${rule.country}.`; } - return null; } - const nationalDigitsOnly = allDigits.startsWith(rule.code.replace(/\D/g, "")) - ? allDigits.slice(rule.code.replace(/\D/g, "").length) - : allDigits; - - const lenStatus = validatePhoneNumberLength(nationalDigitsOnly, iso2); - if (lenStatus === "TOO_SHORT") { - return `${rule.country} phone number is too short (min ${rule.minLength} digits).`; - } - if (lenStatus === "TOO_LONG") { - return `${rule.country} phone number cannot exceed ${rule.maxLength} digits.`; - } - if (lenStatus === "INVALID_LENGTH") { - return rule.minLength === rule.maxLength - ? `${rule.country} phone number must be exactly ${rule.minLength} digits.` - : `${rule.country} phone number must be between ${rule.minLength} and ${rule.maxLength} digits.`; - } - - if (iso2 === "FR") { - return "France mobile number must begin with 06 or 07 (or 6 or 7)."; - } - if (iso2 === "IN") { - return "India mobile number must begin with 6, 7, 8, or 9."; - } - if (iso2 === "GB") { - return "United Kingdom mobile number must begin with 07 (or 7)."; - } - return `Please enter a valid mobile number for ${rule.country} (e.g. ${rule.placeholder}).`; };