PR review

This commit is contained in:
Erik Jan de Wit 2023-07-03 15:10:32 +02:00 committed by Pedro Igor
parent 95d5fae3b3
commit 359ece98f9
2 changed files with 10 additions and 13 deletions

View file

@ -29,9 +29,9 @@ export async function getPersonalInfo({
return parseResponse<UserRepresentation>(response); return parseResponse<UserRepresentation>(response);
} }
export async function getSupportedLocales({ signal }: CallOptions = {}): Promise< export async function getSupportedLocales({
string[] signal,
> { }: CallOptions = {}): Promise<string[]> {
const response = await request("/supportedLocales", { signal }); const response = await request("/supportedLocales", { signal });
return parseResponse<string[]>(response); return parseResponse<string[]>(response);
} }

View file

@ -2,7 +2,7 @@ import { useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import type { Option } from "ui-shared"; import type { Option } from "ui-shared";
import { SelectControl } from "ui-shared"; import { SelectControl } from "ui-shared";
import { supportedLocales } from "../api/methods"; import { getSupportedLocales } from "../api/methods";
import { usePromise } from "../utils/usePromise"; import { usePromise } from "../utils/usePromise";
const localeToDisplayName = (locale: string) => { const localeToDisplayName = (locale: string) => {
@ -18,22 +18,19 @@ export const LocaleSelector = () => {
const [locales, setLocales] = useState<Option[]>([]); const [locales, setLocales] = useState<Option[]>([]);
usePromise( usePromise(
(signal) => supportedLocales({ signal }), (signal) => getSupportedLocales({ signal }),
(locales) => (locales) =>
setLocales( setLocales(
locales.map<Option>( locales.map<Option>((locale) => ({
(l) => key: locale,
({ value: localeToDisplayName(locale) || "",
key: l, }))
value: localeToDisplayName(l),
})
)
) )
); );
return ( return (
<SelectControl <SelectControl
id="locale-select" data-testid="locale-select"
name="attributes.locale" name="attributes.locale"
label={t("selectALocale")} label={t("selectALocale")}
controller={{ defaultValue: "" }} controller={{ defaultValue: "" }}