diff --git a/src/components/hosts/RoleDropdown.tsx b/src/components/hosts/RoleDropdown.tsx index 545c1e0646..97c390798b 100644 --- a/src/components/hosts/RoleDropdown.tsx +++ b/src/components/hosts/RoleDropdown.tsx @@ -5,7 +5,8 @@ import { SimpleDropdown } from '../ui/SimpleDropdown'; import { patchCluster } from '../../api/clusters'; import { HOST_ROLES } from '../../config/constants'; import { updateCluster } from '../../features/clusters/currentClusterSlice'; -import { handleApiError } from '../../api/utils'; +import { handleApiError, getErrorMessage } from '../../api/utils'; +import { AlertsContext } from '../AlertsContextProvider'; type RoleDropdownProps = { host: Host; @@ -15,6 +16,7 @@ export const RoleDropdown: React.FC = ({ host }) => { const { role, id, clusterId } = host; const [isDisabled, setDisabled] = React.useState(false); const dispatch = useDispatch(); + const { addAlert } = React.useContext(AlertsContext); const setRole = async (role?: string) => { const params: ClusterUpdateParams = {}; @@ -24,7 +26,9 @@ export const RoleDropdown: React.FC = ({ host }) => { const { data } = await patchCluster(clusterId as string, params); dispatch(updateCluster(data)); } catch (e) { - handleApiError(e); + handleApiError(e, () => + addAlert({ title: 'Failed to set role', message: getErrorMessage(e) }), + ); } setDisabled(false); };