|
|
@ -182,6 +182,8 @@ export function QuestionBirthplace({ |
|
|
return () => window.removeEventListener("keydown", handleKeyDown); |
|
|
return () => window.removeEventListener("keydown", handleKeyDown); |
|
|
}, [isOpen, closeSheet]); |
|
|
}, [isOpen, closeSheet]); |
|
|
|
|
|
|
|
|
|
|
|
const lastInternalAnswerRef = useRef<string | null>(null); |
|
|
|
|
|
|
|
|
const updateAnswers = (country: string, city: string) => { |
|
|
const updateAnswers = (country: string, city: string) => { |
|
|
const cleanCountry = country?.trim() || ""; |
|
|
const cleanCountry = country?.trim() || ""; |
|
|
const cleanCity = city?.trim() || ""; |
|
|
const cleanCity = city?.trim() || ""; |
|
|
@ -189,6 +191,7 @@ export function QuestionBirthplace({ |
|
|
cleanCity && cleanCountry |
|
|
cleanCity && cleanCountry |
|
|
? `${cleanCity}, ${cleanCountry}` |
|
|
? `${cleanCity}, ${cleanCountry}` |
|
|
: cleanCity || cleanCountry || null; |
|
|
: cleanCity || cleanCountry || null; |
|
|
|
|
|
lastInternalAnswerRef.current = formatted; |
|
|
setAnswerValue(question, formatted); |
|
|
setAnswerValue(question, formatted); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
@ -266,8 +269,11 @@ export function QuestionBirthplace({ |
|
|
updateAnswers(country, city); |
|
|
updateAnswers(country, city); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
// Synchronize state if rawValue changes externally
|
|
|
|
|
|
|
|
|
// Synchronize state ONLY if rawValue changes externally (e.g. draft fetch or reset)
|
|
|
useEffect(() => { |
|
|
useEffect(() => { |
|
|
|
|
|
if (rawValue === lastInternalAnswerRef.current) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
const updated = parseValue(rawValue); |
|
|
const updated = parseValue(rawValue); |
|
|
const resolvedC = resolveCountryName(updated.country, locale); |
|
|
const resolvedC = resolveCountryName(updated.country, locale); |
|
|
if (resolvedC && resolvedC !== selectedCountry) { |
|
|
if (resolvedC && resolvedC !== selectedCountry) { |
|
|
|