Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LF-4056b Fix for language selector dropdown #3436

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions packages/webapp/src/components/Profile/Account/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import useGenderOptions from '../../../hooks/useGenderOptions';
import useLanguageOptionsMap from '../../../hooks/useLanguageOptions';

const useLanguageOptions = (language_preference) => {
const languageOptionMap = useLanguageOptionsMap();
const languageOptions = Object.values(languageOptionMap);
const languageOptions = useLanguageOptionsMap();
const languagePreferenceOptionRef = useRef();
languagePreferenceOptionRef.current =
languageOptionMap[language_preference] || language_preference;
return { languageOptionMap, languageOptions, languagePreferenceOptionRef };
languageOptions.find(({ value }) => value === language_preference) || language_preference;
return { languageOptions, languagePreferenceOptionRef };
};

export default function PureAccount({ userFarm, onSubmit, history, isAdmin }) {
Expand All @@ -42,14 +41,10 @@ export default function PureAccount({ userFarm, onSubmit, history, isAdmin }) {
shouldUnregister: true,
});
useEffect(() => {
// get proper translations for the selected options right after language preference is updated
setValue(userFarmEnum.language_preference, null, { shouldValidate: false, shouldDirty: false });
setTimeout(() => {
setValue(userFarmEnum.language_preference, languagePreferenceOptionRef.current, {
shouldValidate: false,
shouldDirty: false,
});
}, 100);
setValue(userFarmEnum.language_preference, languagePreferenceOptionRef.current, {
shouldValidate: false,
shouldDirty: false,
});
}, [userFarm.language_preference]);
const disabled = !isDirty || !isValid;
return (
Expand Down
5 changes: 1 addition & 4 deletions packages/webapp/src/hooks/useLanguageOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>.
*/
import { useTranslation } from 'react-i18next';

const supportedLanguages = [
['en', 'English'],
Expand All @@ -26,11 +25,9 @@ const supportedLanguages = [
];

const useLanguageOptions = () => {
const { t } = useTranslation();

return supportedLanguages.map(([value, text]) => ({
value,
label: t(text),
label: text,
}));
};

Expand Down