import React, { useContext, useEffect } from "react"; import { useTranslation } from "react-i18next"; import { FormGroup, TextInput, Form, Switch, TextArea, PageSection, ActionGroup, Button, AlertVariant, } from "@patternfly/react-core"; import { useParams } from "react-router-dom"; import { Controller, useForm } from "react-hook-form"; import { ScrollForm } from "../components/scroll-form/ScrollForm"; import { ClientDescription } from "./ClientDescription"; import { CapabilityConfig } from "./add/CapabilityConfig"; import { RealmContext } from "../components/realm-context/RealmContext"; import { HttpClientContext } from "../http-service/HttpClientContext"; import { ClientRepresentation } from "../realm/models/Realm"; import { convertToMultiline, MultiLineInput, toValue, } from "../components/multi-line-input/MultiLineInput"; import { useAlerts } from "../components/alert/Alerts"; export const ClientSettings = () => { const { t } = useTranslation("clients"); const httpClient = useContext(HttpClientContext)!; const { realm } = useContext(RealmContext); const [addAlert, Alerts] = useAlerts(); const { id } = useParams<{ id: string }>(); const form = useForm(); const url = `/admin/realms/${realm}/clients/${id}`; useEffect(() => { (async () => { const fetchedClient = await httpClient.doGet(url); if (fetchedClient.data) { Object.entries(fetchedClient.data).map((entry) => { if (entry[0] !== "redirectUris") { form.setValue(entry[0], entry[1]); } else if (entry[1] && entry[1].length > 0) { form.setValue(entry[0], convertToMultiline(entry[1])); } }); } })(); }, []); const save = async () => { if (await form.trigger()) { const redirectUris = toValue(form.getValues()["redirectUris"]); try { httpClient.doPut(url, { ...form.getValues(), redirectUris }); addAlert(t("clientSaveSuccess"), AlertVariant.success); } catch (error) { addAlert(`${t("clientSaveError")} '${error}'`, AlertVariant.danger); } } }; return (
( )} /> ( )} />