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

Commit 5596aad

Browse files
committed
fix: issue #37
1 parent 5181c3f commit 5596aad

File tree

6 files changed

+119
-12
lines changed

6 files changed

+119
-12
lines changed

package-lock.json

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

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"dev": "webpack-dev-server --port 8501 --host 0.0.0.0",
66
"dev-https": "webpack-dev-server --https --port 8501 --host 0.0.0.0",
77
"build": "webpack --mode=${APPMODE:-development} --env.config=${APPENV:-dev}",
8+
"build:prod": "webpack --mode=${APPMODE:-production} --env.config=${APPENV:-prod}",
89
"analyze": "webpack --mode=production --env.analyze=true",
910
"lint": "eslint src --ext js",
1011
"format": "prettier --write \"./**\"",
@@ -74,7 +75,8 @@
7475
"redux": "^4.0.5",
7576
"redux-logger": "^3.0.6",
7677
"redux-promise-middleware": "^6.1.2",
77-
"redux-thunk": "^2.3.0"
78+
"redux-thunk": "^2.3.0",
79+
"use-debounce": "^5.2.0"
7880
},
7981
"browserslist": [
8082
"last 1 version",

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/MyTeamsList/index.jsx

+63-9
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,84 @@
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";
9+
import { useDebouncedCallback } from "use-debounce";
810
import PageHeader from "components/PageHeader";
9-
import { useData } from "../../hooks/useData";
11+
import Input from "components/Input";
12+
import Pagination from "components/Pagination";
1013
import { getMyTeams } from "../../services/teams";
1114
import TeamCard from "./components/TeamCard";
1215
import TeamCardGrid from "./components/TeamCardGrid";
1316
import LoadingIndicator from "../../components/LoadingIndicator";
1417
import { useAsync } from "react-use";
18+
import { TEAMS_PER_PAGE } from "constants";
19+
import "./styles.module.scss";
1520

1621
const MyTeamsList = () => {
17-
const [myTeams, loadingError] = useData(getMyTeams);
22+
// let [myTeams, loadingError] = useData(getMyTeams);
23+
let [myTeams, setMyTeams] = useState();
24+
const [filter, setFilter] = useState("");
25+
const [loadingError, setLoadingError] = useState(false);
26+
const [page, setPage] = useState(1);
27+
const [total, setTotal] = useState(0);
28+
29+
const onFilterChange = useDebouncedCallback((value) => {
30+
setFilter(value);
31+
setPage(1);
32+
}, 200);
33+
34+
useEffect(() => {
35+
getMyTeams(filter, page, TEAMS_PER_PAGE)
36+
.then((response) => {
37+
setMyTeams(response.data);
38+
setTotal(response.headers["x-total"]);
39+
})
40+
.catch((responseError) => {
41+
setLoadingError(responseError);
42+
});
43+
}, [filter, page]);
44+
45+
const onPageClick = useCallback(
46+
(newPage) => {
47+
setPage(newPage);
48+
},
49+
[setPage]
50+
);
1851

1952
return (
2053
<LayoutContainer>
21-
<PageHeader title="My Teams" />
54+
<PageHeader
55+
title="My Teams"
56+
aside={
57+
<Input
58+
placeholder="Filter by team name"
59+
styleName="filter-input"
60+
onChange={(e) => onFilterChange.callback(e.target.value)}
61+
/>
62+
}
63+
/>
2264
{!myTeams ? (
2365
<LoadingIndicator error={loadingError && loadingError.toString()} />
2466
) : (
25-
<TeamCardGrid>
26-
{myTeams.map((team) => (
27-
<TeamCard key={team.id} team={team} />
28-
))}
29-
</TeamCardGrid>
67+
<>
68+
<TeamCardGrid>
69+
{myTeams.map((team) => (
70+
<TeamCard key={team.id} team={team} />
71+
))}
72+
</TeamCardGrid>
73+
{myTeams.length > 0 && (
74+
<div styleName="pagination-wrapper">
75+
<Pagination
76+
total={total}
77+
currentPage={page}
78+
perPage={TEAMS_PER_PAGE}
79+
onPageClick={onPageClick}
80+
/>
81+
</div>
82+
)}
83+
</>
3084
)}
3185
</LayoutContainer>
3286
);
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
22+
.pagination-wrapper {
23+
margin-top: 20px;
24+
margin-right: 20px;
25+
display: flex;
26+
justify-content: flex-end;
27+
}
28+
29+
@media (max-width: 650px) {
30+
.filter-input {
31+
width: 100%;
32+
}
33+
}

src/services/teams.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@ import config from "../../config";
66

77
/**
88
* Get my teams.
9+
* @param {string|number} name team name
10+
* @param {number} page current page
11+
* @param {number} perPage perPage
912
*
1013
* @returns {Promise<object[]>} list of teams
1114
*/
12-
export const getMyTeams = () => {
13-
return axios.get(`${config.API.V5}/taas-teams`);
15+
export const getMyTeams = (name, page = 1, perPage) => {
16+
let query = `page=${page}&perPage=${perPage}`;
17+
if (name) {
18+
query += `&name=${name}`;
19+
}
20+
21+
return axios.get(`${config.API.V5}/taas-teams?${query}`);
1422
};
1523

1624
/**

0 commit comments

Comments
 (0)