import React from "react"; // PatternFly import { Flex, FlexItem, Form, FormGroup, JumpLinks, JumpLinksItem, Sidebar, SidebarContent, SidebarPanel, } from "@patternfly/react-core"; // Data types import { Trust, Metadata } from "src/utils/datatypes/globalDataTypes"; // Hooks import useUpdateRoute from "src/hooks/useUpdateRoute"; // Utils import { asRecord } from "src/utils/trustsUtils"; // RPC import { TrustModPayload, useTrustModMutation } from "src/services/rpcTrusts"; // Components import IpaTextInput from "src/components/Form/IpaTextInput/IpaTextInput"; import TabLayout from "src/components/layouts/TabLayout"; import SecondaryButton from "src/components/layouts/SecondaryButton"; import HelpTextWithIconLayout from "src/components/layouts/HelpTextWithIconLayout"; import IpaTextboxList from "src/components/Form/IpaTextboxList"; import TitleLayout from "src/components/layouts/TitleLayout"; // Redux import { addAlert } from "src/store/Global/alerts-slice"; import { useAppDispatch } from "src/store/hooks"; interface TrustsSettingsProps { trust: Partial; originalTrust: Partial; metadata: Metadata; onTrustChange: (trust: Partial) => void; onRefresh: () => void; isModified: boolean; isDataLoading: boolean; modifiedValues: () => Partial; onResetValues: () => void; pathname: string; } const TrustsSettings = (props: TrustsSettingsProps) => { // Alerts to show in the UI const dispatch = useAppDispatch(); // Update current route data to Redux and highlight the current page in the Nav bar useUpdateRoute({ pathname: props.pathname }); // States const [isDataLoading, setIsDataLoading] = React.useState(false); // API calls const [saveTrust] = useTrustModMutation(); // 'Revert' handler method const onRevert = () => { props.onTrustChange(props.originalTrust); props.onRefresh(); dispatch( addAlert({ name: "revert-success", title: "Trust data reverted", variant: "success", }) ); }; // Helper method to build the payload based on values const buildPayload = ( modifiedValues: Partial, keyArray: string[] ): TrustModPayload => { const payload: TrustModPayload = { cn: props.trust.cn || "" }; keyArray.forEach((key) => { payload[key] = modifiedValues[key]; }); return payload; }; // Get 'ipaObject' and 'recordOnChange' to use in 'IpaTextInput' const { ipaObject, recordOnChange } = asRecord( props.trust, props.onTrustChange ); // 'Save' handler method const onSave = () => { setIsDataLoading(true); const modifiedValues = props.modifiedValues(); const payload = buildPayload(modifiedValues, [ "ipantadditionalsuffixes", "ipantsidblacklistincoming", "ipantsidblacklistoutgoing", ]); saveTrust(payload) .then((response) => { if ("data" in response) { const data = response.data; if (data?.error) { dispatch( addAlert({ name: "error", title: (data.error as Error).message, variant: "danger", }) ); } if (data?.result) { props.onTrustChange(data.result.result); dispatch( addAlert({ name: "save-success", title: "Trust data updated", variant: "success", }) ); props.onRefresh(); } } }) .finally(() => { setIsDataLoading(false); }); }; // Toolbar const toolbarFields = [ { key: 0, element: ( Refresh ), }, { key: 1, element: ( Revert ), }, { key: 2, element: ( Save ), }, ]; // Return component return ( Trusts settings Alternative UPN suffixes SID blocklists
); }; export default TrustsSettings;