From 4eb0b90d757d4b6f962be1d9ead321fc0fa644e2 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Mon, 13 Jun 2022 11:42:00 +0200 Subject: [PATCH] Changed error and success message (#2785) --- public/resources/en/realm-settings.json | 2 ++ src/realm-settings/LoginTab.tsx | 41 ++++++++++++------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/public/resources/en/realm-settings.json b/public/resources/en/realm-settings.json index 142709fbc0..81fac270fc 100644 --- a/public/resources/en/realm-settings.json +++ b/public/resources/en/realm-settings.json @@ -118,6 +118,8 @@ "verifyEmailHelpText": "Require user to verify their email address after initial login or after address changes are submitted.", "userInfoSettings": "User info settings", "editUsername": "Edit username", + "enableSwitchSuccess": "{{switch}} changed successfully", + "enableSwitchError": "Could not enable / disable due to {{error}}", "testConnection": "Test connection", "testConnectionSuccess": "Success! SMTP connection successful. E-mail was sent!", "testConnectionError": "Error! Failed to send email.", diff --git a/src/realm-settings/LoginTab.tsx b/src/realm-settings/LoginTab.tsx index 9cf06ac47d..e4738908b0 100644 --- a/src/realm-settings/LoginTab.tsx +++ b/src/realm-settings/LoginTab.tsx @@ -1,11 +1,6 @@ import React from "react"; import { useTranslation } from "react-i18next"; -import { - AlertVariant, - FormGroup, - PageSection, - Switch, -} from "@patternfly/react-core"; +import { FormGroup, PageSection, Switch } from "@patternfly/react-core"; import { FormAccess } from "../components/form-access/FormAccess"; import { HelpItem } from "../components/help-enabler/HelpItem"; import { FormPanel } from "../components/scroll-form/FormPanel"; @@ -31,11 +26,7 @@ export const RealmSettingsLoginTab = ({ const adminClient = useAdminClient(); const { realm: realmName } = useRealm(); - const updateSwitchValue = async ( - onChange: (newValue: boolean) => void, - value: boolean - ) => { - onChange(value); + const updateSwitchValue = async (name: string) => { const switchValues = form.getValues(); try { @@ -45,10 +36,10 @@ export const RealmSettingsLoginTab = ({ }, switchValues ); - addAlert(t("deleteClientPolicySuccess"), AlertVariant.success); + addAlert(t("enableSwitchSuccess", { switch: t(name) })); refresh(); } catch (error) { - addError(t("deleteClientPolicyError"), error); + addError(t("enableSwitchError"), error); } }; @@ -83,7 +74,8 @@ export const RealmSettingsLoginTab = ({ labelOff={t("common:off")} isChecked={value} onChange={(value) => { - updateSwitchValue(onChange, value); + onChange(value); + updateSwitchValue("userRegistration"); }} /> )} @@ -114,7 +106,8 @@ export const RealmSettingsLoginTab = ({ labelOff={t("common:off")} isChecked={value} onChange={(value) => { - updateSwitchValue(onChange, value); + onChange(value); + updateSwitchValue("forgotPassword"); }} /> )} @@ -144,7 +137,8 @@ export const RealmSettingsLoginTab = ({ labelOff={t("common:off")} isChecked={value} onChange={(value) => { - updateSwitchValue(onChange, value); + onChange(value); + updateSwitchValue("rememberMe"); }} /> )} @@ -178,7 +172,8 @@ export const RealmSettingsLoginTab = ({ labelOff={t("common:off")} isChecked={value} onChange={(value) => { - updateSwitchValue(onChange, value); + onChange(value); + updateSwitchValue("emailAsUsername"); }} /> )} @@ -208,7 +203,8 @@ export const RealmSettingsLoginTab = ({ labelOff={t("common:off")} isChecked={value} onChange={(value) => { - updateSwitchValue(onChange, value); + onChange(value); + updateSwitchValue("loginWithEmail"); }} /> )} @@ -241,7 +237,8 @@ export const RealmSettingsLoginTab = ({ !form.getValues().registrationEmailAsUsername } onChange={(value) => { - updateSwitchValue(onChange, value); + onChange(value); + updateSwitchValue("duplicateEmails"); }} isDisabled={ form.getValues().loginWithEmailAllowed || @@ -276,7 +273,8 @@ export const RealmSettingsLoginTab = ({ labelOff={t("common:off")} isChecked={value} onChange={(value) => { - updateSwitchValue(onChange, value); + onChange(value); + updateSwitchValue("verifyEmail"); }} /> )} @@ -313,7 +311,8 @@ export const RealmSettingsLoginTab = ({ labelOff={t("common:off")} isChecked={value} onChange={(value) => { - updateSwitchValue(onChange, value); + onChange(value); + updateSwitchValue("userInfoSettings"); }} /> )}