changed how errors are displayed (#2066)
This commit is contained in:
parent
35ef6aff88
commit
c84c983415
4 changed files with 56 additions and 28 deletions
|
@ -17,39 +17,49 @@ export const OpenIdConnectSettings = () => {
|
||||||
|
|
||||||
const adminClient = useAdminClient();
|
const adminClient = useAdminClient();
|
||||||
const { realm } = useRealm();
|
const { realm } = useRealm();
|
||||||
const { setValue, errors, setError } = useFormContext();
|
const { setValue, errors, setError, clearErrors } = useFormContext();
|
||||||
|
|
||||||
const setupForm = (result: any) => {
|
const setupForm = (result: any) => {
|
||||||
Object.keys(result).map((k) => setValue(`config.${k}`, result[k]));
|
Object.keys(result).map((k) => setValue(`config.${k}`, result[k]));
|
||||||
};
|
};
|
||||||
|
|
||||||
const fileUpload = async (obj?: object) => {
|
const fileUpload = async (obj?: object) => {
|
||||||
if (obj) {
|
clearErrors("discoveryError");
|
||||||
const formData = new FormData();
|
if (!obj) {
|
||||||
formData.append("providerId", id);
|
return;
|
||||||
formData.append("file", new Blob([JSON.stringify(obj)]));
|
}
|
||||||
|
|
||||||
try {
|
const formData = new FormData();
|
||||||
const response = await fetch(
|
formData.append("providerId", id);
|
||||||
`${getBaseUrl(
|
formData.append("file", new Blob([JSON.stringify(obj)]));
|
||||||
adminClient
|
|
||||||
)}admin/realms/${realm}/identity-provider/import-config`,
|
try {
|
||||||
{
|
const response = await fetch(
|
||||||
method: "POST",
|
`${getBaseUrl(
|
||||||
body: formData,
|
adminClient
|
||||||
headers: {
|
)}admin/realms/${realm}/identity-provider/import-config`,
|
||||||
Authorization: `bearer ${await adminClient.getAccessToken()}`,
|
{
|
||||||
},
|
method: "POST",
|
||||||
}
|
body: formData,
|
||||||
);
|
headers: {
|
||||||
|
Authorization: `Bearer ${await adminClient.getAccessToken()}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (response.ok) {
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
setupForm(result);
|
setupForm(result);
|
||||||
} catch (error) {
|
} else {
|
||||||
setError("discoveryError", {
|
setError("discoveryError", {
|
||||||
type: "manual",
|
type: "manual",
|
||||||
message: (error as Error).message,
|
message: response.statusText,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
setError("discoveryError", {
|
||||||
|
type: "manual",
|
||||||
|
message: (error as Error).message,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -72,7 +82,7 @@ export const OpenIdConnectSettings = () => {
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
validated={errors.discoveryError ? "error" : "default"}
|
validated={errors.discoveryError ? "error" : "default"}
|
||||||
helperTextInvalid={errors.discoveryError}
|
helperTextInvalid={errors.discoveryError?.message}
|
||||||
>
|
>
|
||||||
<JsonFileUpload
|
<JsonFileUpload
|
||||||
id="kc-import-config"
|
id="kc-import-config"
|
||||||
|
|
|
@ -20,7 +20,8 @@ export const SamlConnectSettings = () => {
|
||||||
|
|
||||||
const adminClient = useAdminClient();
|
const adminClient = useAdminClient();
|
||||||
const { realm } = useRealm();
|
const { realm } = useRealm();
|
||||||
const { setValue, register, errors, setError } = useFormContext();
|
const { setValue, register, errors, setError, clearErrors } =
|
||||||
|
useFormContext();
|
||||||
|
|
||||||
const setupForm = (result: IdentityProviderRepresentation) => {
|
const setupForm = (result: IdentityProviderRepresentation) => {
|
||||||
Object.entries(result).map(([key, value]) =>
|
Object.entries(result).map(([key, value]) =>
|
||||||
|
@ -29,6 +30,10 @@ export const SamlConnectSettings = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const fileUpload = async (xml: string) => {
|
const fileUpload = async (xml: string) => {
|
||||||
|
clearErrors("discoveryError");
|
||||||
|
if (!xml) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("providerId", id);
|
formData.append("providerId", id);
|
||||||
formData.append("file", new Blob([xml]));
|
formData.append("file", new Blob([xml]));
|
||||||
|
@ -46,8 +51,15 @@ export const SamlConnectSettings = () => {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const result = await response.json();
|
if (response.ok) {
|
||||||
setupForm(result);
|
const result = await response.json();
|
||||||
|
setupForm(result);
|
||||||
|
} else {
|
||||||
|
setError("discoveryError", {
|
||||||
|
type: "manual",
|
||||||
|
message: response.statusText,
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError("discoveryError", {
|
setError("discoveryError", {
|
||||||
type: "manual",
|
type: "manual",
|
||||||
|
@ -99,7 +111,7 @@ export const SamlConnectSettings = () => {
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
validated={errors.discoveryError ? "error" : "default"}
|
validated={errors.discoveryError ? "error" : "default"}
|
||||||
helperTextInvalid={errors.discoveryError}
|
helperTextInvalid={errors.discoveryError?.message}
|
||||||
>
|
>
|
||||||
<FileUploadForm
|
<FileUploadForm
|
||||||
id="kc-import-config"
|
id="kc-import-config"
|
||||||
|
|
|
@ -82,7 +82,10 @@ export const DiscoveryEndpointField = ({
|
||||||
label={t("common:on")}
|
label={t("common:on")}
|
||||||
labelOff={t("common:off")}
|
labelOff={t("common:off")}
|
||||||
isChecked={discovery}
|
isChecked={discovery}
|
||||||
onChange={setDiscovery}
|
onChange={(checked) => {
|
||||||
|
clearErrors("discoveryError");
|
||||||
|
setDiscovery(checked);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
{discovery && (
|
{discovery && (
|
||||||
|
@ -109,7 +112,9 @@ export const DiscoveryEndpointField = ({
|
||||||
helperTextInvalid={
|
helperTextInvalid={
|
||||||
errors.discoveryEndpoint
|
errors.discoveryEndpoint
|
||||||
? t("common:required")
|
? t("common:required")
|
||||||
: t("noValidMetaDataFound")
|
: t("noValidMetaDataFound", {
|
||||||
|
error: errors.discoveryError?.message,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
isRequired
|
isRequired
|
||||||
>
|
>
|
||||||
|
|
|
@ -98,7 +98,8 @@ export default {
|
||||||
importConfig: "Import config from file",
|
importConfig: "Import config from file",
|
||||||
showMetaData: "Show metadata",
|
showMetaData: "Show metadata",
|
||||||
hideMetaData: "Hide metadata",
|
hideMetaData: "Hide metadata",
|
||||||
noValidMetaDataFound: "No valid metadata was found at this URL",
|
noValidMetaDataFound:
|
||||||
|
"No valid metadata was found at this URL: '{{error}}'",
|
||||||
advanced: "Advanced",
|
advanced: "Advanced",
|
||||||
metadataOfDiscoveryEndpoint: "Metadata of the discovery endpoint",
|
metadataOfDiscoveryEndpoint: "Metadata of the discovery endpoint",
|
||||||
authorizationUrl: "Authorization URL",
|
authorizationUrl: "Authorization URL",
|
||||||
|
|
Loading…
Reference in a new issue