Skip to content

Commit 82abd38

Browse files
committed
Refactor external profile button
1 parent f2fe491 commit 82abd38

File tree

2 files changed

+64
-69
lines changed

2 files changed

+64
-69
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import Button from './button'
2+
import join from 'url-join'
3+
const URL = process.env.APP_URL
4+
5+
const ExternalProfileButton = ({ type, userId }) => {
6+
let targetLink
7+
let title
8+
let label
9+
let altText
10+
let logoImg
11+
12+
switch (type) {
13+
case 'osm-profile':
14+
targetLink = `https://www.openstreetmap.org/user/${userId}`
15+
title = 'View profile on OSM'
16+
label = 'OSM'
17+
altText = 'OSM Logo'
18+
logoImg = 'osm_logo.png'
19+
break
20+
case 'hdyc':
21+
targetLink = `https://hdyc.neis-one.org/?${userId}`
22+
title = 'View profile on HDYC'
23+
label = 'HDYC'
24+
altText = 'How Do You Contribute Logo'
25+
logoImg = 'neis-one-logo.png'
26+
break
27+
case 'osmcha':
28+
targetLink = `https://osmcha.org/?filters={"users":[{"label":"${userId}","value":"${userId}"}]}`
29+
title = 'View profile on OSMCha'
30+
label = 'OSMCha'
31+
altText = 'OSMCha Logo'
32+
logoImg = 'icon-osmcha-logo.svg'
33+
break
34+
default:
35+
return null
36+
}
37+
38+
return (
39+
<Button
40+
onClick={(e) => {
41+
e.stopPropagation()
42+
window.open(targetLink, '_blank', 'noreferrer')
43+
}}
44+
flat
45+
size='small'
46+
className='unstyled small'
47+
title={title}
48+
>
49+
<img
50+
src={`${join(URL, `/static/${logoImg}`)}`}
51+
alt={altText}
52+
width='16'
53+
height='16'
54+
/>
55+
{label}
56+
</Button>
57+
)
58+
}
59+
60+
export default ExternalProfileButton

src/pages/teams/[id]/members-table.js

Lines changed: 4 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import T from 'prop-types'
22
import Table from '../../../components/tables/table'
33
import { useState } from 'react'
4-
import join from 'url-join'
54

65
import Pagination from '../../../components/pagination'
76
import { serverRuntimeConfig } from '../../../../next.config.js'
87
import * as R from 'ramda'
98
import SearchInput from '../../../components/tables/search-input'
10-
import Button from '../../../components/button'
11-
const URL = process.env.APP_URL
9+
import ExternalProfileButton from '../../../components/external-profile-button'
1210
const { DEFAULT_PAGE_SIZE } = serverRuntimeConfig
1311

1412
function MembersTable({ rows: allRows, onRowClick }) {
@@ -27,72 +25,9 @@ function MembersTable({ rows: allRows, onRowClick }) {
2725
key: 'External Profiles',
2826
render: ({ name }) => (
2927
<>
30-
<Button
31-
onClick={(e) => {
32-
e.stopPropagation()
33-
window.open(
34-
`https://www.openstreetmap.org/user/${name}`,
35-
'_blank',
36-
'noreferrer'
37-
)
38-
}}
39-
flat
40-
size='small'
41-
className='unstyled small'
42-
title='View profile on OSM'
43-
>
44-
<img
45-
src={`${join(URL, `/static/osm_logo.png`)}`}
46-
alt='OSM Logo'
47-
width='16'
48-
height='16'
49-
/>
50-
OSM
51-
</Button>
52-
<Button
53-
onClick={(e) => {
54-
e.stopPropagation()
55-
window.open(
56-
`https://hdyc.neis-one.org/?${name}`,
57-
'_blank',
58-
'noreferrer'
59-
)
60-
}}
61-
flat
62-
size='small'
63-
className='unstyled small'
64-
title='View profile on HDYC'
65-
>
66-
<img
67-
src={`${join(URL, `/static/neis-one-logo.png`)}`}
68-
alt='How Do You Contribute Logo'
69-
width='16'
70-
height='16'
71-
/>
72-
HDYC
73-
</Button>
74-
<Button
75-
onClick={(e) => {
76-
e.stopPropagation()
77-
window.open(
78-
`https://osmcha.org/?filters={"users":[{"label":"${name}","value":"${name}"}]}`,
79-
'_blank',
80-
'noreferrer'
81-
)
82-
}}
83-
flat
84-
size='small'
85-
className='unstyled small'
86-
title='View profile on OSMCha'
87-
>
88-
<img
89-
src={`${join(URL, `/static/icon-osmcha-logo.svg`)}`}
90-
alt='OSMCha Logo'
91-
width='16'
92-
height='16'
93-
/>
94-
OSMCha
95-
</Button>
28+
<ExternalProfileButton type='osm-profile' userId={name} />
29+
<ExternalProfileButton type='hdyc' userId={name} />
30+
<ExternalProfileButton type='osmcha' userId={name} />
9631
</>
9732
),
9833
},

0 commit comments

Comments
 (0)