Skip to content

Commit d58b743

Browse files
authored
Merge pull request #7763 from TheThingsNetwork/fix/oauth-client-collaborato
Add oauth client collaborator edit page
2 parents 60e7e17 + 43b32b3 commit d58b743

2 files changed

Lines changed: 93 additions & 0 deletions

File tree

  • pkg/webui/console/views
    • user-settings-oauth-client-collaborator-edit
    • user-settings-oauth-client
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Copyright © 2025 The Things Network Foundation, The Things Industries B.V.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import React from 'react'
16+
import { useParams } from 'react-router-dom'
17+
import { useSelector } from 'react-redux'
18+
19+
import { CLIENT } from '@console/constants/entities'
20+
21+
import PageTitle from '@ttn-lw/components/page-title'
22+
import { useBreadcrumbs } from '@ttn-lw/components/breadcrumbs/context'
23+
import Breadcrumb from '@ttn-lw/components/breadcrumbs/breadcrumb'
24+
25+
import RequireRequest from '@ttn-lw/lib/components/require-request'
26+
27+
import AccountCollaboratorsForm from '@console/containers/collaborators-form'
28+
29+
import { selectCollaboratorById } from '@ttn-lw/lib/store/selectors/collaborators'
30+
import sharedMessages from '@ttn-lw/lib/shared-messages'
31+
import { getCollaborator } from '@ttn-lw/lib/store/actions/collaborators'
32+
33+
const OAuthClientCollaboratorEditInner = () => {
34+
const { clientId, collaboratorId, collaboratorType } = useParams()
35+
36+
useBreadcrumbs(
37+
'user-settings.oauth-clients.single.collaborators.single.edit',
38+
<Breadcrumb
39+
path={`/user-settings/oauth-clients/${clientId}/collaborators/${collaboratorType}/${collaboratorId}`}
40+
content={sharedMessages.edit}
41+
/>,
42+
)
43+
44+
return (
45+
<div className="container container--xxl grid">
46+
<PageTitle title={sharedMessages.collaboratorEdit} values={{ collaboratorId }} />
47+
<div className="item-12 xl:item-8">
48+
<AccountCollaboratorsForm
49+
entity={CLIENT}
50+
entityId={clientId}
51+
collaboratorId={collaboratorId}
52+
collaboratorType={collaboratorType === 'user' ? 'user' : 'organization'}
53+
update
54+
/>
55+
</div>
56+
</div>
57+
)
58+
}
59+
60+
const OAuthClientCollaboratorEdit = () => {
61+
const { clientId, collaboratorId, collaboratorType } = useParams()
62+
63+
// Check if collaborator still exists after being possibly deleted.
64+
const collaborator = useSelector(state => selectCollaboratorById(state, collaboratorId))
65+
const hasCollaborator = Boolean(collaborator)
66+
const isUser = collaboratorType === 'user'
67+
68+
useBreadcrumbs(
69+
'user-settings.oauth-clients.single.collaborators.single',
70+
<Breadcrumb
71+
path={`/user-settings/oauth-clients/${clientId}/collaborators/${collaboratorType}/${collaboratorId}`}
72+
content={collaboratorId}
73+
/>,
74+
)
75+
76+
if (collaboratorType !== 'user' && collaboratorType !== 'organization') {
77+
return null
78+
}
79+
80+
return (
81+
<RequireRequest requestAction={getCollaborator('client', clientId, collaboratorId, isUser)}>
82+
{hasCollaborator && <OAuthClientCollaboratorEditInner />}
83+
</RequireRequest>
84+
)
85+
}
86+
87+
export default OAuthClientCollaboratorEdit

pkg/webui/console/views/user-settings-oauth-client/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import { getClient, getClientRights } from '@console/store/actions/clients'
3838

3939
import { selectClientById } from '@console/store/selectors/clients'
4040

41+
import OAuthClientCollaboratorEdit from '../user-settings-oauth-client-collaborator-edit'
42+
4143
import style from './user-settings-oauth-client.styl'
4244

4345
const OAuthClientInner = () => {
@@ -85,6 +87,10 @@ const OAuthClientInner = () => {
8587
<Route index Component={OAuthClientGeneralSettings} />
8688
<Route path="collaborators" Component={OAuthClientCollaboratorsList} />
8789
<Route path="collaborators/add" Component={OAuthClientCollaboratorAdd} />
90+
<Route
91+
path="collaborators/:collaboratorType/:collaboratorId"
92+
Component={OAuthClientCollaboratorEdit}
93+
/>
8894
<Route path="*" element={<GenericNotFound />} />
8995
</Routes>
9096
</>

0 commit comments

Comments
 (0)