From 7a6de9ee5fd143dab4acca6d2f56e6570e6ddf46 Mon Sep 17 00:00:00 2001 From: Manojava Koushik <111366021+manojava-gk@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:54:35 +0530 Subject: [PATCH] feat(company roles): introduce company service file to enable page based on company role (#1361) --- src/index.tsx | 23 +++++++----- src/services/AccessService.tsx | 5 +++ src/services/CompanyService.ts | 68 ++++++++++++++++++++++++++++++++++ src/types/Constants.ts | 8 ++++ 4 files changed, 94 insertions(+), 10 deletions(-) create mode 100644 src/services/CompanyService.ts diff --git a/src/index.tsx b/src/index.tsx index 238e775a3..e99f35199 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -30,19 +30,22 @@ import { SharedThemeProvider, SharedCssBaseline, } from '@catena-x/portal-shared-components' +import CompanyService from 'services/CompanyService' I18nService.init() AccessService.init() UserService.init(() => { - createRoot(document.getElementById('app')!).render( - - - - - - - - - ) + CompanyService.init(() => { + createRoot(document.getElementById('app')!).render( + + + + + + + + + ) + }) }) diff --git a/src/services/AccessService.tsx b/src/services/AccessService.tsx index fa36be23c..820e0bcc5 100644 --- a/src/services/AccessService.tsx +++ b/src/services/AccessService.tsx @@ -81,6 +81,7 @@ import { getClientIdSsiCredential, } from './EnvironmentService' import CSVUploadOverlay from 'components/overlays/CSVUploadOverlay' +import { getCompanyRoles } from './CompanyService' let pageMap: { [page: string]: IPage } let actionMap: { [action: string]: IAction } @@ -98,6 +99,9 @@ export const userHasClientRole = ( export const userHasPortalRole = (roles: string | Array): boolean => userHasClientRole(getClientId(), roles) +export const companyHasRole = (role: string): boolean => + getCompanyRoles().includes(role) + export const userHasRegistrationRole = ( roles: string | Array ): boolean => userHasClientRole(getClientIdRegistration(), roles) @@ -294,6 +298,7 @@ const AccessService = { userMenuReg, footerMenu, userMenuComp, + companyHasRole, } export default AccessService diff --git a/src/services/CompanyService.ts b/src/services/CompanyService.ts new file mode 100644 index 000000000..3fdde9eb1 --- /dev/null +++ b/src/services/CompanyService.ts @@ -0,0 +1,68 @@ +/******************************************************************************** + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +import { type CompanyDetails } from 'features/admin/userApiSlice' +import { getApiBase } from './EnvironmentService' +import UserService from './UserService' + +let CI: CompanyDetails = { + bpn: '', + city: '', + companyId: '', + countryAlpha2Code: '', + countryDe: '', + name: '', + region: '', + shortName: '', + streetAdditional: '', + streetName: '', + streetNumber: '', + taxId: '', + zipCode: '', + companyRole: [], +} + +const init = (onCompanyDetailsCallback: () => void) => { + fetch(`${getApiBase()}/api/administration/companydata/ownCompanyDetails`, { + method: 'GET', + headers: { + authorization: `Bearer ${UserService.getToken()}`, + }, + }) + .then((res) => res.json()) + .then((data) => { + CI = data + onCompanyDetailsCallback() + }) + .catch((error) => { + console.log(error) + }) +} + +export const getCompanyDetails = () => CI + +export const getCompanyRoles = () => CI.companyRole + +const CompanyService = { + init, + getCompanyDetails, + getCompanyRoles, +} + +export default CompanyService diff --git a/src/types/Constants.ts b/src/types/Constants.ts index e39ead49c..ab51c19ac 100644 --- a/src/types/Constants.ts +++ b/src/types/Constants.ts @@ -254,3 +254,11 @@ export const serviceTypeMapping: Record = { 'Datenraum Services': ServiceTypeIdsEnum.DATASPACE_SERVICES, 'Beratungs Services': ServiceTypeIdsEnum.CONSULTANCY_SERVICES, } + +export enum COMPANY_ROLES { + ACTIVE_PARTICIPANT = 'ACTIVE_PARTICIPANT', + APP_PROVIDER = 'APP_PROVIDER', + SERVICE_PROVIDER = 'SERVICE_PROVIDER', + OPERATOR = 'OPERATOR', + ONBOARDING_SERVICE_PROVIDER = 'ONBOARDING_SERVICE_PROVIDER', +}