@keycloakify/keycloak-admin-ui
Version:
Repackaged Keycloak Admin UI
87 lines • 4.66 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { AlertVariant, Button, ButtonVariant, Form, FormGroup, Modal, ModalVariant, TextContent, TextInput, } from "@patternfly/react-core";
import { useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { useAdminClient } from "../admin-client";
import { useAlerts } from "../ui-shared";
import { useRealm } from "../context/realm-context/RealmContext";
export const RevocationModal = ({ handleModalToggle, save, }) => {
const { adminClient } = useAdminClient();
const { t } = useTranslation();
const { addAlert, addError } = useAlerts();
const { realm: realmName, realmRepresentation: realm, refresh } = useRealm();
const { register, handleSubmit } = useForm();
const parseResult = (result, prefixKey) => {
var _a, _b;
const successCount = ((_a = result.successRequests) === null || _a === void 0 ? void 0 : _a.length) || 0;
const failedCount = ((_b = result.failedRequests) === null || _b === void 0 ? void 0 : _b.length) || 0;
if (successCount === 0 && failedCount === 0) {
addAlert(t("noAdminUrlSet"), AlertVariant.warning);
}
else if (failedCount > 0) {
addAlert(t("" + prefixKey + "Success", {
successNodes: result.successRequests,
}), AlertVariant.success);
addAlert(t("" + prefixKey + "Fail", {
failedNodes: result.failedRequests,
}), AlertVariant.danger);
}
else {
addAlert(t("" + prefixKey + "Success", {
successNodes: result.successRequests,
}), AlertVariant.success);
}
};
const setToNow = async () => {
try {
await adminClient.realms.update({ realm: realmName }, {
realm: realmName,
notBefore: Date.now() / 1000,
});
addAlert(t("notBeforeSuccess"), AlertVariant.success);
}
catch (error) {
addError("setToNowError", error);
}
};
const clearNotBefore = async () => {
try {
await adminClient.realms.update({ realm: realmName }, {
realm: realmName,
notBefore: 0,
});
addAlert(t("notBeforeClearedSuccess"), AlertVariant.success);
refresh();
}
catch (error) {
addError("notBeforeError", error);
}
};
const push = async () => {
const result = await adminClient.realms.pushRevocation({
realm: realmName,
});
parseResult(result, "notBeforePush");
refresh();
};
return (_jsxs(Modal, { variant: ModalVariant.small, title: t("revocation"), isOpen: true, onClose: handleModalToggle, actions: [
_jsx(Button, { "data-testid": "set-to-now-button", variant: "tertiary", onClick: () => {
setToNow();
handleModalToggle();
}, form: "revocation-modal-form", children: t("setToNow") }, "set-to-now"),
_jsx(Button, { "data-testid": "clear-not-before-button", variant: "tertiary", onClick: () => {
clearNotBefore();
handleModalToggle();
}, form: "revocation-modal-form", children: t("clear") }, "clear"),
_jsx(Button, { "data-testid": "modal-test-connection-button", variant: "secondary", onClick: () => {
push();
handleModalToggle();
}, form: "revocation-modal-form", children: t("push") }, "push"),
_jsx(Button, { id: "modal-cancel", "data-testid": "cancel", variant: ButtonVariant.link, onClick: () => {
handleModalToggle();
}, children: t("cancel") }, "cancel"),
], children: [_jsx(TextContent, { className: "kc-revocation-description-text", children: t("revocationDescription") }), _jsx(Form, { id: "revocation-modal-form", isHorizontal: true, onSubmit: handleSubmit(save), children: _jsx(FormGroup, { className: "kc-revocation-modal-form-group", label: t("notBefore"), name: "notBefore", fieldId: "not-before", children: _jsx(TextInput, { "data-testid": "not-before-input", autoFocus: true, readOnly: true, value: (realm === null || realm === void 0 ? void 0 : realm.notBefore) === 0
? t("none")
: new Date((realm === null || realm === void 0 ? void 0 : realm.notBefore) * 1000).toString(), type: "text", id: "not-before", ...register("notBefore") }) }) })] }));
};
//# sourceMappingURL=RevocationModal.js.map