Skip to content

Commit

Permalink
feat(company roles): introduce company service file to enable page ba…
Browse files Browse the repository at this point in the history
…sed on company role (#1361)
  • Loading branch information
manojava-gk authored Nov 21, 2024
1 parent 75d604c commit 7a6de9e
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<StrictMode>
<SharedCssBaseline />
<Provider store={store}>
<SharedThemeProvider>
<AuthorizingRouter />
</SharedThemeProvider>
</Provider>
</StrictMode>
)
CompanyService.init(() => {
createRoot(document.getElementById('app')!).render(
<StrictMode>
<SharedCssBaseline />
<Provider store={store}>
<SharedThemeProvider>
<AuthorizingRouter />
</SharedThemeProvider>
</Provider>
</StrictMode>
)
})
})
5 changes: 5 additions & 0 deletions src/services/AccessService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -98,6 +99,9 @@ export const userHasClientRole = (
export const userHasPortalRole = (roles: string | Array<string>): boolean =>
userHasClientRole(getClientId(), roles)

export const companyHasRole = (role: string): boolean =>
getCompanyRoles().includes(role)

export const userHasRegistrationRole = (
roles: string | Array<string>
): boolean => userHasClientRole(getClientIdRegistration(), roles)
Expand Down Expand Up @@ -294,6 +298,7 @@ const AccessService = {
userMenuReg,
footerMenu,
userMenuComp,
companyHasRole,
}

export default AccessService
68 changes: 68 additions & 0 deletions src/services/CompanyService.ts
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions src/types/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,11 @@ export const serviceTypeMapping: Record<string, ServiceTypeIdsEnum> = {
'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',
}

0 comments on commit 7a6de9e

Please sign in to comment.