Added confirm dialog on disable (#2238)
This commit is contained in:
parent
7c4509e9bf
commit
05f321fd06
1 changed files with 46 additions and 24 deletions
|
@ -24,13 +24,15 @@ import type ClientPolicyRepresentation from "@keycloak/keycloak-admin-client/lib
|
||||||
import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog";
|
import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog";
|
||||||
import { useAlerts } from "../components/alert/Alerts";
|
import { useAlerts } from "../components/alert/Alerts";
|
||||||
|
|
||||||
import "./realm-settings-section.css";
|
|
||||||
import { useRealm } from "../context/realm-context/RealmContext";
|
import { useRealm } from "../context/realm-context/RealmContext";
|
||||||
import { toAddClientPolicy } from "./routes/AddClientPolicy";
|
import { toAddClientPolicy } from "./routes/AddClientPolicy";
|
||||||
import { toEditClientPolicy } from "./routes/EditClientPolicy";
|
import { toEditClientPolicy } from "./routes/EditClientPolicy";
|
||||||
import { KeycloakSpinner } from "../components/keycloak-spinner/KeycloakSpinner";
|
import { KeycloakSpinner } from "../components/keycloak-spinner/KeycloakSpinner";
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import { toClientPolicies } from "./routes/ClientPolicies";
|
import { toClientPolicies } from "./routes/ClientPolicies";
|
||||||
|
|
||||||
|
import "./realm-settings-section.css";
|
||||||
|
|
||||||
export const PoliciesTab = () => {
|
export const PoliciesTab = () => {
|
||||||
const { t } = useTranslation("realm-settings");
|
const { t } = useTranslation("realm-settings");
|
||||||
const adminClient = useAdminClient();
|
const adminClient = useAdminClient();
|
||||||
|
@ -93,25 +95,46 @@ export const PoliciesTab = () => {
|
||||||
<Link to={toEditClientPolicy({ realm, policyName: name! })}>{name}</Link>
|
<Link to={toEditClientPolicy({ realm, policyName: name! })}>{name}</Link>
|
||||||
);
|
);
|
||||||
|
|
||||||
const SwitchRenderer = (clientPolicy: ClientPolicyRepresentation) => {
|
const SwitchRenderer = ({
|
||||||
|
clientPolicy,
|
||||||
|
}: {
|
||||||
|
clientPolicy: ClientPolicyRepresentation;
|
||||||
|
}) => {
|
||||||
|
const [toggleDisableDialog, DisableConfirm] = useConfirmDialog({
|
||||||
|
titleKey: "realm-settings:disablePolicyConfirmTitle",
|
||||||
|
messageKey: "realm-settings:disablePolicyConfirm",
|
||||||
|
continueButtonLabel: "common:disable",
|
||||||
|
onConfirm: () => {
|
||||||
|
form.setValue(clientPolicy.name!, false);
|
||||||
|
saveStatus();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Controller
|
<>
|
||||||
name={clientPolicy.name!}
|
<DisableConfirm />
|
||||||
data-testid={`${clientPolicy.name!}-switch`}
|
<Controller
|
||||||
defaultValue={clientPolicy.enabled}
|
name={clientPolicy.name!}
|
||||||
control={form.control}
|
data-testid={`${clientPolicy.name!}-switch`}
|
||||||
render={({ onChange, value }) => (
|
defaultValue={clientPolicy.enabled}
|
||||||
<Switch
|
control={form.control}
|
||||||
label={t("common:enabled")}
|
render={({ onChange, value }) => (
|
||||||
labelOff={t("common:disabled")}
|
<Switch
|
||||||
isChecked={value}
|
label={t("common:enabled")}
|
||||||
onChange={(value) => {
|
labelOff={t("common:disabled")}
|
||||||
onChange(value);
|
isChecked={value}
|
||||||
saveStatus();
|
onChange={(value) => {
|
||||||
}}
|
if (!value) {
|
||||||
/>
|
toggleDisableDialog();
|
||||||
)}
|
} else {
|
||||||
/>
|
onChange(value);
|
||||||
|
saveStatus();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -247,7 +270,9 @@ export const PoliciesTab = () => {
|
||||||
{
|
{
|
||||||
name: "enabled",
|
name: "enabled",
|
||||||
displayKey: "realm-settings:status",
|
displayKey: "realm-settings:status",
|
||||||
cellRenderer: SwitchRenderer,
|
cellRenderer: (clientPolicy) => (
|
||||||
|
<SwitchRenderer clientPolicy={clientPolicy} />
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "description",
|
name: "description",
|
||||||
|
@ -264,9 +289,7 @@ export const PoliciesTab = () => {
|
||||||
code={code}
|
code={code}
|
||||||
language={Language.json}
|
language={Language.json}
|
||||||
height="30rem"
|
height="30rem"
|
||||||
onChange={(value) => {
|
onChange={setCode}
|
||||||
setCode(value ?? "");
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="pf-u-mt-md">
|
<div className="pf-u-mt-md">
|
||||||
|
@ -285,7 +308,6 @@ export const PoliciesTab = () => {
|
||||||
setCode(prettyPrintJSON(tablePolicies));
|
setCode(prettyPrintJSON(tablePolicies));
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{" "}
|
|
||||||
{t("reload")}
|
{t("reload")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue