diff --git a/frontend/src/component/admin/auth/AutoCreateForm/AutoCreateForm.tsx b/frontend/src/component/admin/auth/AutoCreateForm/AutoCreateForm.tsx index 73ff46fa9d..4424c84b2d 100644 --- a/frontend/src/component/admin/auth/AutoCreateForm/AutoCreateForm.tsx +++ b/frontend/src/component/admin/auth/AutoCreateForm/AutoCreateForm.tsx @@ -22,11 +22,13 @@ interface IAutoCreateFormProps { name: string, value: string | boolean | number | undefined, ) => void; + onUpdateRole: (role: IRole | null) => void; } export const AutoCreateForm = ({ data = { enabled: false, autoCreate: false }, setValue, + onUpdateRole, }: IAutoCreateFormProps) => { const { roles } = useRoles(); @@ -34,16 +36,21 @@ export const AutoCreateForm = ({ setValue('autoCreate', !data.autoCreate); }; - const updateDefaultRootRoleId = (role: IRole | null) => { - setValue('defaultRootRoleId', role?.id); - }; - const updateField = (e: ChangeEvent) => { setValue(e.target.name, e.target.value); }; - const roleIdToRole = (rootRoleId: number | undefined): IRole | null => { - return roles.find((role: IRole) => role.id === rootRoleId) || null; + const resolveRole = ({ + defaultRootRole, + defaultRootRoleId, + }: { + defaultRootRole?: string; + defaultRootRoleId?: number; + }): IRole | null => { + if (defaultRootRoleId) { + return roles.find(({ id }) => id === defaultRootRoleId) || null; + } + return roles.find(({ name }) => name === defaultRootRole) || null; }; return ( @@ -81,8 +88,8 @@ export const AutoCreateForm = ({ { const { setToastData, setToastApiError } = useToast(); const { uiConfig } = useUiConfig(); - const [data, setData] = useState(initialState); + const [data, setData] = useState(initialState); const { config } = useAuthSettings('oidc'); const { updateSettings, errors, loading } = useAuthSettingsApi('oidc'); @@ -70,6 +76,14 @@ export const OidcAuth = () => { }); }; + const onUpdateRole = (role: IRole | null) => { + setData({ + ...data, + defaultRootRole: undefined, + defaultRootRoleId: role?.id, + }); + }; + const onSubmit = async (event: React.SyntheticEvent) => { event.preventDefault(); @@ -240,7 +254,11 @@ export const OidcAuth = () => { data={data} setValue={setValue} /> - + ID Signing algorithm diff --git a/frontend/src/component/admin/auth/SamlAuth/SamlAuth.tsx b/frontend/src/component/admin/auth/SamlAuth/SamlAuth.tsx index 5842e4b18d..c8f81f6343 100644 --- a/frontend/src/component/admin/auth/SamlAuth/SamlAuth.tsx +++ b/frontend/src/component/admin/auth/SamlAuth/SamlAuth.tsx @@ -15,6 +15,7 @@ import useAuthSettingsApi from 'hooks/api/actions/useAuthSettingsApi/useAuthSett import { formatUnknownError } from 'utils/formatUnknownError'; import { removeEmptyStringFields } from 'utils/removeEmptyStringFields'; import { SsoGroupSettings } from '../SsoGroupSettings'; +import { IRole } from 'interfaces/role'; const initialState = { enabled: false, @@ -30,10 +31,15 @@ const initialState = { groupJsonPath: '', }; +type State = typeof initialState & { + defaultRootRole?: string; + defaultRootRoleId?: number; +}; + export const SamlAuth = () => { const { setToastData, setToastApiError } = useToast(); const { uiConfig } = useUiConfig(); - const [data, setData] = useState(initialState); + const [data, setData] = useState(initialState); const { config } = useAuthSettings('saml'); const { updateSettings, errors, loading } = useAuthSettingsApi('saml'); @@ -61,6 +67,14 @@ export const SamlAuth = () => { }); }; + const onUpdateRole = (role: IRole | null) => { + setData({ + ...data, + defaultRootRole: undefined, + defaultRootRoleId: role?.id, + }); + }; + const onSubmit = async (event: React.SyntheticEvent) => { event.preventDefault(); @@ -248,7 +262,11 @@ export const SamlAuth = () => { setValue={setValue} /> - +