Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Part 2. Edit user in team #161

Merged
merged 21 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bfd886b
Add base skeleton for edit user in team sidebar modal
johnnadeluy Mar 14, 2024
f961ce0
added removeUserfromGroups function
ssb-jnk Mar 14, 2024
05fd92e
Update view for in edit user in team Sidebar Modal with correct data
johnnadeluy Mar 14, 2024
d00fe31
Added functionality to edit user group in team dropdown
ssb-jnk Mar 14, 2024
ee6d493
.
ssb-jnk Mar 14, 2024
61b8acd
Refactors SidebarModal duplicated code for add/edit user in team
johnnadeluy Mar 14, 2024
331a855
temporary fix for removing user from a group
ssb-jnk Mar 15, 2024
7c76eda
.
johnnadeluy Mar 15, 2024
a9db07c
Merge branch 'develop' of https://github.com/statisticsnorway/dapla-c…
johnnadeluy Mar 15, 2024
b29fc01
Merge branch 'develop' of https://github.com/statisticsnorway/dapla-c…
johnnadeluy Mar 18, 2024
b677748
Reset select group dropdown for edit user
johnnadeluy Mar 18, 2024
b54e618
Update edit user requests; include form resets, spinnger and error me…
johnnadeluy Mar 18, 2024
8a7a7bc
Fix double spinner and refactor modal code
johnnadeluy Mar 18, 2024
40f9b91
Add alignment options for Table and center edit user column data
johnnadeluy Mar 18, 2024
fe83fb9
.
johnnadeluy Mar 18, 2024
1853af5
Add delete user feature for edit user in team
johnnadeluy Mar 18, 2024
2316a49
Add conditional rendering for user editing in teams
johnnadeluy Mar 22, 2024
757d36c
Use useCallback for team manager view conditional
johnnadeluy Mar 22, 2024
8042f55
Create DeleteLink component for editing
johnnadeluy Mar 22, 2024
e6a6f55
Merge branch 'develop' of https://github.com/statisticsnorway/dapla-c…
johnnadeluy Mar 22, 2024
3f45b42
Fix view for dropdown on onSelect when editing users
johnnadeluy Mar 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 135 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"eslint-plugin-prettier": "^5.1.3",
"express": "4.18.3",
"express-http-proxy": "^2.0.0",
"http-proxy-middleware": "^2.0.6",
"http-status-codes": "^2.3.0",
"jsonwebtoken": "^9.0.2",
"jwks-rsa": "^3.1.0",
Expand Down
42 changes: 41 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ const app = express()
const PORT = process.env.PORT || 3000
const DAPLA_TEAM_API_URL = process.env.DAPLA_TEAM_API_URL || 'https://dapla-team-api-v2.staging-bip-app.ssb.no'

// Proxy, note this middleware must be place before all else.. THIS TOOK ME 3 HOURS TO FIGURE OUT! TODO: Remove comment
app.use(
'/api',
proxy(DAPLA_TEAM_API_URL, {
proxyReqBodyDecorator: function (bodyContent, srcReq) {
console.log(`Request Body: ${bodyContent}`)
return bodyContent
},
proxyReqOptDecorator: function (proxyReqOpts, srcReq) {
console.log(`Request Headers:`, srcReq.headers)
if (srcReq.body) {
Expand All @@ -34,6 +37,10 @@ app.use(
console.log(`Response Headers:`, proxyRes.headers)
return proxyResData
},
proxyErrorHandler: function (err, res) {
console.error('Proxy Error:', err)
res.status(500).send('Proxy Error')
},
})
)

Expand Down Expand Up @@ -66,6 +73,39 @@ async function fetchPhoto(accessToken, url, fallbackErrorMessage) {
return photoBuffer.toString('base64')
}

//TODO: Remove me once DELETE with proxy is fixed
app.delete('/localApi/groups/:groupUniformName/:userPrincipalName', async (req, res) => {
const token = req.headers.authorization
const groupUniformName = req.params.groupUniformName
const userPrincipalName = req.params.userPrincipalName
const groupsUrl = `${DAPLA_TEAM_API_URL}/groups/${groupUniformName}/users`

try {
const response = await fetch(groupsUrl, {
method: 'DELETE',
headers: {
Accept: '*/*',
'Content-Type': 'application/json',
Authorization: token,
},
body: JSON.stringify({
users: [userPrincipalName],
}),
})

if (!response.ok) {
const err = await response.text()
res.status(response.status).send(err)
} else {
const data = await response.json()
res.status(response.status).send(data)
}
} catch (error) {
console.log(error)
res.status(500).send('Internal Server Error')
}
})

app.get('/localApi/fetch-token', (req, res) => {
if (!req.headers.authorization || !req.headers.authorization.startsWith('Bearer')) {
return res.status(401).json({ message: 'No token provided' })
Expand Down
21 changes: 21 additions & 0 deletions src/components/DeleteLink/DeleteLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import styles from './deletelink.module.scss'

import { Trash2 } from 'react-feather'

interface DeleteLink {
children: string
tabIndex?: number
icon?: boolean
handleDeleteUser: CallableFunction
}

const DeleteLink = ({ children, tabIndex, icon, handleDeleteUser }: DeleteLink) => {
return (
<a className={styles.deleteLinkWrapper} tabIndex={tabIndex ?? 0} onClick={() => handleDeleteUser}>
{icon && <Trash2 size={22} />}
<span>{children}</span>
</a>
)
}

export default DeleteLink
22 changes: 22 additions & 0 deletions src/components/DeleteLink/deletelink.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@use '@statisticsnorway/ssb-component-library/src/style/variables' as variables;

.deleteLinkWrapper {
display: inline-flex;
align-items: center;
color: variables.$ssb-red-3;
padding: .5rem;
line-height: 1.7;
cursor: pointer;

svg {
margin-right: .5rem;
}

span {
border-bottom: 1px solid;
}

&:focus {
@include variables.focus-marker;
}
}
6 changes: 5 additions & 1 deletion src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ interface TableProps extends TableData {
interface TableDesktopViewProps extends TableData {
activeTab?: string
}

export interface TableData {
columns: {
id: string
label: string
unsortable?: boolean
align?: string
}[]
data: {
id: string
Expand Down Expand Up @@ -152,7 +154,9 @@ const TableDesktopView = ({ columns, data, activeTab }: TableDesktopViewProps) =
return (
<tr key={row.id + index} className={conditionalStyling(index)}>
{columns.map((column) => (
<td key={column.id}>{row[column.id]}</td>
<td key={column.id} className={column.align === 'center' ? styles.centerText : undefined}>
{row[column.id]}
</td>
))}
</tr>
)
Expand Down
7 changes: 7 additions & 0 deletions src/components/Table/table.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,11 @@
@media #{variables.$mobile} {
display: flex;
}
}

.centerText {
span {
display: flex;
justify-content: center;
}
}
Loading