Skip to content

Commit 7a6de9e

Browse files
authored
feat(company roles): introduce company service file to enable page based on company role (eclipse-tractusx#1361)
1 parent 75d604c commit 7a6de9e

File tree

4 files changed

+94
-10
lines changed

4 files changed

+94
-10
lines changed

src/index.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,22 @@ import {
3030
SharedThemeProvider,
3131
SharedCssBaseline,
3232
} from '@catena-x/portal-shared-components'
33+
import CompanyService from 'services/CompanyService'
3334

3435
I18nService.init()
3536
AccessService.init()
3637

3738
UserService.init(() => {
38-
createRoot(document.getElementById('app')!).render(
39-
<StrictMode>
40-
<SharedCssBaseline />
41-
<Provider store={store}>
42-
<SharedThemeProvider>
43-
<AuthorizingRouter />
44-
</SharedThemeProvider>
45-
</Provider>
46-
</StrictMode>
47-
)
39+
CompanyService.init(() => {
40+
createRoot(document.getElementById('app')!).render(
41+
<StrictMode>
42+
<SharedCssBaseline />
43+
<Provider store={store}>
44+
<SharedThemeProvider>
45+
<AuthorizingRouter />
46+
</SharedThemeProvider>
47+
</Provider>
48+
</StrictMode>
49+
)
50+
})
4851
})

src/services/AccessService.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ import {
8181
getClientIdSsiCredential,
8282
} from './EnvironmentService'
8383
import CSVUploadOverlay from 'components/overlays/CSVUploadOverlay'
84+
import { getCompanyRoles } from './CompanyService'
8485

8586
let pageMap: { [page: string]: IPage }
8687
let actionMap: { [action: string]: IAction }
@@ -98,6 +99,9 @@ export const userHasClientRole = (
9899
export const userHasPortalRole = (roles: string | Array<string>): boolean =>
99100
userHasClientRole(getClientId(), roles)
100101

102+
export const companyHasRole = (role: string): boolean =>
103+
getCompanyRoles().includes(role)
104+
101105
export const userHasRegistrationRole = (
102106
roles: string | Array<string>
103107
): boolean => userHasClientRole(getClientIdRegistration(), roles)
@@ -294,6 +298,7 @@ const AccessService = {
294298
userMenuReg,
295299
footerMenu,
296300
userMenuComp,
301+
companyHasRole,
297302
}
298303

299304
export default AccessService

src/services/CompanyService.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/********************************************************************************
2+
* Copyright (c) 2024 Contributors to the Eclipse Foundation
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Apache License, Version 2.0 which is available at
9+
* https://www.apache.org/licenses/LICENSE-2.0.
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations
15+
* under the License.
16+
*
17+
* SPDX-License-Identifier: Apache-2.0
18+
********************************************************************************/
19+
20+
import { type CompanyDetails } from 'features/admin/userApiSlice'
21+
import { getApiBase } from './EnvironmentService'
22+
import UserService from './UserService'
23+
24+
let CI: CompanyDetails = {
25+
bpn: '',
26+
city: '',
27+
companyId: '',
28+
countryAlpha2Code: '',
29+
countryDe: '',
30+
name: '',
31+
region: '',
32+
shortName: '',
33+
streetAdditional: '',
34+
streetName: '',
35+
streetNumber: '',
36+
taxId: '',
37+
zipCode: '',
38+
companyRole: [],
39+
}
40+
41+
const init = (onCompanyDetailsCallback: () => void) => {
42+
fetch(`${getApiBase()}/api/administration/companydata/ownCompanyDetails`, {
43+
method: 'GET',
44+
headers: {
45+
authorization: `Bearer ${UserService.getToken()}`,
46+
},
47+
})
48+
.then((res) => res.json())
49+
.then((data) => {
50+
CI = data
51+
onCompanyDetailsCallback()
52+
})
53+
.catch((error) => {
54+
console.log(error)
55+
})
56+
}
57+
58+
export const getCompanyDetails = () => CI
59+
60+
export const getCompanyRoles = () => CI.companyRole
61+
62+
const CompanyService = {
63+
init,
64+
getCompanyDetails,
65+
getCompanyRoles,
66+
}
67+
68+
export default CompanyService

src/types/Constants.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,11 @@ export const serviceTypeMapping: Record<string, ServiceTypeIdsEnum> = {
254254
'Datenraum Services': ServiceTypeIdsEnum.DATASPACE_SERVICES,
255255
'Beratungs Services': ServiceTypeIdsEnum.CONSULTANCY_SERVICES,
256256
}
257+
258+
export enum COMPANY_ROLES {
259+
ACTIVE_PARTICIPANT = 'ACTIVE_PARTICIPANT',
260+
APP_PROVIDER = 'APP_PROVIDER',
261+
SERVICE_PROVIDER = 'SERVICE_PROVIDER',
262+
OPERATOR = 'OPERATOR',
263+
ONBOARDING_SERVICE_PROVIDER = 'ONBOARDING_SERVICE_PROVIDER',
264+
}

0 commit comments

Comments
 (0)