diff --git a/apps/console/src/features/organization-discovery/components/add-organization-discovery-domains.tsx b/apps/console/src/features/organization-discovery/components/add-organization-discovery-domains.tsx index efde92a85d5..4e32141b5b0 100644 --- a/apps/console/src/features/organization-discovery/components/add-organization-discovery-domains.tsx +++ b/apps/console/src/features/organization-discovery/components/add-organization-discovery-domains.tsx @@ -24,6 +24,7 @@ import Chip from "@oxygen-ui/react/Chip"; import FormHelperText from "@oxygen-ui/react/FormHelperText"; import InputLabel from "@oxygen-ui/react/InputLabel"; import TextField from "@oxygen-ui/react/TextField"; +import { hasRequiredScopes } from "@wso2is/core/helpers"; import { AlertLevels, IdentifiableComponentInterface, @@ -39,13 +40,13 @@ import { } from "@wso2is/form"; import { EmphasizedSegment, Hint, PrimaryButton } from "@wso2is/react-components"; import isEmpty from "lodash-es/isEmpty"; -import React, { FunctionComponent, ReactElement, SyntheticEvent, useMemo, useState } from "react"; +import React, { FunctionComponent, ReactElement, SyntheticEvent, useEffect, useMemo, useState } from "react"; import { useTranslation } from "react-i18next"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { Dispatch } from "redux"; +import { AppState, FeatureConfigInterface } from "../../core"; import { AppConstants } from "../../core/constants/app-constants"; import { history } from "../../core/helpers/history"; -import { FeatureConfigInterface } from "../../core/models/config"; import useGetOrganizations from "../../organizations/api/use-get-organizations"; import { OrganizationInterface } from "../../organizations/models/organizations"; import addOrganizationEmailDomain from "../api/add-organization-email-domains"; @@ -90,17 +91,35 @@ const FORM_ID: string = "edit-organization-email-domains-form"; const AddOrganizationDiscoveryDomains: FunctionComponent = ( props: AddOrganizationDiscoveryDomainsPropsInterface ): ReactElement => { - const { ["data-componentid"]: componentId } = props; + const { + isReadOnly, + ["data-componentid"]: componentId + } = props; const { t } = useTranslation(); const dispatch: Dispatch = useDispatch(); + const allowedScopes: string = useSelector((state: AppState) => state?.auth?.allowedScopes); + const featureConfig: FeatureConfigInterface = useSelector((state: AppState) => state.config.ui.features); + const { data: organizations } = useGetOrganizations(true, null, null, null, null, true); const { data: discoverableOrganizations } = useGetOrganizationDiscovery(true, null, null, null); const [ emailDomains, setEmailDomains ] = useState([]); + const [ hasScopes, setHasScopes ] = useState(false); + + /** + * Set the hasScopes state based on the feature config. + */ + useEffect(() => { + setHasScopes( + !hasRequiredScopes( + featureConfig?.organizationDiscovery, + featureConfig?.organizationDiscovery?.scopes?.update, + allowedScopes)); + }, [ featureConfig ]); /** * Filter the already configured organizations from the list of organizations. @@ -273,17 +292,19 @@ const AddOrganizationDiscoveryDomains: FunctionComponent { ({ values }: { values: AddOrganizationDiscoveryDomainsFormValuesInterface }) => ( - - { t("common:update") } - + !isReadOnly && !hasScopes && ( + + { t("console:manage.features.organizationDiscovery.assign.buttons.assign") } + + ) ) } diff --git a/apps/console/src/features/organization-discovery/components/discoverable-organizations-list.tsx b/apps/console/src/features/organization-discovery/components/discoverable-organizations-list.tsx index f2a7fe4e24f..24603eb37a4 100644 --- a/apps/console/src/features/organization-discovery/components/discoverable-organizations-list.tsx +++ b/apps/console/src/features/organization-discovery/components/discoverable-organizations-list.tsx @@ -253,7 +253,7 @@ const DiscoverableOrganizationsList: FunctionComponent = useDispatch(); + const allowedScopes: string = useSelector((state: AppState) => state?.auth?.allowedScopes); + const featureConfig: FeatureConfigInterface = useSelector((state: AppState) => state.config.ui.features); + const [ emailDomains, setEmailDomains ] = useState([]); + const [ hasScopes, setHasScopes ] = useState(false); const optionsArray: string[] = []; @@ -113,6 +118,17 @@ const EditOrganizationDiscoveryDomains: FunctionComponent { + setHasScopes( + !hasRequiredScopes( + featureConfig?.organizationDiscovery, + featureConfig?.organizationDiscovery?.scopes?.update, + allowedScopes)); + }, [ featureConfig, organization ]); + /** * Function to handle the form submit action. * @@ -264,7 +280,7 @@ const EditOrganizationDiscoveryDomains: FunctionComponent - { !isReadOnly && ( + { !isReadOnly && !hasScopes && (