Compare commits
5 Commits
fix/issue-
...
main
| Author | SHA1 | Date |
|---|---|---|
|
|
ededd6f0c1 | |
|
|
053d08eb5d | |
|
|
967aec6403 | |
|
|
5d76e8ba19 | |
|
|
6291c325eb |
|
|
@ -56,10 +56,11 @@ 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, refreshAccess]),
|
}, [accessToken, modulesQuery.refetch, refreshAccess]),
|
||||||
);
|
);
|
||||||
|
|
||||||
const items = useMemo(
|
const items = useMemo(
|
||||||
|
|
|
||||||
|
|
@ -1,353 +1,408 @@
|
||||||
import {
|
import { parsePhoneNumberFromString, type CountryCode as LibCountryCode } from "libphonenumber-js/max";
|
||||||
getCountries,
|
|
||||||
getCountryCallingCode,
|
|
||||||
getExampleNumber,
|
|
||||||
parsePhoneNumberFromString,
|
|
||||||
type CountryCode as LibCountryCode,
|
|
||||||
} from "libphonenumber-js/max";
|
|
||||||
import metadata from "libphonenumber-js/metadata.max.json";
|
|
||||||
import examples from "libphonenumber-js/examples.mobile.json";
|
|
||||||
|
|
||||||
export interface CountryCode {
|
export interface CountryCode {
|
||||||
iso2: LibCountryCode;
|
iso2: LibCountryCode;
|
||||||
code: string;
|
code: string;
|
||||||
label: string;
|
label: string;
|
||||||
country: string;
|
country: string;
|
||||||
|
currency: string;
|
||||||
minLength: number;
|
minLength: number;
|
||||||
maxLength: number;
|
maxLength: number;
|
||||||
placeholder: string;
|
placeholder: string;
|
||||||
validPrefixes?: string[];
|
|
||||||
example?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type CountryMetadataTuple = readonly unknown[];
|
|
||||||
|
|
||||||
interface MetadataJson {
|
|
||||||
countries: Record<string, CountryMetadataTuple>;
|
|
||||||
country_calling_codes: Record<string, string[]>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const typedMetadata = metadata as unknown as MetadataJson;
|
|
||||||
|
|
||||||
/** Converts an ISO 3166-1 alpha-2 code (e.g. "IN") into its Unicode flag emoji. */
|
|
||||||
const isoToFlag = (iso2: string): string => {
|
|
||||||
const upper = iso2.toUpperCase();
|
|
||||||
if (!/^[A-Z]{2}$/.test(upper)) return "🏳️";
|
|
||||||
return String.fromCodePoint(
|
|
||||||
0x1f1e6 + upper.charCodeAt(0) - 65,
|
|
||||||
0x1f1e6 + upper.charCodeAt(1) - 65
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const regionDisplayNames =
|
|
||||||
typeof Intl !== "undefined" && typeof Intl.DisplayNames === "function"
|
|
||||||
? new Intl.DisplayNames(["en"], { type: "region" })
|
|
||||||
: null;
|
|
||||||
|
|
||||||
const getRegionName = (iso2: string): string => {
|
|
||||||
try {
|
|
||||||
return regionDisplayNames?.of(iso2) || iso2;
|
|
||||||
} catch {
|
|
||||||
return iso2;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const buildCountryRule = (iso2: LibCountryCode): CountryCode => {
|
|
||||||
const callingCode = getCountryCallingCode(iso2);
|
|
||||||
const code = `+${callingCode}`;
|
|
||||||
const flag = isoToFlag(iso2);
|
|
||||||
const country = getRegionName(iso2);
|
|
||||||
|
|
||||||
const countryMeta = typedMetadata.countries[iso2];
|
|
||||||
const mobileDesc = countryMeta?.[11] as unknown[] | undefined;
|
|
||||||
const mobileTuple = mobileDesc?.[1] as [string, number[]?] | undefined;
|
|
||||||
const generalLengths = countryMeta?.[3] as number[] | undefined;
|
|
||||||
const mobileLengths = mobileTuple?.[1] ?? generalLengths ?? [7, 15];
|
|
||||||
|
|
||||||
const minLength = Math.min(...mobileLengths);
|
|
||||||
const maxLength = Math.max(...mobileLengths);
|
|
||||||
|
|
||||||
const exampleNumber = getExampleNumber(iso2, examples);
|
|
||||||
const example = exampleNumber?.nationalNumber;
|
|
||||||
const placeholder =
|
|
||||||
minLength === maxLength
|
|
||||||
? `${minLength}-digit mobile number`
|
|
||||||
: `${minLength}-${maxLength} digit mobile number`;
|
|
||||||
|
|
||||||
return {
|
|
||||||
iso2,
|
|
||||||
code,
|
|
||||||
label: `${flag} ${code}`,
|
|
||||||
country,
|
|
||||||
minLength,
|
|
||||||
maxLength,
|
|
||||||
placeholder,
|
|
||||||
example,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// Order primary country per calling code before secondary territories (e.g. US before AG for +1, GB before GG for +44).
|
|
||||||
const isPrimaryForCallingCode = (iso2: LibCountryCode): boolean => {
|
|
||||||
const callingCode = getCountryCallingCode(iso2);
|
|
||||||
return typedMetadata.country_calling_codes[callingCode]?.[0] === iso2;
|
|
||||||
};
|
|
||||||
|
|
||||||
const allCountries = getCountries();
|
|
||||||
export const COUNTRY_CODES: CountryCode[] = [
|
export const COUNTRY_CODES: CountryCode[] = [
|
||||||
...allCountries.filter(isPrimaryForCallingCode),
|
// South Asia
|
||||||
...allCountries.filter((iso) => !isPrimaryForCallingCode(iso)),
|
{ iso2: "IN", code: "+91", label: "🇮🇳 +91", country: "India", currency: "INR", minLength: 10, maxLength: 10, placeholder: "10-digit mobile number" },
|
||||||
].map(buildCountryRule);
|
{ 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
|
||||||
|
{ 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
|
||||||
|
{ 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
|
||||||
|
{ 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
|
||||||
|
{ 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
|
||||||
|
{ 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
|
||||||
|
{ 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 SORTED_COUNTRY_CODES: CountryCode[] = [...COUNTRY_CODES].sort((a, b) =>
|
export const SORTED_COUNTRY_CODES: CountryCode[] = [...COUNTRY_CODES].sort((a, b) =>
|
||||||
a.country.localeCompare(b.country)
|
a.country.localeCompare(b.country)
|
||||||
);
|
);
|
||||||
|
|
||||||
export const DEFAULT_COUNTRY: CountryCode =
|
export const DEFAULT_COUNTRY = COUNTRY_CODES[0]; // India (+91)
|
||||||
COUNTRY_CODES.find((c) => c.iso2 === "IN") ?? COUNTRY_CODES[0];
|
|
||||||
|
|
||||||
export const getCountryRuleByIso = (iso?: string | null): CountryCode => {
|
export const getCountryRuleByIso = (iso?: string | null): CountryCode => {
|
||||||
if (!iso) return DEFAULT_COUNTRY;
|
if (!iso) return DEFAULT_COUNTRY;
|
||||||
const upper = iso.trim().toUpperCase();
|
const upper = iso.toUpperCase().trim();
|
||||||
return COUNTRY_CODES.find((c) => c.iso2 === upper) || DEFAULT_COUNTRY;
|
return COUNTRY_CODES.find((c) => c.iso2 === upper) || DEFAULT_COUNTRY;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getCountryRuleByName = (countryName?: string | null): CountryCode => {
|
export const getCountryRuleByName = (countryName?: string | null): CountryCode => {
|
||||||
if (!countryName) return DEFAULT_COUNTRY;
|
if (!countryName) return DEFAULT_COUNTRY;
|
||||||
const stripped = countryName.replace(/\s*\(\+\d+\)\s*$/, "").trim().toLowerCase();
|
const normalized = countryName.toLowerCase().trim();
|
||||||
if (!stripped) return DEFAULT_COUNTRY;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
COUNTRY_CODES.find(
|
COUNTRY_CODES.find(
|
||||||
(c) =>
|
(c) =>
|
||||||
c.country.toLowerCase() === stripped ||
|
c.country.toLowerCase() === normalized ||
|
||||||
c.iso2.toLowerCase() === stripped
|
c.iso2.toLowerCase() === normalized ||
|
||||||
) ||
|
normalized.includes(c.country.toLowerCase())
|
||||||
COUNTRY_CODES.find(
|
) || {
|
||||||
(c) =>
|
iso2: "IN",
|
||||||
c.country.toLowerCase().startsWith(stripped) ||
|
code: "+91",
|
||||||
stripped.startsWith(c.country.toLowerCase())
|
label: "🇮🇳 +91",
|
||||||
) ||
|
country: countryName,
|
||||||
DEFAULT_COUNTRY
|
currency: normalized === "india" ? "INR" : "USD",
|
||||||
|
minLength: 7,
|
||||||
|
maxLength: 15,
|
||||||
|
placeholder: "Phone number",
|
||||||
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getCountryRuleByDialCode = (
|
export const getCountryRuleByDialCode = (dialCode?: string | null, countryHint?: string | null): CountryCode => {
|
||||||
dialCode?: string | null,
|
|
||||||
countryHint?: string | null
|
|
||||||
): CountryCode => {
|
|
||||||
if (!dialCode) return DEFAULT_COUNTRY;
|
if (!dialCode) return DEFAULT_COUNTRY;
|
||||||
const normalizedDial = dialCode.startsWith("+") ? dialCode : `+${dialCode}`;
|
|
||||||
|
|
||||||
if (countryHint) {
|
if (countryHint) {
|
||||||
const byCountry = getCountryRuleByName(countryHint);
|
const byCountry = getCountryRuleByName(countryHint);
|
||||||
if (byCountry.code === normalizedDial) return byCountry;
|
if (byCountry && byCountry.code === dialCode) {
|
||||||
|
return byCountry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
COUNTRY_CODES.find((c) => c.code === normalizedDial) || DEFAULT_COUNTRY
|
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",
|
||||||
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const extractNationalDigits = (
|
|
||||||
cleaned: string,
|
|
||||||
digitsOnly: string,
|
|
||||||
rule: CountryCode
|
|
||||||
): string => {
|
|
||||||
const dialDigits = rule.code.replace(/\D/g, "");
|
|
||||||
// Try parsing as a national/international number directly for this country first.
|
|
||||||
const direct = parsePhoneNumberFromString(cleaned, rule.iso2);
|
|
||||||
if (direct?.nationalNumber && (!direct.country || direct.country === rule.iso2)) {
|
|
||||||
return direct.nationalNumber;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
digitsOnly.startsWith(dialDigits) &&
|
|
||||||
digitsOnly.length > dialDigits.length + 4
|
|
||||||
) {
|
|
||||||
return digitsOnly.slice(dialDigits.length);
|
|
||||||
}
|
|
||||||
return digitsOnly;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates a mobile phone number generically against the selected country's
|
* Validates mobile phone number according to country telecom numbering plans.
|
||||||
* libphonenumber-js rules, lengths, and number type.
|
* Uses libphonenumber-js to enforce mobile prefixes (e.g., France 06/07, India 6-9, UK 07).
|
||||||
* Returns null if valid, or a descriptive user-friendly error message.
|
|
||||||
*/
|
*/
|
||||||
export const validatePhoneNumber = (
|
export const validatePhoneNumber = (
|
||||||
value: string,
|
val?: string | null,
|
||||||
dialCode?: string,
|
dialCode?: string,
|
||||||
country?: string
|
country?: string
|
||||||
): string | null => {
|
): string | null => {
|
||||||
const trimmed = value.trim();
|
if (!val || !val.trim()) return null;
|
||||||
if (!trimmed) {
|
const trimmed = val.trim();
|
||||||
return "Mobile number is required";
|
|
||||||
|
// Explicitly disallow alphabetic characters
|
||||||
|
if (/[a-zA-Z]/.test(trimmed)) {
|
||||||
|
return "Phone number cannot contain alphabetic characters.";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!/^\+?[\d\s\-()]+$/.test(trimmed)) {
|
// Strictly disallow hyphens, dashes, and invalid symbols
|
||||||
return "Mobile number can only contain digits";
|
if (/[\-_()/[\]]/.test(trimmed)) {
|
||||||
|
return "Phone number cannot contain hyphens or special symbols.";
|
||||||
}
|
}
|
||||||
|
|
||||||
const rule = country
|
// Strictly enforce numeric digits with optional leading '+' and whitespace
|
||||||
? getCountryRuleByName(country)
|
if (!/^\+?[\d\s]+$/.test(trimmed)) {
|
||||||
: dialCode
|
return "Please enter a valid phone number containing only numeric digits.";
|
||||||
? getCountryRuleByDialCode(dialCode, country)
|
|
||||||
: DEFAULT_COUNTRY;
|
|
||||||
|
|
||||||
const cleaned = trimmed.replace(/[\s\-()]/g, "");
|
|
||||||
const digitsOnly = cleaned.replace(/\D/g, "");
|
|
||||||
if (!digitsOnly) {
|
|
||||||
return "Mobile number is required";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const nationalDigits = extractNationalDigits(cleaned, digitsOnly, rule);
|
const allDigits = trimmed.replace(/\D/g, "");
|
||||||
const lengthLabel =
|
if (allDigits.length === 0) {
|
||||||
rule.minLength === rule.maxLength
|
return "Please enter a valid phone number with numeric digits.";
|
||||||
? `exactly ${rule.minLength} digits`
|
|
||||||
: `${rule.minLength} to ${rule.maxLength} digits`;
|
|
||||||
|
|
||||||
if (nationalDigits.length < rule.minLength || nationalDigits.length > rule.maxLength) {
|
|
||||||
return `For ${rule.country}, the mobile number must be ${lengthLabel}.`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const candidate = cleaned.startsWith("+") ? cleaned : `${rule.code}${nationalDigits}`;
|
let rule = country ? getCountryRuleByName(country) : undefined;
|
||||||
const parsed = parsePhoneNumberFromString(candidate, rule.iso2);
|
if (!rule && dialCode) {
|
||||||
|
rule = getCountryRuleByDialCode(dialCode, country);
|
||||||
if (!parsed || !parsed.isValid()) {
|
}
|
||||||
return "Please enter a valid number";
|
if (!rule) {
|
||||||
|
rule = DEFAULT_COUNTRY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const iso2 = rule.iso2 || "IN";
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
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.`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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();
|
const numberType = parsed.getType();
|
||||||
if (numberType && numberType !== "MOBILE" && numberType !== "FIXED_LINE_OR_MOBILE") {
|
if (numberType === "FIXED_LINE") {
|
||||||
return "Please enter a valid number";
|
return `Please enter a valid mobile number for ${rule.country}.`;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return `Please enter a valid mobile number for ${rule.country} (e.g. ${rule.placeholder}).`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const isValidPhoneNumber = (
|
export const isValidPhoneNumber = (
|
||||||
val: string,
|
val?: string | null,
|
||||||
dialCode?: string,
|
dialCode?: string,
|
||||||
country?: string
|
country?: string
|
||||||
): boolean => {
|
): boolean => {
|
||||||
return validatePhoneNumber(val, dialCode, country) === null;
|
return validatePhoneNumber(val, dialCode, country) === null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits a full phone number into dialCode, country, and localDigits
|
||||||
|
*/
|
||||||
export const parsePhoneNumber = (
|
export const parsePhoneNumber = (
|
||||||
fullNumber: string,
|
fullPhone?: string | null,
|
||||||
fallbackCountry?: string
|
fallbackCountry = "India"
|
||||||
): { country: string; dialCode: string; localDigits: string; iso2: LibCountryCode } => {
|
): { country: string; dialCode: string; localDigits: string; iso2: LibCountryCode } => {
|
||||||
const defaultRule = fallbackCountry
|
const defaultRule = getCountryRuleByName(fallbackCountry) || DEFAULT_COUNTRY;
|
||||||
? getCountryRuleByName(fallbackCountry)
|
if (!fullPhone || !fullPhone.trim()) {
|
||||||
: DEFAULT_COUNTRY;
|
return { country: defaultRule.country, dialCode: defaultRule.code, localDigits: "", iso2: defaultRule.iso2 };
|
||||||
const trimmed = (fullNumber || "").trim();
|
|
||||||
if (!trimmed) {
|
|
||||||
return {
|
|
||||||
country: defaultRule.country,
|
|
||||||
dialCode: defaultRule.code,
|
|
||||||
localDigits: "",
|
|
||||||
iso2: defaultRule.iso2,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const trimmed = fullPhone.trim();
|
||||||
const parsed = parsePhoneNumberFromString(trimmed, defaultRule.iso2);
|
const parsed = parsePhoneNumberFromString(trimmed, defaultRule.iso2);
|
||||||
if (parsed && parsed.countryCallingCode) {
|
|
||||||
|
if (parsed) {
|
||||||
const matchedRule = parsed.country
|
const matchedRule = parsed.country
|
||||||
? getCountryRuleByIso(parsed.country)
|
? getCountryRuleByIso(parsed.country)
|
||||||
: getCountryRuleByDialCode(`+${parsed.countryCallingCode}`, fallbackCountry);
|
: getCountryRuleByDialCode(`+${parsed.countryCallingCode}`, fallbackCountry);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
country: matchedRule.country,
|
country: matchedRule.country,
|
||||||
dialCode: matchedRule.code,
|
dialCode: `+${parsed.countryCallingCode}`,
|
||||||
localDigits: parsed.nationalNumber,
|
localDigits: parsed.nationalNumber,
|
||||||
iso2: matchedRule.iso2,
|
iso2: matchedRule.iso2,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const cleaned = trimmed.replace(/[\s\-()]/g, "");
|
|
||||||
if (cleaned.startsWith("+")) {
|
|
||||||
const sorted = [...COUNTRY_CODES].sort((a, b) => b.code.length - a.code.length);
|
const sorted = [...COUNTRY_CODES].sort((a, b) => b.code.length - a.code.length);
|
||||||
for (const c of sorted) {
|
const matched = sorted.find((c) => trimmed.startsWith(c.code));
|
||||||
if (cleaned.startsWith(c.code)) {
|
if (matched) {
|
||||||
|
const rawLocal = trimmed.slice(matched.code.length).replace(/\D/g, "");
|
||||||
return {
|
return {
|
||||||
country: c.country,
|
country: matched.country,
|
||||||
dialCode: c.code,
|
dialCode: matched.code,
|
||||||
localDigits: cleaned.slice(c.code.length).replace(/\D/g, ""),
|
localDigits: rawLocal.slice(0, matched.maxLength),
|
||||||
iso2: c.iso2,
|
iso2: matched.iso2,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const rawDigits = trimmed.replace(/\D/g, "");
|
||||||
return {
|
return {
|
||||||
country: defaultRule.country,
|
country: defaultRule.country,
|
||||||
dialCode: defaultRule.code,
|
dialCode: defaultRule.code,
|
||||||
localDigits: cleaned.replace(/\D/g, ""),
|
localDigits: rawDigits.slice(0, defaultRule.maxLength),
|
||||||
iso2: defaultRule.iso2,
|
iso2: defaultRule.iso2,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const formatE164Phone = (
|
/**
|
||||||
dialCode: string,
|
* Formats full phone number cleanly as E.164 without spaces (+<dialCode><digits>),
|
||||||
localDigits: string,
|
* automatically stripping any national trunk '0' where appropriate.
|
||||||
country?: string
|
*/
|
||||||
): string => {
|
export const formatE164Phone = (dialCode: string, localDigits: string, country?: string): string => {
|
||||||
const rule = country
|
if (!localDigits || !localDigits.trim()) return "";
|
||||||
? getCountryRuleByName(country)
|
const rule = country ? getCountryRuleByName(country) : getCountryRuleByDialCode(dialCode, country);
|
||||||
: getCountryRuleByDialCode(dialCode, country);
|
const rawDigits = localDigits.replace(/\D/g, "");
|
||||||
const cleaned = (localDigits || "").trim().replace(/[\s\-()]/g, "");
|
if (!rawDigits) return "";
|
||||||
if (!cleaned) return "";
|
|
||||||
|
const code = dialCode.startsWith("+") ? dialCode : `+${dialCode}`;
|
||||||
|
const candidate = localDigits.startsWith("+") ? localDigits : `${code}${rawDigits}`;
|
||||||
|
|
||||||
const digits = cleaned.replace(/\D/g, "");
|
|
||||||
const nationalDigits = extractNationalDigits(cleaned, digits, rule);
|
|
||||||
const candidate = cleaned.startsWith("+") ? cleaned : `${rule.code}${nationalDigits}`;
|
|
||||||
const parsed = parsePhoneNumberFromString(candidate, rule.iso2);
|
const parsed = parsePhoneNumberFromString(candidate, rule.iso2);
|
||||||
if (parsed) {
|
if (parsed && parsed.isValid()) {
|
||||||
return parsed.number;
|
return parsed.format("E.164");
|
||||||
}
|
}
|
||||||
|
|
||||||
return nationalDigits ? `${rule.code}${nationalDigits}` : "";
|
let cleanLocal = rawDigits;
|
||||||
};
|
if (rule.iso2 !== "IT" && cleanLocal.startsWith("0")) {
|
||||||
|
cleanLocal = cleanLocal.replace(/^0+/, "");
|
||||||
export const cleanPhoneInput = (text: string, maxLength = 15): string => {
|
|
||||||
if (!text) return "";
|
|
||||||
const trimmed = text.trim();
|
|
||||||
if (trimmed.startsWith("+")) {
|
|
||||||
const digitsOnly = trimmed.slice(1).replace(/\D/g, "");
|
|
||||||
return `+${digitsOnly}`.slice(0, maxLength + 1);
|
|
||||||
}
|
}
|
||||||
return trimmed.replace(/\D/g, "").slice(0, maxLength);
|
|
||||||
|
return `${code}${cleanLocal}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strips non-numeric / non-phone characters from text in real-time
|
||||||
|
* If maxLength is provided, strictly restricts digit length
|
||||||
|
* If allowPlus is false, strips any '+' symbols as well (for local number inputs)
|
||||||
|
*/
|
||||||
|
export const cleanPhoneInput = (text: string, maxLength = 16, allowPlus = true): string => {
|
||||||
|
const trimmedStart = text.trimStart();
|
||||||
|
const hasPlus = allowPlus && trimmedStart.startsWith("+");
|
||||||
|
const rest = hasPlus ? trimmedStart.slice(1) : text;
|
||||||
|
const digitsOnly = rest.replace(/\D/g, "");
|
||||||
|
const boundedDigits = maxLength ? digitsOnly.slice(0, maxLength) : digitsOnly;
|
||||||
|
return hasPlus ? `+${boundedDigits}` : boundedDigits;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the dial code prefix of an existing phone number when country changes.
|
||||||
|
* Automatically clamps remaining digits to the new country's maxLength.
|
||||||
|
*/
|
||||||
export const updatePhoneDialCode = (
|
export const updatePhoneDialCode = (
|
||||||
currentValue: string,
|
currentPhone: string,
|
||||||
oldCountry: string,
|
oldCountry: string,
|
||||||
newCountry: string
|
newCountry: string
|
||||||
): string => {
|
): string => {
|
||||||
const trimmed = (currentValue || "").trim();
|
const trimmed = currentPhone.trim();
|
||||||
|
if (!trimmed) return "";
|
||||||
|
|
||||||
const oldRule = getCountryRuleByName(oldCountry);
|
const oldRule = getCountryRuleByName(oldCountry);
|
||||||
const newRule = getCountryRuleByName(newCountry);
|
const newRule = getCountryRuleByName(newCountry);
|
||||||
|
|
||||||
const parsed = parsePhoneNumber(trimmed, oldRule.country);
|
const parsed = parsePhoneNumber(trimmed, oldRule.country);
|
||||||
if (!parsed.localDigits) return "";
|
const bounded = parsed.localDigits.slice(0, newRule.maxLength);
|
||||||
|
return bounded ? `${newRule.code} ${bounded}` : `${newRule.code} `;
|
||||||
return formatE164Phone(newRule.code, parsed.localDigits, newRule.country);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const EMAIL_REGEX = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
/**
|
||||||
|
* RFC 5322 & RFC 1035 compliant email validation regex.
|
||||||
|
*/
|
||||||
|
export const EMAIL_REGEX = /^[a-zA-Z0-9_%+-]+(?:\.[a-zA-Z0-9_%+-]+)*@[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$/;
|
||||||
|
|
||||||
export const validateEmail = (value: string): string | null => {
|
export const validateEmail = (email?: string | null): string | null => {
|
||||||
const trimmed = value.trim();
|
if (!email || !email.trim()) {
|
||||||
if (!trimmed) {
|
|
||||||
return "Email is required";
|
return "Email is required";
|
||||||
}
|
}
|
||||||
if (trimmed.includes(" ")) {
|
if (!EMAIL_REGEX.test(email.trim())) {
|
||||||
return "Email cannot contain spaces";
|
|
||||||
}
|
|
||||||
if (!EMAIL_REGEX.test(trimmed)) {
|
|
||||||
return "Please enter a valid email address";
|
return "Please enter a valid email address";
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const isValidEmail = (val: string): boolean => {
|
export const isValidEmail = (email?: string | null): boolean => {
|
||||||
return validateEmail(val) === null;
|
return validateEmail(email) === null;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -20,31 +20,27 @@ interface LoginTabsProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function LoginTabs({
|
export default function LoginTabs({
|
||||||
activeTab: _activeTab,
|
activeTab,
|
||||||
onTabChange: _onTabChange,
|
onTabChange,
|
||||||
}: LoginTabsProps) {
|
}: LoginTabsProps) {
|
||||||
// Temporarily hidden: restore return JSX below (and Phone tab inside) when multi-tab login is re-enabled
|
|
||||||
return null;
|
|
||||||
|
|
||||||
/*
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<Pressable
|
<Pressable
|
||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
accessibilityLabel="Login with Email"
|
accessibilityLabel="Login with Email"
|
||||||
style={styles.tab}
|
style={styles.tab}
|
||||||
onPress={() => _onTabChange("email")}
|
onPress={() => onTabChange("email")}
|
||||||
>
|
>
|
||||||
<Text
|
<Text
|
||||||
style={[
|
style={[
|
||||||
styles.text,
|
styles.text,
|
||||||
_activeTab === "email" && styles.activeText,
|
activeTab === "email" && styles.activeText,
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
Email
|
Email
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
{_activeTab === "email" && (
|
{activeTab === "email" && (
|
||||||
<View style={styles.indicator} />
|
<View style={styles.indicator} />
|
||||||
)}
|
)}
|
||||||
</Pressable>
|
</Pressable>
|
||||||
|
|
@ -53,24 +49,23 @@ export default function LoginTabs({
|
||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
accessibilityLabel="Login with Phone"
|
accessibilityLabel="Login with Phone"
|
||||||
style={styles.tab}
|
style={styles.tab}
|
||||||
onPress={() => _onTabChange("phone")}
|
onPress={() => onTabChange("phone")}
|
||||||
>
|
>
|
||||||
<Text
|
<Text
|
||||||
style={[
|
style={[
|
||||||
styles.text,
|
styles.text,
|
||||||
_activeTab === "phone" && styles.activeText,
|
activeTab === "phone" && styles.activeText,
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
Phone
|
Phone
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
{_activeTab === "phone" && (
|
{activeTab === "phone" && (
|
||||||
<View style={styles.indicator} />
|
<View style={styles.indicator} />
|
||||||
)}
|
)}
|
||||||
</Pressable>
|
</Pressable>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
|
|
|
||||||
|
|
@ -261,11 +261,7 @@ export default function SignUpForm() {
|
||||||
<TextInput
|
<TextInput
|
||||||
value={phone}
|
value={phone}
|
||||||
onChangeText={handlePhoneChange}
|
onChangeText={handlePhoneChange}
|
||||||
placeholder={
|
placeholder={selectedCountry.placeholder || "Phone Number (Optional)"}
|
||||||
selectedCountry.example
|
|
||||||
? `e.g. ${selectedCountry.example}`
|
|
||||||
: selectedCountry.placeholder || "Phone Number (Optional)"
|
|
||||||
}
|
|
||||||
placeholderTextColor={AuthColors.textSecondary}
|
placeholderTextColor={AuthColors.textSecondary}
|
||||||
keyboardType="number-pad"
|
keyboardType="number-pad"
|
||||||
autoCapitalize="none"
|
autoCapitalize="none"
|
||||||
|
|
|
||||||
|
|
@ -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: 10 * 60 * 1000,
|
staleTime: 30 * 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 { humanizeKey } from "./helpers/value";
|
import { buildDefinitionLabelMap, humanizeKey, resolveAttributeLabel } 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,10 +40,7 @@ export function GenericDetailRenderer({
|
||||||
);
|
);
|
||||||
|
|
||||||
const definitionMap = useMemo(
|
const definitionMap = useMemo(
|
||||||
() =>
|
() => buildDefinitionLabelMap(definitions),
|
||||||
new Map(
|
|
||||||
(definitions ?? []).map((d) => [d.code, d.label]),
|
|
||||||
),
|
|
||||||
[definitions],
|
[definitions],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -73,8 +70,7 @@ export function GenericDetailRenderer({
|
||||||
!(isTherapeutic && key.toLowerCase() === "name"),
|
!(isTherapeutic && key.toLowerCase() === "name"),
|
||||||
)
|
)
|
||||||
.map(([key, value]) => {
|
.map(([key, value]) => {
|
||||||
const rawLabel = definitionMap.get(key) || key;
|
const label = resolveAttributeLabel(key, definitionMap);
|
||||||
const label = humanizeKey(rawLabel);
|
|
||||||
return (
|
return (
|
||||||
<SectionCard key={key} title={label}>
|
<SectionCard key={key} title={label}>
|
||||||
<ContentValue value={value} />
|
<ContentValue value={value} />
|
||||||
|
|
|
||||||
|
|
@ -549,7 +549,13 @@ export function GynecologyDiseaseCollectionRenderer(
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|
||||||
return <CollectionScaffold {...props} header={header} />;
|
return (
|
||||||
|
<CollectionScaffold
|
||||||
|
{...props}
|
||||||
|
header={header}
|
||||||
|
countLabel="Identifications of patterns"
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createGynecologyDiseaseCollectionRenderer(templateCode: string) {
|
export function createGynecologyDiseaseCollectionRenderer(templateCode: string) {
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,21 @@ 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 { asNumber, asString, asStringArray, humanizeKey } from "../helpers/value";
|
import {
|
||||||
|
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,
|
||||||
|
|
@ -35,6 +43,10 @@ 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-");
|
||||||
|
|
@ -70,6 +82,16 @@ 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",
|
||||||
|
|
@ -138,8 +160,8 @@ export function PatternAccordionCardRenderer({
|
||||||
? rawManifestations.split("\n").map((s) => s.trim()).filter(Boolean)
|
? rawManifestations.split("\n").map((s) => s.trim()).filter(Boolean)
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
const tongue = asString(detailData.tongue);
|
const tongue = stripTrailingPeriod(asString(detailData.tongue));
|
||||||
const pulse = asString(detailData.pulse);
|
const pulse = stripTrailingPeriod(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)
|
||||||
|
|
@ -213,7 +235,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}>
|
||||||
Clinical Manifestations
|
{resolveAttributeLabel("clinical_manifestations", labelMap, "Clinical Manifestations")}
|
||||||
</Text>
|
</Text>
|
||||||
<View style={accordionStyles.bulletList}>
|
<View style={accordionStyles.bulletList}>
|
||||||
{clinicalManifestations.map((itemText, idx) => (
|
{clinicalManifestations.map((itemText, idx) => (
|
||||||
|
|
@ -226,22 +248,23 @@ export function PatternAccordionCardRenderer({
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{/* 2. Tongue & Pulse (Side-by-Side as drawn) */}
|
{/* 2. Tongue */}
|
||||||
{tongue || pulse ? (
|
|
||||||
<View style={accordionStyles.twoColumnBox}>
|
|
||||||
{tongue ? (
|
{tongue ? (
|
||||||
<View style={accordionStyles.column}>
|
<View style={accordionStyles.section}>
|
||||||
<Text style={accordionStyles.columnLabel}>Tongue</Text>
|
<Text style={accordionStyles.sectionTitle}>
|
||||||
<Text style={accordionStyles.columnValue}>{tongue}</Text>
|
{resolveAttributeLabel("tongue", labelMap, "Tongue")}
|
||||||
|
</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.column}>
|
<View style={accordionStyles.section}>
|
||||||
<Text style={accordionStyles.columnLabel}>Pulse</Text>
|
<Text style={accordionStyles.sectionTitle}>
|
||||||
<Text style={accordionStyles.columnValue}>{pulse}</Text>
|
{resolveAttributeLabel("pulse", labelMap, "Pulse")}
|
||||||
</View>
|
</Text>
|
||||||
) : null}
|
<Text style={accordionStyles.sectionText}>{pulse}</Text>
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
|
@ -249,7 +272,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}>
|
||||||
Treatment Principle
|
{resolveAttributeLabel("treatment_principle", labelMap, "Treatment Principle")}
|
||||||
</Text>
|
</Text>
|
||||||
<View style={accordionStyles.bulletList}>
|
<View style={accordionStyles.bulletList}>
|
||||||
{treatmentPrinciples.map((itemText, idx) => (
|
{treatmentPrinciples.map((itemText, idx) => (
|
||||||
|
|
@ -262,13 +285,12 @@ export function PatternAccordionCardRenderer({
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{/* 4. Acupuncture Points & Method */}
|
{/* 4. Acupuncture Points */}
|
||||||
{pointChips.length > 0 || acuMethod ? (
|
{pointChips.length > 0 ? (
|
||||||
<View style={accordionStyles.section}>
|
<View style={accordionStyles.section}>
|
||||||
<Text style={accordionStyles.sectionTitle}>
|
<Text style={accordionStyles.sectionTitle}>
|
||||||
Acupuncture Points
|
{resolveAttributeLabel("acupuncture", labelMap, "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
|
||||||
|
|
@ -291,13 +313,16 @@ 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}
|
||||||
|
|
||||||
|
|
@ -305,7 +330,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}>
|
||||||
Explanation
|
{resolveAttributeLabel("explanation", labelMap, "Explanation")}
|
||||||
</Text>
|
</Text>
|
||||||
<View style={accordionStyles.explanationList}>
|
<View style={accordionStyles.explanationList}>
|
||||||
{explanations.map((exp, idx) => (
|
{explanations.map((exp, idx) => (
|
||||||
|
|
@ -321,7 +346,9 @@ export function PatternAccordionCardRenderer({
|
||||||
{/* 6. Category */}
|
{/* 6. Category */}
|
||||||
{category ? (
|
{category ? (
|
||||||
<View style={accordionStyles.categoryRow}>
|
<View style={accordionStyles.categoryRow}>
|
||||||
<Text style={accordionStyles.categoryLabel}>Category:</Text>
|
<Text style={accordionStyles.categoryLabel}>
|
||||||
|
{`${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>
|
||||||
|
|
@ -495,8 +522,7 @@ const accordionStyles = StyleSheet.create({
|
||||||
lineHeight: moderateScale(16),
|
lineHeight: moderateScale(16),
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: "#4A6B5B",
|
color: "#4A6B5B",
|
||||||
textTransform: "uppercase",
|
letterSpacing: 0.15,
|
||||||
letterSpacing: 0.7,
|
|
||||||
},
|
},
|
||||||
bulletList: {
|
bulletList: {
|
||||||
gap: verticalScale(8),
|
gap: verticalScale(8),
|
||||||
|
|
@ -519,38 +545,10 @@ const accordionStyles = StyleSheet.create({
|
||||||
lineHeight: moderateScale(21),
|
lineHeight: moderateScale(21),
|
||||||
color: "#334155",
|
color: "#334155",
|
||||||
},
|
},
|
||||||
twoColumnBox: {
|
sectionText: {
|
||||||
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(20),
|
lineHeight: moderateScale(21),
|
||||||
color: "#1E293B",
|
color: "#334155",
|
||||||
fontWeight: "600",
|
|
||||||
},
|
},
|
||||||
principleBox: {
|
principleBox: {
|
||||||
backgroundColor: greenTone.soft,
|
backgroundColor: greenTone.soft,
|
||||||
|
|
@ -591,23 +589,6 @@ 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),
|
||||||
},
|
},
|
||||||
|
|
@ -640,8 +621,7 @@ const accordionStyles = StyleSheet.create({
|
||||||
lineHeight: moderateScale(15),
|
lineHeight: moderateScale(15),
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: "#597064",
|
color: "#597064",
|
||||||
textTransform: "uppercase",
|
letterSpacing: 0.15,
|
||||||
letterSpacing: 0.5,
|
|
||||||
},
|
},
|
||||||
categoryBadge: {
|
categoryBadge: {
|
||||||
backgroundColor: "#EEF7F1",
|
backgroundColor: "#EEF7F1",
|
||||||
|
|
|
||||||
|
|
@ -234,8 +234,7 @@ const styles = StyleSheet.create({
|
||||||
lineHeight: 17,
|
lineHeight: 17,
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: "#597064",
|
color: "#597064",
|
||||||
textTransform: "uppercase",
|
letterSpacing: 0.15,
|
||||||
letterSpacing: 0.4,
|
|
||||||
},
|
},
|
||||||
pathway: {
|
pathway: {
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
|
|
|
||||||
|
|
@ -278,7 +278,6 @@ const styles = StyleSheet.create({
|
||||||
lineHeight: 18,
|
lineHeight: 18,
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: "#536F61",
|
color: "#536F61",
|
||||||
textTransform: "uppercase",
|
letterSpacing: 0.15,
|
||||||
letterSpacing: 0.35,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -216,8 +216,7 @@ const styles = StyleSheet.create({
|
||||||
fontSize: moderateScale(12),
|
fontSize: moderateScale(12),
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: Colors.textSecondary,
|
color: Colors.textSecondary,
|
||||||
textTransform: "uppercase",
|
letterSpacing: 0.2,
|
||||||
letterSpacing: 1,
|
|
||||||
marginBottom: verticalScale(12),
|
marginBottom: verticalScale(12),
|
||||||
marginLeft: moderateScale(4),
|
marginLeft: moderateScale(4),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,12 @@ 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 { asString, humanizeKey } from "../helpers/value";
|
import {
|
||||||
|
asString,
|
||||||
|
buildDefinitionLabelMap,
|
||||||
|
humanizeKey,
|
||||||
|
resolveAttributeLabel,
|
||||||
|
} from "../helpers/value";
|
||||||
import {
|
import {
|
||||||
findAttributePresentationRule,
|
findAttributePresentationRule,
|
||||||
isEmptyValue,
|
isEmptyValue,
|
||||||
|
|
@ -41,9 +46,7 @@ export function SixStagesDetailRenderer({
|
||||||
const title = humanizeKey(rawTitle);
|
const title = humanizeKey(rawTitle);
|
||||||
|
|
||||||
const orderedSections = useMemo(() => {
|
const orderedSections = useMemo(() => {
|
||||||
const definitionByLabel = new Map(
|
const definitionByLabel = buildDefinitionLabelMap(definitions);
|
||||||
(definitions ?? []).map((d) => [d.code, d.label]),
|
|
||||||
);
|
|
||||||
|
|
||||||
return Object.entries(data)
|
return Object.entries(data)
|
||||||
.filter(
|
.filter(
|
||||||
|
|
@ -55,8 +58,7 @@ 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 rawLabel = definitionByLabel.get(key) || key;
|
const label = resolveAttributeLabel(key, definitionByLabel);
|
||||||
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,7 +2,12 @@ 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 { asString, humanizeKey } from "../helpers/value";
|
import {
|
||||||
|
asString,
|
||||||
|
buildDefinitionLabelMap,
|
||||||
|
humanizeKey,
|
||||||
|
resolveAttributeLabel,
|
||||||
|
} from "../helpers/value";
|
||||||
import {
|
import {
|
||||||
findAttributePresentationRule,
|
findAttributePresentationRule,
|
||||||
isEmptyValue,
|
isEmptyValue,
|
||||||
|
|
@ -36,9 +41,7 @@ export function TcmPatternDetailRenderer({
|
||||||
const title = humanizeKey(rawTitle);
|
const title = humanizeKey(rawTitle);
|
||||||
|
|
||||||
const orderedSections = useMemo(() => {
|
const orderedSections = useMemo(() => {
|
||||||
const definitionByLabel = new Map(
|
const definitionByLabel = buildDefinitionLabelMap(definitions);
|
||||||
(definitions ?? []).map((d) => [d.code, d.label]),
|
|
||||||
);
|
|
||||||
|
|
||||||
return Object.entries(data)
|
return Object.entries(data)
|
||||||
.filter(
|
.filter(
|
||||||
|
|
@ -49,8 +52,7 @@ 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 rawLabel = definitionByLabel.get(key) || key;
|
const label = resolveAttributeLabel(key, definitionByLabel);
|
||||||
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,8 +452,7 @@ const styles = StyleSheet.create({
|
||||||
lineHeight: 17,
|
lineHeight: 17,
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: "#597064",
|
color: "#597064",
|
||||||
textTransform: "uppercase",
|
letterSpacing: 0.15,
|
||||||
letterSpacing: 0.4,
|
|
||||||
},
|
},
|
||||||
sectionValue: {
|
sectionValue: {
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
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);
|
||||||
|
|
@ -54,3 +56,53 @@ 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 },
|
props: CollectionRendererProps & { header?: React.ReactNode; countLabel?: string },
|
||||||
) {
|
) {
|
||||||
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.total} {props.total === 1 ? "result" : "results"}
|
{props.countLabel ?? `${props.total} ${props.total === 1 ? "result" : "results"}`}
|
||||||
</Text>
|
</Text>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|
@ -86,8 +86,7 @@ const styles = StyleSheet.create({
|
||||||
fontSize: moderateScale(12),
|
fontSize: moderateScale(12),
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: Colors.textSecondary,
|
color: Colors.textSecondary,
|
||||||
textTransform: "uppercase",
|
letterSpacing: 0.2,
|
||||||
letterSpacing: 1,
|
|
||||||
marginBottom: verticalScale(8),
|
marginBottom: verticalScale(8),
|
||||||
marginLeft: moderateScale(4),
|
marginLeft: moderateScale(4),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -217,7 +217,6 @@ const styles = StyleSheet.create({
|
||||||
lineHeight: 17,
|
lineHeight: 17,
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: Colors.textSecondary,
|
color: Colors.textSecondary,
|
||||||
textTransform: "uppercase",
|
letterSpacing: 0.15,
|
||||||
letterSpacing: 0.35,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,7 @@ const styles = StyleSheet.create({
|
||||||
lineHeight: 17,
|
lineHeight: 17,
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: "#597064",
|
color: "#597064",
|
||||||
textTransform: "uppercase",
|
letterSpacing: 0.15,
|
||||||
letterSpacing: 0.4,
|
|
||||||
},
|
},
|
||||||
value: { fontSize: 16, lineHeight: 25, color: "#334155" },
|
value: { fontSize: 16, lineHeight: 25, color: "#334155" },
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,6 @@ const styles = StyleSheet.create({
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
lineHeight: 18,
|
lineHeight: 18,
|
||||||
color: "#536F61",
|
color: "#536F61",
|
||||||
textTransform: "uppercase",
|
letterSpacing: 0.15,
|
||||||
letterSpacing: 0.35,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,7 @@ const styles = StyleSheet.create({
|
||||||
lineHeight: 17,
|
lineHeight: 17,
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: "#617468",
|
color: "#617468",
|
||||||
textTransform: "uppercase",
|
letterSpacing: 0.15,
|
||||||
letterSpacing: 0.35,
|
|
||||||
},
|
},
|
||||||
value: { fontSize: 15, lineHeight: 23, color: "#334155" },
|
value: { fontSize: 15, lineHeight: 23, color: "#334155" },
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ 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,6 +224,7 @@ 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");
|
||||||
|
|
||||||
|
|
@ -241,7 +242,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: metadataPlanCode ?? visual?.planCode ?? "",
|
planCode: apiPlanCode ?? metadataPlanCode ?? visual?.planCode ?? "",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import {
|
||||||
SORTED_COUNTRY_CODES,
|
SORTED_COUNTRY_CODES,
|
||||||
getCountryRuleByName,
|
getCountryRuleByName,
|
||||||
validatePhoneNumber,
|
validatePhoneNumber,
|
||||||
|
isValidPhoneNumber,
|
||||||
parsePhoneNumber,
|
parsePhoneNumber,
|
||||||
formatE164Phone,
|
formatE164Phone,
|
||||||
cleanPhoneInput,
|
cleanPhoneInput,
|
||||||
|
|
@ -90,8 +91,10 @@ export default function EditProfileForm({
|
||||||
const cleaned = cleanPhoneInput(text, activeRule.maxLength + activeRule.code.length + 2);
|
const cleaned = cleanPhoneInput(text, activeRule.maxLength + activeRule.code.length + 2);
|
||||||
setPhone(cleaned);
|
setPhone(cleaned);
|
||||||
if (phoneError) {
|
if (phoneError) {
|
||||||
|
if (!cleaned.trim() || isValidPhoneNumber(cleaned, activeRule.code, country)) {
|
||||||
setPhoneError("");
|
setPhoneError("");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCountrySelect = (newCountry: string) => {
|
const handleCountrySelect = (newCountry: string) => {
|
||||||
|
|
@ -172,13 +175,7 @@ export default function EditProfileForm({
|
||||||
<BaseTextInput
|
<BaseTextInput
|
||||||
value={phone}
|
value={phone}
|
||||||
onChangeText={handlePhoneChange}
|
onChangeText={handlePhoneChange}
|
||||||
placeholder={
|
placeholder={activeRule.placeholder ? `e.g. ${activeRule.code} ${activeRule.placeholder}` : `e.g. ${activeRule.code} 9876543210`}
|
||||||
activeRule.example
|
|
||||||
? `e.g. ${activeRule.code} ${activeRule.example}`
|
|
||||||
: activeRule.placeholder
|
|
||||||
? `e.g. ${activeRule.code} ${activeRule.placeholder}`
|
|
||||||
: `e.g. ${activeRule.code} 9876543210`
|
|
||||||
}
|
|
||||||
keyboardType="phone-pad"
|
keyboardType="phone-pad"
|
||||||
maxLength={activeRule.maxLength + activeRule.code.length + 2}
|
maxLength={activeRule.maxLength + activeRule.code.length + 2}
|
||||||
textContentType="telephoneNumber"
|
textContentType="telephoneNumber"
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,9 @@ 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));
|
||||||
}, [refreshSession]),
|
}, [modulesQuery.refetch, refreshSession]),
|
||||||
);
|
);
|
||||||
|
|
||||||
const unlockedModules = useMemo(() => {
|
const unlockedModules = useMemo(() => {
|
||||||
|
|
|
||||||
|
|
@ -77,12 +77,15 @@ 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, refreshAccess]),
|
}, [accessToken, modulesQuery.refetch, refreshAccess]),
|
||||||
);
|
);
|
||||||
|
|
||||||
const items = useMemo(
|
const items = useMemo(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue