From 9b3cd978c3c82863b6f4b2526ecc28217f0c00cb Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Mon, 15 Nov 2021 08:30:53 +0100 Subject: [PATCH] fixes: #1514 (#1551) --- src/clients/keys/SamlKeys.tsx | 4 ++++ src/clients/keys/SamlKeysDialog.tsx | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/clients/keys/SamlKeys.tsx b/src/clients/keys/SamlKeys.tsx index 4447259eac..e016007172 100644 --- a/src/clients/keys/SamlKeys.tsx +++ b/src/clients/keys/SamlKeys.tsx @@ -225,6 +225,10 @@ export const SamlKeys = ({ clientId, save }: SamlKeysProps) => { save(); setRefresh(refresh + 1); }} + onCancel={() => { + setValue(KEYS_MAPPING[selectedType!].name, "false"); + setIsChanged(undefined); + }} /> )} diff --git a/src/clients/keys/SamlKeysDialog.tsx b/src/clients/keys/SamlKeysDialog.tsx index 56a79e63f0..8f14756a86 100644 --- a/src/clients/keys/SamlKeysDialog.tsx +++ b/src/clients/keys/SamlKeysDialog.tsx @@ -34,6 +34,7 @@ type SamlKeysDialogProps = { id: string; attr: KeyTypes; onClose: () => void; + onCancel: () => void; }; export type SamlKeysDialogForm = KeyStoreConfig & { @@ -65,11 +66,21 @@ export const submitForm = async ( } }; -export const SamlKeysDialog = ({ id, attr, onClose }: SamlKeysDialogProps) => { +export const SamlKeysDialog = ({ + id, + attr, + onClose, + onCancel, +}: SamlKeysDialogProps) => { const { t } = useTranslation("clients"); const [type, setType] = useState(false); const [keys, setKeys] = useState(); - const { register, control, handleSubmit } = useForm(); + const { + register, + control, + handleSubmit, + formState: { isDirty }, + } = useForm(); const adminClient = useAdminClient(); const { addAlert, addError } = useAlerts(); @@ -122,6 +133,7 @@ export const SamlKeysDialog = ({ id, attr, onClose }: SamlKeysDialogProps) => { key="confirm" data-testid="confirm" variant="primary" + isDisabled={!isDirty && !keys} onClick={() => { if (type) { handleSubmit(submit)(); @@ -136,7 +148,7 @@ export const SamlKeysDialog = ({ id, attr, onClose }: SamlKeysDialogProps) => { key="cancel" data-testid="cancel" variant={ButtonVariant.link} - onClick={onClose} + onClick={onCancel} > {t("common:cancel")} ,