Normalize client attributes before saving (#1442)

This commit is contained in:
Jon Koops 2021-10-29 20:28:58 +02:00 committed by GitHub
parent 861ed39dc1
commit 79f8452ab5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,6 +15,7 @@ import { useAlerts } from "../../components/alert/Alerts";
import { ViewHeader } from "../../components/view-header/ViewHeader"; import { ViewHeader } from "../../components/view-header/ViewHeader";
import { useAdminClient } from "../../context/auth/AdminClient"; import { useAdminClient } from "../../context/auth/AdminClient";
import { useRealm } from "../../context/realm-context/RealmContext"; import { useRealm } from "../../context/realm-context/RealmContext";
import { convertFormValuesToObject } from "../../util";
import { toClient } from "../routes/Client"; import { toClient } from "../routes/Client";
import { toClients } from "../routes/Clients"; import { toClients } from "../routes/Clients";
import { CapabilityConfig } from "./CapabilityConfig"; import { CapabilityConfig } from "./CapabilityConfig";
@ -43,8 +44,15 @@ export default function NewClientForm() {
const methods = useForm<ClientRepresentation>({ defaultValues: client }); const methods = useForm<ClientRepresentation>({ defaultValues: client });
const save = async () => { const save = async () => {
const attributes = client.attributes
? convertFormValuesToObject(client.attributes)
: undefined;
try { try {
const newClient = await adminClient.clients.create({ ...client }); const newClient = await adminClient.clients.create({
...client,
attributes,
});
addAlert(t("createSuccess"), AlertVariant.success); addAlert(t("createSuccess"), AlertVariant.success);
history.push( history.push(
toClient({ realm, clientId: newClient.id, tab: "settings" }) toClient({ realm, clientId: newClient.id, tab: "settings" })