diff --git a/cypress/integration/realm_settings_tabs_test.spec.ts b/cypress/integration/realm_settings_tabs_test.spec.ts index 5cd59f43ca..039ab72725 100644 --- a/cypress/integration/realm_settings_tabs_test.spec.ts +++ b/cypress/integration/realm_settings_tabs_test.spec.ts @@ -63,14 +63,16 @@ describe("Realm settings tabs tests", () => { sidebarPage.goToRealmSettings(); cy.findByTestId("rs-login-tab").click(); realmSettingsPage.toggleSwitch(realmSettingsPage.userRegSwitch); + realmSettingsPage.toggleSwitch(realmSettingsPage.forgotPwdSwitch); + realmSettingsPage.toggleSwitch(realmSettingsPage.rememberMeSwitch); - }); - it("Check login tab values", () => { - sidebarPage.goToRealmSettings(); - cy.findByTestId("rs-login-tab").click(); + realmSettingsPage.toggleSwitch(realmSettingsPage.loginWithEmailSwitch); + realmSettingsPage.toggleSwitch(realmSettingsPage.duplicateEmailsSwitch); + + // Check values cy.findByTestId(realmSettingsPage.userRegSwitch).should("have.value", "on"); cy.findByTestId(realmSettingsPage.forgotPwdSwitch).should( "have.value", @@ -80,6 +82,24 @@ describe("Realm settings tabs tests", () => { "have.value", "on" ); + cy.findByTestId(realmSettingsPage.emailAsUsernameSwitch).should( + "have.value", + "off" + ); + cy.findByTestId(realmSettingsPage.loginWithEmailSwitch).should( + "have.value", + "off" + ); + + cy.findByTestId(realmSettingsPage.duplicateEmailsSwitch).should( + "have.value", + "on" + ); + + cy.findByTestId(realmSettingsPage.verifyEmailSwitch).should( + "have.value", + "off" + ); }); it("Go to email tab", () => { diff --git a/src/realm-settings/GeneralTab.tsx b/src/realm-settings/GeneralTab.tsx index ae3c933e8f..ef1487892b 100644 --- a/src/realm-settings/GeneralTab.tsx +++ b/src/realm-settings/GeneralTab.tsx @@ -150,7 +150,7 @@ export const RealmSettingsGeneralTab = ({ fieldLabelId="realm-settings:userManagedAccess" /> } - fieldId="kc-user-manged-access" + fieldId="kc-user-managed-access" > void; realm: RealmRepresentation; refresh: () => void; }; export const RealmSettingsLoginTab = ({ - save, realm, refresh, }: RealmSettingsLoginTabProps) => { const { t } = useTranslation("realm-settings"); const form = useForm({ mode: "onChange" }); + const { addAlert, addError } = useAlerts(); + const adminClient = useAdminClient(); + const { realm: realmName } = useRealm(); - const updateSwitchValue = ( + const updateSwitchValue = async ( onChange: (newValue: boolean) => void, - value: boolean, - name: string + value: boolean ) => { - save({ ...realm, [name as keyof typeof realm]: value }); onChange(value); - refresh(); + const switchValues = form.getValues(); + + try { + await adminClient.realms.update( + { + realm: realmName, + }, + switchValues + ); + addAlert(t("deleteClientPolicySuccess"), AlertVariant.success); + refresh(); + } catch (error) { + addError(t("deleteClientPolicyError"), error); + } }; return ( @@ -58,12 +78,12 @@ export const RealmSettingsLoginTab = ({ { - updateSwitchValue(onChange, value, "registrationAllowed"); + updateSwitchValue(onChange, value); }} /> )} @@ -89,11 +109,12 @@ export const RealmSettingsLoginTab = ({ id="kc-forgot-pw-switch" data-testid="forgot-pw-switch" name="resetPasswordAllowed" + value={value ? "on" : "off"} label={t("common:on")} labelOff={t("common:off")} isChecked={value} onChange={(value) => { - updateSwitchValue(onChange, value, "resetPasswordAllowed"); + updateSwitchValue(onChange, value); }} /> )} @@ -118,12 +139,12 @@ export const RealmSettingsLoginTab = ({ { - updateSwitchValue(onChange, value, "rememberMe"); + updateSwitchValue(onChange, value); }} /> )} @@ -152,16 +173,12 @@ export const RealmSettingsLoginTab = ({ { - updateSwitchValue( - onChange, - value, - "registrationEmailAsUsername" - ); + updateSwitchValue(onChange, value); }} /> )} @@ -186,12 +203,12 @@ export const RealmSettingsLoginTab = ({ { - updateSwitchValue(onChange, value, "loginWithEmailAllowed"); + updateSwitchValue(onChange, value); }} /> )} @@ -218,18 +235,13 @@ export const RealmSettingsLoginTab = ({ data-testid="duplicate-emails-switch" label={t("common:on")} labelOff={t("common:off")} - name="duplicateEmailsAllowed" isChecked={ form.getValues().duplicateEmailsAllowed && !form.getValues().loginWithEmailAllowed && !form.getValues().registrationEmailAsUsername } onChange={(value) => { - updateSwitchValue( - onChange, - value, - "duplicateEmailsAllowed" - ); + updateSwitchValue(onChange, value); }} isDisabled={ form.getValues().loginWithEmailAllowed || @@ -259,11 +271,12 @@ export const RealmSettingsLoginTab = ({ id="kc-verify-email-switch" data-testid="verify-email-switch" name="verifyEmail" + value={value ? "on" : "off"} label={t("common:on")} labelOff={t("common:off")} isChecked={value} onChange={(value) => { - updateSwitchValue(onChange, value, "verifyEmail"); + updateSwitchValue(onChange, value); }} /> )} @@ -295,12 +308,12 @@ export const RealmSettingsLoginTab = ({ { - updateSwitchValue(onChange, value, "editUsernameAllowed"); + updateSwitchValue(onChange, value); }} /> )} diff --git a/src/realm-settings/RealmSettingsTabs.tsx b/src/realm-settings/RealmSettingsTabs.tsx index b6a98c4770..96b4834723 100644 --- a/src/realm-settings/RealmSettingsTabs.tsx +++ b/src/realm-settings/RealmSettingsTabs.tsx @@ -278,11 +278,7 @@ export const RealmSettingsTabs = ({ data-testid="rs-login-tab" {...route("login")} > - + {t("email")}}