Skip to content

Commit fa6c713

Browse files
committed
Test for direct handle input when assigning in WM
#1415
1 parent 5df32c0 commit fa6c713

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

config/constants/development.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
ACCOUNTS_APP_CONNECTOR_URL: `https://accounts-auth0.${DOMAIN}`,
66
ACCOUNTS_APP_LOGIN_URL: `https://accounts-auth0.${DOMAIN}`,
77
COMMUNITY_APP_URL: `https://www.${DOMAIN}`,
8-
MEMBER_API_URL: `${DEV_API_HOSTNAME}/v4/members`,
8+
MEMBER_API_URL: `${DEV_API_HOSTNAME}/v5/members`,
99
MEMBER_API_V3_URL: `${DEV_API_HOSTNAME}/v3/members`,
1010
CHALLENGE_API_URL: `${DEV_API_HOSTNAME}/v5/challenges`,
1111
CHALLENGE_TIMELINE_TEMPLATES_URL: `${DEV_API_HOSTNAME}/v5/timeline-templates`,

config/constants/production.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
ACCOUNTS_APP_CONNECTOR_URL: process.env.ACCOUNTS_APP_CONNECTOR_URL || `https://accounts-auth0.${DOMAIN}`,
66
ACCOUNTS_APP_LOGIN_URL: `https://accounts-auth0.${DOMAIN}`,
77
COMMUNITY_APP_URL: `https://www.${DOMAIN}`,
8-
MEMBER_API_URL: `${PROD_API_HOSTNAME}/v4/members`,
8+
MEMBER_API_URL: `${PROD_API_HOSTNAME}/v5/members`,
99
MEMBER_API_V3_URL: `${PROD_API_HOSTNAME}/v3/members`,
1010
CHALLENGE_API_URL: `${PROD_API_HOSTNAME}/v5/challenges`,
1111
CHALLENGE_TIMELINE_TEMPLATES_URL: `${PROD_API_HOSTNAME}/v5/timeline-templates`,

src/components/SelectUserAutocomplete/index.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import React, { useState, useCallback } from 'react'
88
import PropTypes from 'prop-types'
99
import Select from '../Select'
10-
import { suggestProfiles } from '../../services/user'
10+
import { suggestProfiles, fetchProfileV5 } from '../../services/user'
1111
import _ from 'lodash'
1212
import { AUTOCOMPLETE_MIN_LENGTH, AUTOCOMPLETE_DEBOUNCE_TIME_MS } from '../../config/constants'
1313

@@ -27,13 +27,17 @@ export default function SelectUserAutocomplete (props) {
2727
return
2828
}
2929

30-
suggestProfiles(inputValue).then((suggestions) => {
31-
const suggestedOptions = suggestions.map((user) => ({
32-
label: user.handle,
33-
value: user.userId.toString()
34-
}))
35-
setOptions(suggestedOptions)
36-
})
30+
Promise.all([suggestProfiles(inputValue), fetchProfileV5(inputValue)]).then(
31+
([suggestions, user]) => {
32+
const suggestedOptions = suggestions.map((u) => ({
33+
label: u.handle,
34+
value: u.userId.toString()
35+
}))
36+
if (user && !_.find(suggestions, u => u.userId === user.userId)) {
37+
suggestedOptions.push({ label: user.handle, value: user.userId.toString() })
38+
}
39+
setOptions(suggestedOptions)
40+
})
3741
}, AUTOCOMPLETE_DEBOUNCE_TIME_MS), []) // debounce, to reduce API calling rate
3842

3943
return (

src/services/user.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import _ from 'lodash'
22
import { axiosInstance } from './axiosWithAuth'
3-
const { MEMBER_API_V3_URL } = process.env
3+
const { MEMBER_API_URL, MEMBER_API_V3_URL } = process.env
44

55
/**
66
* Api request for fetching user profile
@@ -11,6 +11,16 @@ export async function fetchProfile (handle) {
1111
return _.get(response, 'data.result.content')
1212
}
1313

14+
/**
15+
* Api request for fetching user profile v5
16+
* @returns {Promise<*>}
17+
*/
18+
export async function fetchProfileV5 (handle) {
19+
const response = await axiosInstance.get(`${MEMBER_API_URL}?handle=${handle}`)
20+
const data = _.get(response, 'data')
21+
return data.length ? data[0] : undefined
22+
}
23+
1424
/**
1525
* Api request for fetching user profile
1626
* @returns {Promise<*>}

0 commit comments

Comments
 (0)