Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 31582a1

Browse files
authored
Merge pull request #40 from yoution/feature/fix-issue
Feature/fix issue
2 parents d8f522c + d935ee3 commit 31582a1

File tree

8 files changed

+150
-73
lines changed

8 files changed

+150
-73
lines changed

package-lock.json

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/constants/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ export const DAY_FORMAT = "MM/DD/YYYY";
1212
*/
1313
export const TEAM_MEMBERS_PER_PAGE = 5;
1414

15+
/**
16+
* How many teams show per page by default
17+
*/
18+
export const TEAMS_PER_PAGE = 20;
19+
1520
/**
1621
* How many position candidates show per page by default
1722
*/

src/routes/MyTeamsDetails/index.jsx

+1-6
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,9 @@ import TeamSummary from "./components/TeamSummary";
1515
import TeamMembers from "./components/TeamMembers";
1616
import TeamPositions from "./components/TeamPositions";
1717
import { useAsync } from "react-use";
18-
import {
19-
getAuthUserTokens,
20-
} from "@topcoder/micro-frontends-navbar-app";
2118

2219
const MyTeamsDetails = ({ teamId }) => {
23-
const authUserTokens = useAsync(getAuthUserTokens);
24-
const tokenV3 = authUserTokens.value ? authUserTokens.value.tokenV3 : null;
25-
const [team, loadingError] = useData(getTeamById, tokenV3, teamId);
20+
const [team, loadingError] = useData(getTeamById, teamId);
2621

2722
return (
2823
<LayoutContainer>

src/routes/MyTeamsList/index.jsx

+69-15
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,89 @@
33
*
44
* Page for the list of teams.
55
*/
6-
import React from "react";
6+
import React, { useCallback, useState, useEffect } from "react";
7+
import _ from "lodash";
78
import LayoutContainer from "components/LayoutContainer";
89
import PageHeader from "components/PageHeader";
9-
import { useData } from "../../hooks/useData";
10+
import Input from "components/Input";
11+
import Pagination from "components/Pagination";
1012
import { getMyTeams } from "../../services/teams";
1113
import TeamCard from "./components/TeamCard";
1214
import TeamCardGrid from "./components/TeamCardGrid";
1315
import LoadingIndicator from "../../components/LoadingIndicator";
14-
import { useAsync } from "react-use";
15-
import {
16-
getAuthUserTokens,
17-
} from "@topcoder/micro-frontends-navbar-app";
16+
import { useDebounce } from "react-use";
17+
import { TEAMS_PER_PAGE } from "constants";
18+
import "./styles.module.scss";
1819

1920
const MyTeamsList = () => {
20-
const authUserTokens = useAsync(getAuthUserTokens);
21-
const tokenV3 = authUserTokens.value ? authUserTokens.value.tokenV3 : null;
22-
const [myTeams, loadingError] = useData(getMyTeams, tokenV3);
21+
let [myTeams, setMyTeams] = useState(null);
22+
const [filter, setFilter] = useState("");
23+
const [tempFilter, setTempFilter] = React.useState('');
24+
const [loadingError, setLoadingError] = useState(false);
25+
const [page, setPage] = useState(1);
26+
const [total, setTotal] = useState(0);
27+
const onFilterChange = (evt) => {
28+
setTempFilter(evt.target.value)
29+
}
30+
31+
useDebounce((value) => {
32+
console.log('xxxx', value)
33+
setFilter(tempFilter);
34+
setPage(1);
35+
}, 200, [tempFilter]);
36+
37+
useEffect(() => {
38+
setMyTeams(null);
39+
getMyTeams(filter, page, TEAMS_PER_PAGE)
40+
.then((response) => {
41+
setMyTeams(response.data);
42+
setTotal(response.headers["x-total"]);
43+
})
44+
.catch((responseError) => {
45+
setLoadingError(responseError);
46+
});
47+
}, [filter, page]);
48+
49+
const onPageClick = useCallback(
50+
(newPage) => {
51+
setPage(newPage);
52+
},
53+
[setPage]
54+
);
2355

2456
return (
2557
<LayoutContainer>
26-
<PageHeader title="My Teams" />
58+
<PageHeader
59+
title="My Teams"
60+
aside={
61+
<Input
62+
placeholder="Filter by team name"
63+
styleName="filter-input"
64+
onChange={onFilterChange}
65+
/>
66+
}
67+
/>
68+
{myTeams && myTeams.length === 0 && (<div styleName="empty">No teams found</div>)}
2769
{!myTeams ? (
2870
<LoadingIndicator error={loadingError && loadingError.toString()} />
2971
) : (
30-
<TeamCardGrid>
31-
{myTeams.map((team) => (
32-
<TeamCard key={team.id} team={team} />
33-
))}
34-
</TeamCardGrid>
72+
<>
73+
<TeamCardGrid>
74+
{myTeams.map((team) => (
75+
<TeamCard key={team.id} team={team} />
76+
))}
77+
</TeamCardGrid>
78+
{myTeams.length > 0 && (
79+
<div styleName="pagination-wrapper">
80+
<Pagination
81+
total={total}
82+
currentPage={page}
83+
perPage={TEAMS_PER_PAGE}
84+
onPageClick={onPageClick}
85+
/>
86+
</div>
87+
)}
88+
</>
3589
)}
3690
</LayoutContainer>
3791
);
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@import "styles/include";
2+
3+
.filter-input {
4+
width: 380px;
5+
background-color: #FFFFFF;
6+
border: 1px solid #AAAAAA;
7+
border-radius: 6px;
8+
box-sizing: border-box;
9+
color: #2A2A2A;
10+
font-size: 14px;
11+
height: 40px;
12+
line-height: 38px;
13+
outline: none;
14+
padding: 0 15px;
15+
16+
&::placeholder {
17+
color: #AAAAAA;
18+
}
19+
}
20+
21+
.empty {
22+
text-align: center;
23+
}
24+
25+
.pagination-wrapper {
26+
margin-top: 20px;
27+
margin-right: 20px;
28+
display: flex;
29+
justify-content: flex-end;
30+
}
31+
32+
@media (max-width: 650px) {
33+
.filter-input {
34+
width: 100%;
35+
}
36+
}

src/routes/PositionDetails/actions/index.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* Position Details page actions
33
*/
44
import { getPositionDetails, patchPositionCandidate } from "services/teams";
5-
import { getAuthUserTokens } from "@topcoder/micro-frontends-navbar-app";
65
import { ACTION_TYPE } from "constants";
76

87
/**
@@ -16,12 +15,7 @@ import { ACTION_TYPE } from "constants";
1615
export const loadPosition = (teamId, positionId) => ({
1716
type: ACTION_TYPE.LOAD_POSITION,
1817
payload: async () => {
19-
const tokens = await getAuthUserTokens();
20-
const response = await getPositionDetails(
21-
tokens.tokenV3,
22-
teamId,
23-
positionId
24-
);
18+
const response = await getPositionDetails(teamId, positionId);
2519

2620
return response.data;
2721
},
@@ -42,9 +36,7 @@ export const loadPosition = (teamId, positionId) => ({
4236
export const updateCandidate = (candidateId, partialCandidateData) => ({
4337
type: ACTION_TYPE.UPDATE_CANDIDATE,
4438
payload: async () => {
45-
const tokens = await getAuthUserTokens();
4639
const response = await patchPositionCandidate(
47-
tokens.tokenV3,
4840
candidateId,
4941
partialCandidateData
5042
);

src/services/requestInterceptor.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import axios from "axios";
2+
import store from "../store";
3+
import { getAuthUserTokens } from "@topcoder/micro-frontends-navbar-app";
4+
5+
export const axiosInstance = axios.create({
6+
headers: {
7+
"Content-Type": "application/json",
8+
},
9+
});
10+
11+
// request interceptor to pass auth token
12+
axiosInstance.interceptors.request.use((config) => {
13+
return getAuthUserTokens()
14+
.then(({ tokenV3: token }) => {
15+
config.headers["Authorization"] = `Bearer ${token}`;
16+
return config;
17+
})
18+
.catch((err) => {
19+
return config;
20+
});
21+
});

src/services/teams.js

+16-41
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,59 @@
11
/**
22
* Topcoder TaaS Service
33
*/
4-
import axios from "axios";
4+
import { axiosInstance as axios } from "./requestInterceptor";
55
import config from "../../config";
66

77
/**
88
* Get my teams.
9-
*
10-
* @param {string} tokenV3 login token
9+
* @param {string|number} name team name
10+
* @param {number} page current page
11+
* @param {number} perPage perPage
1112
*
1213
* @returns {Promise<object[]>} list of teams
1314
*/
14-
export const getMyTeams = (tokenV3) => {
15-
if (!tokenV3) {
16-
return Promise.resolve({
17-
data: null,
18-
});
15+
export const getMyTeams = (name, page = 1, perPage) => {
16+
let query = `page=${page}&perPage=${perPage}`;
17+
if (name) {
18+
query += `&name=${name}`;
1919
}
20-
return axios.get(`${config.API.V5}/taas-teams`, {
21-
headers: { Authorization: `Bearer ${tokenV3}` },
22-
});
20+
21+
return axios.get(`${config.API.V5}/taas-teams?${query}`);
2322
};
2423

2524
/**
2625
* Get team by id.
2726
*
28-
* @param {string} tokenV3 login token
2927
* @param {string|number} teamId team id
3028
*
3129
* @returns {Promise<{}>} team object
3230
*/
33-
export const getTeamById = (tokenV3, teamId) => {
34-
if (!tokenV3) {
35-
return Promise.resolve({
36-
data: null,
37-
});
38-
}
39-
return axios.get(`${config.API.V5}/taas-teams/${teamId}`, {
40-
headers: { Authorization: `Bearer ${tokenV3}` },
41-
});
31+
export const getTeamById = (teamId) => {
32+
return axios.get(`${config.API.V5}/taas-teams/${teamId}`);
4233
};
4334

4435
/**
4536
* Get team position details.
4637
*
47-
* @param {string} tokenV3 login token
4838
* @param {string|number} teamId team id
4939
* @param {string|number} positionId position id
5040
*
5141
* @returns {Promise<object{}>} job object
5242
*/
53-
export const getPositionDetails = (tokenV3, teamId, positionId) => {
54-
if (!tokenV3) {
55-
return Promise.resolve({
56-
data: null,
57-
});
58-
}
59-
return axios.get(`${config.API.V5}/taas-teams/${teamId}/jobs/${positionId}`, {
60-
headers: { Authorization: `Bearer ${tokenV3}` },
61-
});
43+
export const getPositionDetails = (teamId, positionId) => {
44+
return axios.get(`${config.API.V5}/taas-teams/${teamId}/jobs/${positionId}`);
6245
};
6346

6447
/**
6548
* Patch Position Candidate
6649
*
67-
* @param {string} tokenV3 login token
6850
* @param {string} candidateId position candidate id
6951
*
7052
* @returns {Promise<object{}>} position candidate
7153
*/
72-
export const patchPositionCandidate = (
73-
tokenV3,
74-
candidateId,
75-
partialCandidateData
76-
) => {
54+
export const patchPositionCandidate = (candidateId, partialCandidateData) => {
7755
return axios.patch(
7856
`${config.API.V5}/jobCandidates/${candidateId}`,
79-
partialCandidateData,
80-
{
81-
headers: { Authorization: `Bearer ${tokenV3}` },
82-
}
57+
partialCandidateData
8358
);
8459
};

0 commit comments

Comments
 (0)