import React, { useEffect, useState } from "react"; import { Form, Button as Button2, Select } from "antd"; import { Text, TextInput } from "@tremor/react"; import { getSSOSettings, updateSSOSettings } from "./networking"; import NotificationManager from "./molecules/notifications_manager"; interface UIAccessControlFormProps { accessToken: string | null; onSuccess: () => void; } // Separate UI Access Control Form Component const UIAccessControlForm: React.FC = ({ accessToken, onSuccess }) => { const [form] = Form.useForm(); const [loading, setLoading] = useState(false); // Load existing UI access control settings useEffect(() => { const loadUIAccessSettings = async () => { if (accessToken) { try { const ssoData = await getSSOSettings(accessToken); if (ssoData && ssoData.values) { // Handle nested ui_access_mode structure const uiAccessMode = ssoData.values.ui_access_mode; let formValues = {}; if (uiAccessMode && typeof uiAccessMode === "object") { formValues = { ui_access_mode_type: uiAccessMode.type, restricted_sso_group: uiAccessMode.restricted_sso_group, sso_group_jwt_field: uiAccessMode.sso_group_jwt_field, }; } else if (typeof uiAccessMode === "string") { // Handle legacy flat structure formValues = { ui_access_mode_type: uiAccessMode, restricted_sso_group: ssoData.values.restricted_sso_group, sso_group_jwt_field: ssoData.values.team_ids_jwt_field || ssoData.values.sso_group_jwt_field, }; } form.setFieldsValue(formValues); } } catch (error) { console.error("Failed to load UI access settings:", error); } } }; loadUIAccessSettings(); }, [accessToken, form]); const handleUIAccessSubmit = async (formValues: Record) => { if (!accessToken) { NotificationManager.fromBackend("No access token available"); return; } setLoading(true); try { // Transform form data to match API expected structure let apiPayload; if (formValues.ui_access_mode_type === "all_authenticated_users") { // Set ui_access_mode to none when all_authenticated_users is selected apiPayload = { ui_access_mode: "none", }; } else { apiPayload = { ui_access_mode: { type: formValues.ui_access_mode_type, restricted_sso_group: formValues.restricted_sso_group, sso_group_jwt_field: formValues.sso_group_jwt_field, }, }; } await updateSSOSettings(accessToken, apiPayload); onSuccess(); } catch (error) { console.error("Failed to save UI access settings:", error); NotificationManager.fromBackend("Failed to save UI access settings"); } finally { setLoading(false); } }; return (
Configure who can access the UI interface and how group information is extracted from JWT tokens.
prevValues.ui_access_mode_type !== currentValues.ui_access_mode_type } > {({ getFieldValue }) => { const uiAccessModeType = getFieldValue("ui_access_mode_type"); return uiAccessModeType === "restricted_sso_group" ? ( ) : null; }}
Update UI Access Control
); }; export default UIAccessControlForm;