UNPKG

@keycloakify/keycloak-admin-ui

Version:
111 lines 4.93 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { AlertVariant, Divider, DropdownItem } from "@patternfly/react-core"; import { useFormContext, useWatch } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { useParams } from "react-router-dom"; import { useAdminClient } from "../../admin-client"; import { useAlerts } from "../../ui-shared"; import { useConfirmDialog } from "../../components/confirm-dialog/ConfirmDialog"; import { Header } from "../../user-federation/shared/Header"; export const ExtendedHeader = ({ provider, editMode, save, noDivider = false, }) => { const { adminClient } = useAdminClient(); const { t } = useTranslation(); const { id } = useParams(); const { addAlert, addError } = useAlerts(); const { control } = useFormContext(); const hasImportUsers = useWatch({ name: "config.importEnabled", control, defaultValue: ["true"], })[0]; const [toggleUnlinkUsersDialog, UnlinkUsersDialog] = useConfirmDialog({ titleKey: "userFedUnlinkUsersConfirmTitle", messageKey: "userFedUnlinkUsersConfirm", continueButtonLabel: "unlinkUsers", onConfirm: () => unlinkUsers(), }); const [toggleRemoveUsersDialog, RemoveUsersConfirm] = useConfirmDialog({ titleKey: t("removeImportedUsers"), messageKey: t("removeImportedUsersMessage"), continueButtonLabel: "remove", onConfirm: async () => { try { removeImportedUsers(); addAlert(t("removeImportedUsersSuccess"), AlertVariant.success); } catch (error) { addError("removeImportedUsersError", error); } }, }); const removeImportedUsers = async () => { try { if (id) { await adminClient.userStorageProvider.removeImportedUsers({ id }); } addAlert(t("removeImportedUsersSuccess"), AlertVariant.success); } catch (error) { addError("removeImportedUsersError", error); } }; const syncChangedUsers = async () => { try { if (id) { const response = await adminClient.userStorageProvider.sync({ id: id, action: "triggerChangedUsersSync", }); if (response.ignored) { addAlert(`${response.status}.`, AlertVariant.warning); } else { addAlert(t("syncUsersSuccess") + `${response.added} users added, ${response.updated} users updated, ${response.removed} users removed, ${response.failed} users failed.`, AlertVariant.success); } } } catch (error) { addError("syncUsersError", error); } }; const syncAllUsers = async () => { try { if (id) { const response = await adminClient.userStorageProvider.sync({ id: id, action: "triggerFullSync", }); if (response.ignored) { addAlert(`${response.status}.`, AlertVariant.warning); } else { addAlert(t("syncUsersSuccess") + `${response.added} users added, ${response.updated} users updated, ${response.removed} users removed, ${response.failed} users failed.`, AlertVariant.success); } } } catch (error) { addError("syncUsersError", error); } }; const unlinkUsers = async () => { try { if (id) { await adminClient.userStorageProvider.unlinkUsers({ id }); } addAlert(t("unlinkUsersSuccess"), AlertVariant.success); } catch (error) { addError("unlinkUsersError", error); } }; return (_jsxs(_Fragment, { children: [_jsx(UnlinkUsersDialog, {}), _jsx(RemoveUsersConfirm, {}), _jsx(Header, { provider: provider, noDivider: noDivider, save: save, dropdownItems: [ _jsx(DropdownItem, { onClick: syncChangedUsers, isDisabled: hasImportUsers === "false", children: t("syncChangedUsers") }, "sync"), _jsx(DropdownItem, { onClick: syncAllUsers, isDisabled: hasImportUsers === "false", children: t("syncAllUsers") }, "syncall"), _jsx(DropdownItem, { isDisabled: editMode ? editMode.includes("UNSYNCED") : false, onClick: toggleUnlinkUsersDialog, children: t("unlinkUsers") }, "unlink"), _jsx(DropdownItem, { onClick: toggleRemoveUsersDialog, children: t("removeImported") }, "remove"), _jsx(Divider, {}, "separator"), ] })] })); }; //# sourceMappingURL=ExtendedHeader.js.map