From 86b3fb93a9dd2dd53d8dd7d000477541ba517236 Mon Sep 17 00:00:00 2001
From: Jenny <32821331+jenny-s51@users.noreply.github.com>
Date: Mon, 28 Mar 2022 16:54:15 -0400
Subject: [PATCH] Client credentials: "Regenerate" button fix (#2337)
---
src/clients/ClientDetails.tsx | 7 +++++-
src/clients/credentials/ClientSecret.tsx | 9 ++++----
src/clients/credentials/Credentials.tsx | 27 +++++++++++++++++-------
3 files changed, 30 insertions(+), 13 deletions(-)
diff --git a/src/clients/ClientDetails.tsx b/src/clients/ClientDetails.tsx
index af6ae55676..a75fef7f0e 100644
--- a/src/clients/ClientDetails.tsx
+++ b/src/clients/ClientDetails.tsx
@@ -216,6 +216,7 @@ export default function ClientDetails() {
});
const setupForm = (client: ClientRepresentation) => {
+ form.reset({ ...client });
convertToFormValues(client, form.setValue);
form.setValue(
"attributes.request.uris",
@@ -383,7 +384,11 @@ export default function ClientDetails() {
title={{t("credentials")}}
{...route("credentials")}
>
- save()} />
+ save()}
+ />
)}
void;
+ form: UseFormMethods;
};
-export const ClientSecret = ({ secret, toggle }: ClientSecretProps) => {
+export const ClientSecret = ({ secret, toggle, form }: ClientSecretProps) => {
const { t } = useTranslation("clients");
- const { formState } = useFormContext();
+
return (
@@ -29,8 +30,8 @@ export const ClientSecret = ({ secret, toggle }: ClientSecretProps) => {
diff --git a/src/clients/credentials/Credentials.tsx b/src/clients/credentials/Credentials.tsx
index 645a529feb..302acc8287 100644
--- a/src/clients/credentials/Credentials.tsx
+++ b/src/clients/credentials/Credentials.tsx
@@ -1,5 +1,10 @@
import React, { useState } from "react";
-import { Controller, useFormContext, useWatch } from "react-hook-form";
+import {
+ Controller,
+ useFormContext,
+ UseFormMethods,
+ useWatch,
+} from "react-hook-form";
import { useTranslation } from "react-i18next";
import {
ActionGroup,
@@ -29,6 +34,7 @@ import { useAdminClient, useFetch } from "../../context/auth/AdminClient";
import { ClientSecret } from "./ClientSecret";
import { SignedJWT } from "./SignedJWT";
import { X509 } from "./X509";
+import type ClientRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientRepresentation";
type AccessToken = {
registrationAccessToken: string;
@@ -37,9 +43,10 @@ type AccessToken = {
export type CredentialsProps = {
clientId: string;
save: () => void;
+ form: UseFormMethods;
};
-export const Credentials = ({ clientId, save }: CredentialsProps) => {
+export const Credentials = ({ clientId, save, form }: CredentialsProps) => {
const { t } = useTranslation("clients");
const adminClient = useAdminClient();
const { addAlert, addError } = useAlerts();
@@ -51,7 +58,9 @@ export const Credentials = ({ clientId, save }: CredentialsProps) => {
const {
control,
formState: { isDirty },
+ handleSubmit,
} = useFormContext();
+
const clientAuthenticatorType = useWatch({
control: control,
name: "clientAuthenticatorType",
@@ -131,7 +140,12 @@ export const Credentials = ({ clientId, save }: CredentialsProps) => {
return (
-
+
@@ -180,11 +194,7 @@ export const Credentials = ({ clientId, save }: CredentialsProps) => {
{clientAuthenticatorType === "client-jwt" && }
{clientAuthenticatorType === "client-x509" && }
-
@@ -195,6 +205,7 @@ export const Credentials = ({ clientId, save }: CredentialsProps) => {
clientAuthenticatorType === "client-secret-jwt") && (