/* eslint-disable */ // @ts-nocheck import type GlobalRequestResult from "@keycloak/keycloak-admin-client/lib/defs/globalRequestResult"; import { AlertVariant, Button, ButtonVariant, Form, FormGroup, Modal, ModalVariant, TextContent, TextInput, } from "../../shared/@patternfly/react-core"; import { useForm } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { useAdminClient } from "../admin-client"; import { useAlerts } from "../../shared/keycloak-ui-shared"; import { useRealm } from "../context/realm-context/RealmContext"; type RevocationModalProps = { handleModalToggle: () => void; save: () => void; }; export const RevocationModal = ({ handleModalToggle, save, }: RevocationModalProps) => { const { adminClient } = useAdminClient(); const { t } = useTranslation(); const { addAlert, addError } = useAlerts(); const { realm: realmName, realmRepresentation: realm, refresh } = useRealm(); const { register, handleSubmit } = useForm(); const parseResult = (result: GlobalRequestResult, prefixKey: string) => { const successCount = result.successRequests?.length || 0; const failedCount = result.failedRequests?.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 ( { await setToNow(); handleModalToggle(); }} form="revocation-modal-form" > {t("setToNow")} , , , , ]} > {t("revocationDescription")}
); };