diff --git a/config/constants/development.js b/config/constants/development.js index e1bb7da1..f4d30341 100644 --- a/config/constants/development.js +++ b/config/constants/development.js @@ -10,7 +10,6 @@ module.exports = { ACCOUNTS_APP_LOGIN_URL: `https://accounts-auth0.${DOMAIN}`, COMMUNITY_APP_URL: `https://www.${DOMAIN}`, MEMBER_API_URL: `${DEV_API_HOSTNAME}/v5/members`, - MEMBER_API_V3_URL: `${DEV_API_HOSTNAME}/v3/members`, CHALLENGE_API_URL: `${DEV_API_HOSTNAME}/v5/challenges`, CHALLENGE_TIMELINE_TEMPLATES_URL: `${DEV_API_HOSTNAME}/v5/timeline-templates`, CHALLENGE_TYPES_URL: `${DEV_API_HOSTNAME}/v5/challenge-types`, diff --git a/config/constants/production.js b/config/constants/production.js index f3f8af81..29c73f3e 100644 --- a/config/constants/production.js +++ b/config/constants/production.js @@ -10,7 +10,6 @@ module.exports = { ACCOUNTS_APP_LOGIN_URL: `https://accounts-auth0.${DOMAIN}`, COMMUNITY_APP_URL: `https://www.${DOMAIN}`, MEMBER_API_URL: `${PROD_API_HOSTNAME}/v5/members`, - MEMBER_API_V3_URL: `${PROD_API_HOSTNAME}/v3/members`, CHALLENGE_API_URL: `${PROD_API_HOSTNAME}/v5/challenges`, CHALLENGE_TIMELINE_TEMPLATES_URL: `${PROD_API_HOSTNAME}/v5/timeline-templates`, CHALLENGE_TYPES_URL: `${PROD_API_HOSTNAME}/v5/challenge-types`, diff --git a/src/actions/challenges.js b/src/actions/challenges.js index 17a6bcb3..58050ea4 100644 --- a/src/actions/challenges.js +++ b/src/actions/challenges.js @@ -62,6 +62,7 @@ import { removeChallengeFromPhaseProduct, saveChallengeAsPhaseProduct } from '.. * @param {number} page * @param {string} projectId * @param {string} status + * @param {boolean} dashboard is in dashboard or not * @param {string} filterChallengeName * @param {bool} selfService * @param {string} userHandle this will be null for admin user(we will return all datas for admin user) @@ -77,6 +78,7 @@ export function loadChallengesByPage ( page, projectId, status, + dashboard, filterChallengeName = null, selfService = false, userHandle = null, @@ -156,16 +158,21 @@ export function loadChallengesByPage ( filters['memberId'] = userId } - if (status === 'all') { - delete filters['status'] - } else if (!_.isEmpty(status)) { - filters['status'] = status === '' ? undefined : _.startCase(status.toLowerCase()) - } else if (!(_.isInteger(projectId) && projectId > 0)) { + if (status !== 'all') { + filters['status'] = !status ? undefined : _.startCase(status.toLowerCase()) + } + + if (!dashboard && !filters['status'] && !(_.isInteger(projectId) && projectId > 0)) { filters['status'] = 'Active' } if (selfService) { filters.selfService = true - if (userHandle && filters.status.toUpperCase() !== CHALLENGE_STATUS.DRAFT && filters.status.toUpperCase() !== CHALLENGE_STATUS.NEW) { + const filtersStatus = filters.status ? filters.status.toUpperCase() : filters.status + if ( + userHandle && + filtersStatus !== CHALLENGE_STATUS.DRAFT && + filtersStatus !== CHALLENGE_STATUS.NEW + ) { filters.selfServiceCopilot = userHandle } } diff --git a/src/components/ChallengesComponent/ChallengeList/index.js b/src/components/ChallengesComponent/ChallengeList/index.js index 2dc5754a..57b63282 100644 --- a/src/components/ChallengesComponent/ChallengeList/index.js +++ b/src/components/ChallengesComponent/ChallengeList/index.js @@ -31,7 +31,7 @@ require('bootstrap/scss/bootstrap.scss') const defaultSearchParam = { searchText: '', challengeProjectOption: null, - challengeStatus: '', + challengeStatus: 'all', challengeType: null, sortBy: 'startDate', sortOrder: 'desc', @@ -112,7 +112,8 @@ class ChallengeList extends Component { loadChallengesByPage( 1, projectId, - !projectStatus ? 'all' : projectStatus, + projectStatus, + dashboard, searchText, selfService, this.getHandle(), @@ -150,6 +151,7 @@ class ChallengeList extends Component { pageNumber, projectId, status, + dashboard, searchText, selfService, this.getHandle(), @@ -188,6 +190,7 @@ class ChallengeList extends Component { 1, projectId, status, + dashboard, searchText, selfService, this.getHandle(), @@ -211,12 +214,14 @@ class ChallengeList extends Component { loadChallengesByPage, activeProjectId, status, - selfService + selfService, + dashboard } = this.props loadChallengesByPage( page, activeProjectId, status, + dashboard, searchText, selfService, this.getHandle(), @@ -301,6 +306,7 @@ class ChallengeList extends Component { page, projectId, status, + dashboard, searchText, selfService, this.getHandle(), @@ -346,15 +352,16 @@ class ChallengeList extends Component { loadChallengesByPage( 1, projectId, - 'all', - '', + defaultSearchParam.challengeStatus, + dashboard, + defaultSearchParam.searchText, selfService, this.getHandle(), this.getLoginUserId(), - null, - {}, - null, - null, + defaultSearchParam.challengeType, + defaultSearchParam.challengeDate, + defaultSearchParam.sortBy, + defaultSearchParam.sortOrder, PAGE_SIZE ) } diff --git a/src/components/SelectUserAutocomplete/index.js b/src/components/SelectUserAutocomplete/index.js index 7c87f729..ccadc5c3 100644 --- a/src/components/SelectUserAutocomplete/index.js +++ b/src/components/SelectUserAutocomplete/index.js @@ -7,7 +7,7 @@ import React, { useState, useCallback } from 'react' import PropTypes from 'prop-types' import Select from '../Select' -import { suggestProfilesV5, fetchProfileV5 } from '../../services/user' +import { suggestProfiles, fetchProfile } from '../../services/user' import _ from 'lodash' import { AUTOCOMPLETE_MIN_LENGTH, AUTOCOMPLETE_DEBOUNCE_TIME_MS } from '../../config/constants' @@ -27,7 +27,7 @@ export default function SelectUserAutocomplete (props) { return } - Promise.all([suggestProfilesV5(inputValue), fetchProfileV5(inputValue)]).then( + Promise.all([suggestProfiles(inputValue), fetchProfile(inputValue)]).then( ([suggestions, user]) => { const suggestedOptions = suggestions.map((u) => ({ label: u.handle, diff --git a/src/components/Tab/index.js b/src/components/Tab/index.js index 01649259..0a8c9bf9 100644 --- a/src/components/Tab/index.js +++ b/src/components/Tab/index.js @@ -28,6 +28,13 @@ const Tab = ({ selectTab(3) } + const onSelfServiceClick = () => { + if (currentTab === 4) { + return + } + selectTab(4) + } + const tabComponent = ( ) diff --git a/src/containers/Challenges/index.js b/src/containers/Challenges/index.js index 35b4b750..ca5dfa97 100644 --- a/src/containers/Challenges/index.js +++ b/src/containers/Challenges/index.js @@ -81,7 +81,8 @@ class Challenges extends Component { this.props.loadChallengesByPage( 1, projectId ? parseInt(projectId) : -1, - dashboard ? 'all' : '', + 'all', + dashboard, '', selfService, isAdmin ? null : this.props.auth.user.handle, diff --git a/src/containers/Tab/index.js b/src/containers/Tab/index.js index 553de850..327d9362 100644 --- a/src/containers/Tab/index.js +++ b/src/containers/Tab/index.js @@ -41,6 +41,8 @@ class TabContainer extends Component { this.setState({ currentTab: 2 }) } else if (nextProps.history.location.pathname === '/users') { this.setState({ currentTab: 3 }) + } else if (nextProps.history.location.pathname === '/self-service') { + this.setState({ currentTab: 4 }) } else { this.setState({ currentTab: 0 }) } @@ -85,6 +87,9 @@ class TabContainer extends Component { } else if (tab === 3) { history.push('/users') this.setState({ currentTab: 3 }) + } else if (tab === 4) { + history.push('/self-service') + this.setState({ currentTab: 4 }) } resetSidebarActiveParams() diff --git a/src/services/user.js b/src/services/user.js index fc7bd888..b3eef804 100644 --- a/src/services/user.js +++ b/src/services/user.js @@ -1,36 +1,27 @@ import _ from 'lodash' import { axiosInstance } from './axiosWithAuth' -const { MEMBER_API_URL, MEMBER_API_V3_URL } = process.env +const { MEMBER_API_URL } = process.env /** * Api request for fetching user profile * @returns {Promise<*>} */ export async function fetchProfile (handle) { - const response = await axiosInstance.get(`${MEMBER_API_V3_URL}/${handle}`) - return _.get(response, 'data.result.content') -} - -/** - * Api request for fetching user profile v5 - * @returns {Promise<*>} - */ -export async function fetchProfileV5 (handle) { - const response = await axiosInstance.get(`${MEMBER_API_URL}?handle=${handle}`) - const data = _.get(response, 'data') - return data.length ? data[0] : undefined + const response = await axiosInstance.get(`${MEMBER_API_URL}/${handle}`) + return _.get(response, 'data') } /** - * Api request for fetching user profile + * Api request for searching profiles * @returns {Promise<*>} */ -export async function searchProfiles (fields, query, limit) { - const response = await axiosInstance.get(`${MEMBER_API_V3_URL}/_search`, { +export async function searchProfiles (fields, queryObject = {}, limit) { + const response = await axiosInstance.get(`${MEMBER_API_URL}`, { params: { fields, - query, - limit + ...queryObject, + perPage: limit, + page: 1 } }) return _.get(response, 'data.result.content') @@ -41,14 +32,13 @@ export async function searchProfiles (fields, query, limit) { * @returns {Promise<*>} */ export async function searchProfilesByUserIds (userIds, fields = 'userId,handle,firstName,lastName,email', limit) { - const response = await axiosInstance.get(`${MEMBER_API_V3_URL}/_search`, { - params: { - query: `${_.map(userIds, id => `userId:${id}`).join(encodeURIComponent(' OR '))}`, - fields, - limit - } - }) - return _.get(response, 'data.result.content') + return searchProfiles( + fields, + { + userIds + }, + limit + ) } /** @@ -56,15 +46,6 @@ export async function searchProfilesByUserIds (userIds, fields = 'userId,handle, * @returns {Promise<*>} */ export async function suggestProfiles (partialHandle) { - const response = await axiosInstance.get(`${MEMBER_API_V3_URL}/_suggest/${encodeURIComponent(partialHandle)}`) - return _.get(response, 'data.result.content') -} - -/** - * Api request for finding (suggesting) users by the part of the handle - * @returns {Promise<*>} - */ -export async function suggestProfilesV5 (partialHandle) { const response = await axiosInstance.get(`${MEMBER_API_URL}/autocomplete?term=${encodeURIComponent(partialHandle)}`) return _.get(response, 'data') }