|
|
@ -66,22 +66,22 @@ export function parseValue(rawValue: unknown): { country: string; city: string } |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
if (str.includes(",")) { |
|
|
if (str.includes(",")) { |
|
|
const idx = str.lastIndexOf(","); |
|
|
|
|
|
const cityPart = str.slice(0, idx).trim(); |
|
|
|
|
|
const countryPart = str.slice(idx + 1).trim(); |
|
|
|
|
|
return { city: cityPart, country: countryPart }; |
|
|
|
|
|
|
|
|
const idx = str.indexOf(","); |
|
|
|
|
|
const countryPart = str.slice(0, idx).trim(); |
|
|
|
|
|
const cityPart = str.slice(idx + 1).trim(); |
|
|
|
|
|
return { country: countryPart, city: cityPart }; |
|
|
} |
|
|
} |
|
|
if (str.includes("،")) { |
|
|
if (str.includes("،")) { |
|
|
const idx = str.lastIndexOf("،"); |
|
|
|
|
|
const cityPart = str.slice(0, idx).trim(); |
|
|
|
|
|
const countryPart = str.slice(idx + 1).trim(); |
|
|
|
|
|
return { city: cityPart, country: countryPart }; |
|
|
|
|
|
|
|
|
const idx = str.indexOf("،"); |
|
|
|
|
|
const countryPart = str.slice(0, idx).trim(); |
|
|
|
|
|
const cityPart = str.slice(idx + 1).trim(); |
|
|
|
|
|
return { country: countryPart, city: cityPart }; |
|
|
} |
|
|
} |
|
|
if (str.includes(" - ")) { |
|
|
if (str.includes(" - ")) { |
|
|
const idx = str.lastIndexOf(" - "); |
|
|
|
|
|
const cityPart = str.slice(0, idx).trim(); |
|
|
|
|
|
const countryPart = str.slice(idx + 3).trim(); |
|
|
|
|
|
return { city: cityPart, country: countryPart }; |
|
|
|
|
|
|
|
|
const idx = str.indexOf(" - "); |
|
|
|
|
|
const countryPart = str.slice(0, idx).trim(); |
|
|
|
|
|
const cityPart = str.slice(idx + 3).trim(); |
|
|
|
|
|
return { country: countryPart, city: cityPart }; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (isKnownCountry(str)) { |
|
|
if (isKnownCountry(str)) { |
|
|
@ -113,7 +113,7 @@ export function QuestionBirthplace({ |
|
|
const initialCity = initial.city || storedRegion?.city || ""; |
|
|
const initialCity = initial.city || storedRegion?.city || ""; |
|
|
const initialLoc = |
|
|
const initialLoc = |
|
|
localizedInitialCountry || initialCity |
|
|
localizedInitialCountry || initialCity |
|
|
? [initialCity, localizedInitialCountry].filter(Boolean).join(", ") |
|
|
|
|
|
|
|
|
? [localizedInitialCountry, initialCity].filter(Boolean).join(", ") |
|
|
: ""; |
|
|
: ""; |
|
|
|
|
|
|
|
|
const [selectedCountry, setSelectedCountry] = useState( |
|
|
const [selectedCountry, setSelectedCountry] = useState( |
|
|
@ -182,9 +182,9 @@ export function QuestionBirthplace({ |
|
|
const cleanCountry = country?.trim() || ""; |
|
|
const cleanCountry = country?.trim() || ""; |
|
|
const cleanCity = city?.trim() || ""; |
|
|
const cleanCity = city?.trim() || ""; |
|
|
const formatted = |
|
|
const formatted = |
|
|
cleanCity && cleanCountry |
|
|
|
|
|
? `${cleanCity}, ${cleanCountry}` |
|
|
|
|
|
: cleanCity || cleanCountry || null; |
|
|
|
|
|
|
|
|
cleanCountry && cleanCity |
|
|
|
|
|
? `${cleanCountry}, ${cleanCity}` |
|
|
|
|
|
: cleanCountry || cleanCity || null; |
|
|
lastInternalAnswerRef.current = formatted; |
|
|
lastInternalAnswerRef.current = formatted; |
|
|
setAnswerValue(question, formatted); |
|
|
setAnswerValue(question, formatted); |
|
|
}; |
|
|
}; |
|
|
@ -196,7 +196,7 @@ export function QuestionBirthplace({ |
|
|
const parsed = parseValue(rawValue); |
|
|
const parsed = parseValue(rawValue); |
|
|
const cName = resolveCountryName(parsed.country, locale) || parsed.country; |
|
|
const cName = resolveCountryName(parsed.country, locale) || parsed.country; |
|
|
if (cName || parsed.city) { |
|
|
if (cName || parsed.city) { |
|
|
const loc = [parsed.city, cName].filter(Boolean).join(", "); |
|
|
|
|
|
|
|
|
const loc = [cName, parsed.city].filter(Boolean).join(", "); |
|
|
if (cName) setSelectedCountry(cName); |
|
|
if (cName) setSelectedCountry(cName); |
|
|
if (parsed.city) setCityInput(parsed.city); |
|
|
if (parsed.city) setCityInput(parsed.city); |
|
|
setDetectedLocation(loc); |
|
|
setDetectedLocation(loc); |
|
|
@ -215,10 +215,10 @@ export function QuestionBirthplace({ |
|
|
const rawCountry = region.country || region.countryCode || ""; |
|
|
const rawCountry = region.country || region.countryCode || ""; |
|
|
const country = resolveCountryName(rawCountry, locale) || rawCountry; |
|
|
const country = resolveCountryName(rawCountry, locale) || rawCountry; |
|
|
|
|
|
|
|
|
if (city || country) { |
|
|
|
|
|
const loc = [city, country].filter(Boolean).join(", "); |
|
|
|
|
|
|
|
|
if (country || city) { |
|
|
setSelectedCountry(country); |
|
|
setSelectedCountry(country); |
|
|
setCityInput(city); |
|
|
setCityInput(city); |
|
|
|
|
|
const loc = [country, city].filter(Boolean).join(", "); |
|
|
setDetectedLocation(loc); |
|
|
setDetectedLocation(loc); |
|
|
updateAnswers(country, city); |
|
|
updateAnswers(country, city); |
|
|
setMode("auto"); |
|
|
setMode("auto"); |
|
|
@ -234,7 +234,7 @@ export function QuestionBirthplace({ |
|
|
setIsDetecting(false); |
|
|
setIsDetecting(false); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}, [rawValue, locale]); |
|
|
|
|
|
|
|
|
}, [rawValue, locale, question, setAnswerValue]); |
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
useEffect(() => { |
|
|
if (isLoading) return; |
|
|
if (isLoading) return; |
|
|
@ -264,7 +264,7 @@ export function QuestionBirthplace({ |
|
|
setSelectedCountry(country); |
|
|
setSelectedCountry(country); |
|
|
setCityInput(city); |
|
|
setCityInput(city); |
|
|
updateAnswers(country, city); |
|
|
updateAnswers(country, city); |
|
|
setDetectedLocation([city, country].filter(Boolean).join(", ")); |
|
|
|
|
|
|
|
|
setDetectedLocation([country, city].filter(Boolean).join(", ")); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
// Synchronize state ONLY if rawValue changes externally (e.g. draft fetch or reset)
|
|
|
// Synchronize state ONLY if rawValue changes externally (e.g. draft fetch or reset)
|
|
|
@ -274,14 +274,6 @@ export function QuestionBirthplace({ |
|
|
} |
|
|
} |
|
|
const updated = parseValue(rawValue); |
|
|
const updated = parseValue(rawValue); |
|
|
const resolvedC = resolveCountryName(updated.country, locale) || updated.country; |
|
|
const resolvedC = resolveCountryName(updated.country, locale) || updated.country; |
|
|
console.log("[BIRTHPLACE_DEBUG] 🔄 External sync triggered: " + JSON.stringify({ |
|
|
|
|
|
rawValue, |
|
|
|
|
|
lastInternal: lastInternalAnswerRef.current, |
|
|
|
|
|
parsed: updated, |
|
|
|
|
|
resolvedCountry: resolvedC, |
|
|
|
|
|
currentSelectedCountry: selectedCountry, |
|
|
|
|
|
currentCityInput: cityInput, |
|
|
|
|
|
})); |
|
|
|
|
|
if (resolvedC !== selectedCountry) { |
|
|
if (resolvedC !== selectedCountry) { |
|
|
setSelectedCountry(resolvedC); |
|
|
setSelectedCountry(resolvedC); |
|
|
} |
|
|
} |
|
|
@ -289,7 +281,7 @@ export function QuestionBirthplace({ |
|
|
setCityInput(updated.city); |
|
|
setCityInput(updated.city); |
|
|
} |
|
|
} |
|
|
if (resolvedC || updated.city) { |
|
|
if (resolvedC || updated.city) { |
|
|
setDetectedLocation([updated.city, resolvedC].filter(Boolean).join(", ")); |
|
|
|
|
|
|
|
|
setDetectedLocation([resolvedC, updated.city].filter(Boolean).join(", ")); |
|
|
} |
|
|
} |
|
|
lastInternalAnswerRef.current = typeof rawValue === "string" ? rawValue : null; |
|
|
lastInternalAnswerRef.current = typeof rawValue === "string" ? rawValue : null; |
|
|
}, [rawValue, locale]); |
|
|
}, [rawValue, locale]); |
|
|
@ -303,14 +295,10 @@ export function QuestionBirthplace({ |
|
|
if (typeof window !== "undefined") { |
|
|
if (typeof window !== "undefined") { |
|
|
localStorage.setItem("hasCheckedGeoIPResidence", "true"); |
|
|
localStorage.setItem("hasCheckedGeoIPResidence", "true"); |
|
|
} |
|
|
} |
|
|
console.log("[BIRTHPLACE_DEBUG] 🚩 handleSelectCountry called: " + JSON.stringify({ |
|
|
|
|
|
chosenCountry: country, |
|
|
|
|
|
currentCityInput: cityInput, |
|
|
|
|
|
})); |
|
|
|
|
|
setSelectedCountry(country); |
|
|
setSelectedCountry(country); |
|
|
closeSheet(); |
|
|
closeSheet(); |
|
|
updateAnswers(country, cityInput); |
|
|
updateAnswers(country, cityInput); |
|
|
setDetectedLocation([cityInput, country].filter(Boolean).join(", ")); |
|
|
|
|
|
|
|
|
setDetectedLocation([country, cityInput].filter(Boolean).join(", ")); |
|
|
window.setTimeout(() => { |
|
|
window.setTimeout(() => { |
|
|
cityInputRef.current?.focus({ preventScroll: true }); |
|
|
cityInputRef.current?.focus({ preventScroll: true }); |
|
|
}, EXIT_ANIMATION_MS); |
|
|
}, EXIT_ANIMATION_MS); |
|
|
@ -321,13 +309,9 @@ export function QuestionBirthplace({ |
|
|
localStorage.setItem("hasCheckedGeoIPResidence", "true"); |
|
|
localStorage.setItem("hasCheckedGeoIPResidence", "true"); |
|
|
} |
|
|
} |
|
|
const newCity = e.target.value; |
|
|
const newCity = e.target.value; |
|
|
console.log("[BIRTHPLACE_DEBUG] ✍️ handleCityChange called: " + JSON.stringify({ |
|
|
|
|
|
currentSelectedCountry: selectedCountry, |
|
|
|
|
|
typedCity: newCity, |
|
|
|
|
|
})); |
|
|
|
|
|
setCityInput(newCity); |
|
|
setCityInput(newCity); |
|
|
updateAnswers(selectedCountry, newCity); |
|
|
updateAnswers(selectedCountry, newCity); |
|
|
setDetectedLocation([newCity, selectedCountry].filter(Boolean).join(", ")); |
|
|
|
|
|
|
|
|
setDetectedLocation([selectedCountry, newCity].filter(Boolean).join(", ")); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const isRtl = locale === "fa" || locale === "ar" || locale === "ur"; |
|
|
const isRtl = locale === "fa" || locale === "ar" || locale === "ur"; |
|
|
|