UNPKG

@keycloakify/keycloak-admin-ui

Version:
56 lines 2.92 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { useAlerts, useFetch } from "../ui-shared"; import { ButtonVariant, DropdownItem } from "@patternfly/react-core"; import { get } from "lodash-es"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { useNavigate, useParams } 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 { useServerInfo } from "../context/server-info/ServerInfoProvider"; import { PageHandler } from "../page/PageHandler"; import { PAGE_PROVIDER } from "../page/PageList"; import { toPage } from "../page/routes"; export default function Page() { var _a, _b; const { adminClient } = useAdminClient(); const { t } = useTranslation(); const { componentTypes } = useServerInfo(); const { realm } = useRealm(); const pages = componentTypes === null || componentTypes === void 0 ? void 0 : componentTypes[PAGE_PROVIDER]; const navigate = useNavigate(); const { id, providerId } = useParams(); const { addAlert, addError } = useAlerts(); const [pageData, setPageData] = useState(); const page = pages === null || pages === void 0 ? void 0 : pages.find((p) => p.id === providerId); if (!page) { throw new Error(t("notFound")); } useFetch(async () => adminClient.components.findOne({ id: id }), setPageData, [id]); const [toggleDeleteDialog, DeleteConfirm] = useConfirmDialog({ titleKey: "itemDeleteConfirmTitle", messageKey: "itemDeleteConfirm", continueButtonLabel: "delete", continueButtonVariant: ButtonVariant.danger, onConfirm: async () => { try { await adminClient.components.del({ id: id, }); addAlert(t("itemDeletedSuccess")); navigate(toPage({ realm, providerId: providerId })); } catch (error) { addError("itemSaveError", error); } }, }); return (_jsxs(_Fragment, { children: [_jsx(DeleteConfirm, {}), _jsx(ViewHeader, { titleKey: ((_b = get(pageData, `config.${((_a = page.metadata.displayFields) === null || _a === void 0 ? void 0 : _a[0]) || page.properties[0].name}`)) === null || _b === void 0 ? void 0 : _b[0]) || t("createItem"), dropdownItems: id ? [ _jsx(DropdownItem, { "data-testid": "delete-item", onClick: () => toggleDeleteDialog(), children: t("delete") }, "delete"), ] : undefined }), _jsx(PageHandler, { providerType: PAGE_PROVIDER, id: id, page: page })] })); } //# sourceMappingURL=Page.js.map