Browse Source

fix(birthplace): prevent country state from being overwritten when typing city

master
mortezaei 3 days ago
parent
commit
55d64b6d03
  1. 8
      src/components/Componentes/question-birthplace.tsx

8
src/components/Componentes/question-birthplace.tsx

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

Loading…
Cancel
Save