import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import { Controller, useFormContext, useWatch } from "react-hook-form"; import { ActionGroup, Button, FormGroup, PageSection, Select, SelectOption, SelectVariant, Switch, TextContent, } from "@patternfly/react-core"; import type RealmRepresentation from "keycloak-admin/lib/defs/realmRepresentation"; import { FormAccess } from "../components/form-access/FormAccess"; import { useServerInfo } from "../context/server-info/ServerInfoProvider"; import { FormPanel } from "../components/scroll-form/FormPanel"; import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable"; import { useAdminClient } from "../context/auth/AdminClient"; import { getBaseUrl } from "../util"; import { ListEmptyState } from "../components/list-empty-state/ListEmptyState"; type LocalizationTabProps = { save: (realm: RealmRepresentation) => void; reset: () => void; refresh: () => void; realm: RealmRepresentation; }; export const LocalizationTab = ({ save, reset, realm, }: LocalizationTabProps) => { const { t } = useTranslation("realm-settings"); const adminClient = useAdminClient(); const [key, setKey] = useState(0); const [supportedLocalesOpen, setSupportedLocalesOpen] = useState(false); const [defaultLocaleOpen, setDefaultLocaleOpen] = useState(false); const { getValues, control, handleSubmit } = useFormContext(); // const [selectedLocale, setSelectedLocale] = useState("en"); const [valueSelected, setValueSelected] = useState(false); const themeTypes = useServerInfo().themes!; const watchSupportedLocales = useWatch({ control, name: "supportedLocales", defaultValue: themeTypes?.account![0].locales, }); const internationalizationEnabled = useWatch({ control, name: "internationalizationEnabled", defaultValue: realm?.internationalizationEnabled, }); const loader = async () => { if (realm) { const response = await fetch( `${getBaseUrl(adminClient)}admin/realms/${realm.realm}/localization/${ getValues("defaultLocale") || "en" }`, { method: "GET", headers: { Authorization: `bearer ${await adminClient.getAccessToken()}`, }, } ); const result = await response.json(); const resultTest = Object.keys(result).map((key) => [key, result[key]]); return resultTest; } return [[]]; }; return ( <> ( )} /> {internationalizationEnabled && ( <> ( )} /> ( )} /> )} {t("messageBundleDescription")}
{}} /> } canSelectAll columns={[ { name: "Key", cellRenderer: (row) => row[0], }, { name: "Value", cellRenderer: (row) => row[1], }, ]} />
); };