UNPKG

@keycloakify/keycloak-admin-ui

Version:
52 lines 3.22 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import { ListEmptyState, OrganizationTable, useAlerts, } from "../ui-shared"; import { Button, ButtonVariant, PageSection, ToolbarItem, } from "@patternfly/react-core"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { Link, useNavigate } from "react-router-dom"; import { useAdminClient } from "../admin-client"; import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog"; import { ViewHeader } from "../components/view-header/ViewHeader"; import { useRealm } from "../context/realm-context/RealmContext"; import { toEditOrganization } from "../organizations/routes/EditOrganization"; import { toAddOrganization } from "../organizations/routes/AddOrganization"; export default function OrganizationSection() { const { adminClient } = useAdminClient(); const { realm } = useRealm(); const { t } = useTranslation(); const { addAlert, addError } = useAlerts(); const navigate = useNavigate(); const [key, setKey] = useState(0); const refresh = () => setKey(key + 1); const [selectedOrg, setSelectedOrg] = useState(); async function loader(first, max, search) { return await adminClient.organizations.find({ first, max, search }); } const [toggleDeleteDialog, DeleteConfirm] = useConfirmDialog({ titleKey: "organizationDelete", messageKey: "organizationDeleteConfirm", continueButtonLabel: "delete", continueButtonVariant: ButtonVariant.danger, onConfirm: async () => { try { await adminClient.organizations.delById({ id: selectedOrg.id, }); addAlert(t("organizationDeletedSuccess")); refresh(); } catch (error) { addError("organizationDeleteError", error); } }, }); return (_jsxs(_Fragment, { children: [_jsx(ViewHeader, { titleKey: "organizationsList", subKey: "organizationsExplain", divider: true }), _jsxs(PageSection, { variant: "light", className: "pf-v5-u-p-0", children: [_jsx(DeleteConfirm, {}), _jsx(OrganizationTable, { link: ({ organization, children }) => (_jsx(Link, { to: toEditOrganization({ realm, id: organization.id, tab: "settings", }), children: children }, organization.id)), loader: loader, isPaginated: true, toolbarItem: _jsx(ToolbarItem, { children: _jsx(Button, { "data-testid": "addOrganization", component: (props) => (_jsx(Link, { ...props, to: toAddOrganization({ realm }) })), children: t("createOrganization") }) }), onDelete: (org) => { setSelectedOrg(org); toggleDeleteDialog(); }, children: _jsx(ListEmptyState, { message: t("emptyOrganizations"), instructions: t("emptyOrganizationsInstructions"), primaryActionText: t("createOrganization"), onPrimaryAction: () => navigate(toAddOrganization({ realm })) }) }, key)] })] })); } //# sourceMappingURL=OrganizationsSection.js.map