Skip to content

Commit 869364a

Browse files
LieutenantRogernqvietyoutionshivam-51fikzzzy
authored
[Bug Bash] Fix 1 (#173)
* issue #145 * fix: issue #110 * Fixed #96 * Reset Pagination to 1 When Choosing Filter * linter * fix: issue #126 * fix: issue #106 * issue #143 * Prevent Trigger Change On Date Picker Input * fix: issue #85 * Fixes #95 * fix: issue #76 * issue #97 * ci:deploying * Add Close Button in Calendar * issue #132 * issue 132: focus selection range when having value * issue 132: fixed duration of a week having 8 days * Clear Challenge Filter On Menu Click * Reset Pagination to 1 * linter * Implement Not Found Error * Use debounce function for sort by * issue #75 * Minor update completed * Updated totalPrizesTo * issue 75: refixed * fix: issue #76 * fix: issue #85 * ci:deploying * Fixes #95 * issue #75 * issue 75: refixed * Use debounce function for sort by * issue #97 * Reset Pagination to 1 When Choosing Filter * linter * issue #145 * Implement Not Found Error * Prevent Trigger Change On Date Picker Input * issue #132 * issue 132: focus selection range when having value * issue 132: fixed duration of a week having 8 days * =resolve merge conflict * Replace Track QA * Reset Pagination * Minor updates done for fixing #96 * fix: lint * fix: refine * restore ci Co-authored-by: Nguyen Viet <nqvietit@gmail.com> Co-authored-by: yoution <zhuyan207@gmail.com> Co-authored-by: Shivam Kumar Singh <shivamhere247@gmail.com> Co-authored-by: M Fikri A <fikzzzy@gmail.com> Co-authored-by: Nguyen Viet <36178659+nqviet@users.noreply.github.com>
1 parent f890395 commit 869364a

File tree

27 files changed

+367
-150
lines changed

27 files changed

+367
-150
lines changed

.circleci/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ workflows:
7777
branches:
7878
only:
7979
- dev
80-
- submission-page
8180

8281
# Production builds are exectuted only on tagged commits to the
8382
# master branch.

config/dev.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,8 @@ module.exports = {
139139
process.env.FILESTACK_SUBMISSION_CONTAINER ||
140140
"topcoder-dev-submissions-dmz",
141141
},
142+
/* Time in MS to wait before refreshing challenge details after register
143+
* and unregister. Used to allow API sufficent time to update.
144+
*/
145+
CHALLENGE_DETAILS_REFRESH_DELAY: 3000,
142146
};

config/prod.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,8 @@ module.exports = {
134134
process.env.FILESTACK_SUBMISSION_CONTAINER ||
135135
"topcoder-dev-submissions-dmz",
136136
},
137+
/* Time in MS to wait before refreshing challenge details after register
138+
* and unregister. Used to allow API sufficent time to update.
139+
*/
140+
CHALLENGE_DETAILS_REFRESH_DELAY: 3000,
137141
};

src/components/DateRangePicker/DateInput/index.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const DateInput = ({
2020
onClickCalendarIcon,
2121
onStartEndDateChange,
2222
placeholder,
23+
enterToSubmit,
2324
}) => {
2425
const ref = useRef(null);
2526
const [focused, setFocused] = useState(false);
@@ -125,7 +126,14 @@ const DateInput = ({
125126
size="xs"
126127
value={rangeText}
127128
onChange={(value) => {
128-
onChangeRangeTextDebounced.current(() => onChangeRangeText(value));
129+
if (!enterToSubmit) {
130+
onChangeRangeTextDebounced.current(() =>
131+
onChangeRangeText(value)
132+
);
133+
}
134+
}}
135+
onEnterKey={(value) => {
136+
onChangeRangeText(value);
129137
}}
130138
placeholder={placeholder}
131139
/>

src/components/DateRangePicker/helpers.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,39 +50,45 @@ const staticRangeHandler = {
5050
* @return {object[]} list of defined ranges
5151
*/
5252
export function createStaticRanges() {
53-
const now = moment().utcOffset(0);
54-
const pastWeek = now.clone().subtract(1, "week");
55-
const pastMonth = now.clone().subtract(1, "month");
56-
const past6Months = now.clone().subtract(6, "month");
57-
const pastYear = now.clone().subtract(1, "year");
53+
const today = moment();
54+
const endOfToday = today.set({
55+
hour: 23,
56+
minute: 59,
57+
second: 59,
58+
millisecond: 999,
59+
});
60+
const pastWeek = endOfToday.clone().subtract(1, "week");
61+
const pastMonth = endOfToday.clone().subtract(1, "month");
62+
const past6Months = endOfToday.clone().subtract(6, "month");
63+
const pastYear = endOfToday.clone().subtract(1, "year");
5864

5965
const ranges = [
6066
{
6167
label: "Past Week",
6268
range: () => ({
6369
startDate: pastWeek.startOf("day").toDate(),
64-
endDate: now.endOf("day").toDate(),
70+
endDate: endOfToday.toDate(),
6571
}),
6672
},
6773
{
6874
label: "Past Month",
6975
range: () => ({
7076
startDate: pastMonth.startOf("day").toDate(),
71-
endDate: now.endOf("day").toDate(),
77+
endDate: endOfToday.toDate(),
7278
}),
7379
},
7480
{
7581
label: "Past 6 Months",
7682
range: () => ({
7783
startDate: past6Months.startOf("day").toDate(),
78-
endDate: now.endOf("day").toDate(),
84+
endDate: endOfToday.toDate(),
7985
}),
8086
},
8187
{
8288
label: "Past Year",
8389
range: () => ({
8490
startDate: pastYear.startOf("day").toDate(),
85-
endDate: now.endOf("day").toDate(),
91+
endDate: endOfToday.toDate(),
8692
}),
8793
},
8894
];

src/components/DateRangePicker/index.jsx

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from "./helpers";
1717

1818
function DateRangePicker(props) {
19-
const { id, range, onChange, placeholder } = props;
19+
const { id, range, onChange, placeholder, enterToSubmit = false } = props;
2020

2121
const [rangeString, setRangeString] = useState({
2222
startDateString: "",
@@ -344,8 +344,19 @@ function DateRangePicker(props) {
344344
const onPreviewChange = (date) => {
345345
if (!(date instanceof Date)) {
346346
setPreview(null);
347-
setActiveDate(null);
348-
setFocusedRange([0, focusedRange[1]]);
347+
348+
// ---
349+
// workaround for fixing issue 132:
350+
// - set the active range's background to transparent color
351+
// to prevent the calendar auto focusing on the day of today by default when no
352+
// start date nor end date are set.
353+
// - does not set focus on the empty selection range when mouse leaves.
354+
// ---
355+
356+
// setActiveDate(null);
357+
if (range.startDate || range.endDate) {
358+
setFocusedRange([0, focusedRange[1]]);
359+
}
349360
return;
350361
}
351362

@@ -485,7 +496,7 @@ function DateRangePicker(props) {
485496
startDate: activeDate,
486497
endDate: activeDate,
487498
key: "active",
488-
color: "#D8FDD8",
499+
color: preview ? "#D8FDD8" : "#D8FDD800",
489500
},
490501
];
491502
}
@@ -538,6 +549,7 @@ function DateRangePicker(props) {
538549
}}
539550
onStartEndDateChange={onStartEndDateChange}
540551
placeholder={placeholder}
552+
enterToSubmit={enterToSubmit}
541553
/>
542554
</div>
543555
<div ref={calendarRef} styleName="calendar-container">
@@ -562,18 +574,29 @@ function DateRangePicker(props) {
562574
preview={preview}
563575
onPreviewChange={onPreviewChange}
564576
/>
565-
<button
566-
type="button"
567-
styleName="reset-button"
568-
onClick={() => {
569-
onDateRangePickerChange({
570-
startDate: null,
571-
endDate: null,
572-
});
573-
}}
574-
>
575-
Reset
576-
</button>
577+
<div styleName="calendar-footer">
578+
<button
579+
type="button"
580+
styleName="calendar-button"
581+
onClick={() => {
582+
onDateRangePickerChange({
583+
startDate: null,
584+
endDate: null,
585+
});
586+
}}
587+
>
588+
Reset
589+
</button>
590+
<button
591+
type="button"
592+
styleName="calendar-button"
593+
onClick={() => {
594+
setIsComponentVisible(false);
595+
}}
596+
>
597+
Close
598+
</button>
599+
</div>
577600
</div>
578601
)}
579602
</div>

src/components/DateRangePicker/style.scss

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ $darkGreen: #0AB88A;;
391391
z-index: 10;
392392

393393
@include phone {
394+
width: 100vw;
394395
position: fixed;
395396
top: 0;
396397
left: 0;
@@ -402,7 +403,15 @@ $darkGreen: #0AB88A;;
402403
border-radius: 0;
403404
}
404405

405-
.reset-button {
406+
.calendar-footer {
407+
width: 100%;
408+
409+
@include phone {
410+
padding: 0 20px;
411+
}
412+
}
413+
414+
.calendar-button {
406415
@include roboto-bold;
407416

408417
width: 71px;
@@ -421,7 +430,7 @@ $darkGreen: #0AB88A;;
421430
height: 26px;
422431
line-height: 27px;
423432
font-size: 12px;
424-
margin: 20px 12px 0;
433+
margin: 0 12px 0;
425434
}
426435
}
427436
}

src/components/DropdownTerms/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ function DropdownTerms({
5151
}
5252
}, [focused, selectedOption]);
5353
useEffect(() => {
54-
setInternalTerms(terms);
55-
}, [terms]);
54+
setInternalTerms(terms); // eslint-disable-next-line react-hooks/exhaustive-deps
55+
}, [terms && terms.length]);
5656

5757
const CustomReactSelectRow = React.forwardRef(
5858
({ className, option, children, onSelect }, ref) =>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from "react";
2+
import IconNotFound from "assets/icons/not-found.png";
3+
4+
import "./styles.scss";
5+
6+
const NotFoundError = ({ message }) => (
7+
<div styleName="not-found-error">
8+
<div>
9+
<img src={IconNotFound} alt="not found" />
10+
</div>
11+
<h1>404 Not found</h1>
12+
<p>Sorry, we couldn’t find that page</p>
13+
</div>
14+
);
15+
16+
export default NotFoundError;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@import "styles/variables";
2+
3+
.not-found-error {
4+
padding: 16px 24px;
5+
min-height: 136px;
6+
margin-bottom: 35px;
7+
font-size: $font-size-sm;
8+
line-height: 22px;
9+
text-align: center;
10+
background: $white;
11+
border-radius: $border-radius-lg;
12+
13+
h1 {
14+
padding: 15px 0 10px;
15+
margin-bottom: 20px;
16+
}
17+
18+
p {
19+
margin-bottom: 8px;
20+
}
21+
}

src/components/Pagination/index.jsx

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useRef, useState } from "react";
1+
import React, { useRef, useState, useEffect } from "react";
22
import PT from "prop-types";
33
import Dropdown from "../Dropdown";
44
import {
@@ -12,6 +12,20 @@ import "./styles.scss";
1212

1313
const N = PAGINATION_MAX_PAGE_DISPLAY;
1414

15+
const createDisplayPages = (p, n) => {
16+
const pages = [];
17+
for (
18+
let start = utils.clamp(p - N, 0, n),
19+
end = utils.clamp(p + N, 0, n),
20+
i = start;
21+
i < end;
22+
i += 1
23+
) {
24+
pages.push(i);
25+
}
26+
return pages.slice(-N);
27+
};
28+
1529
/**
1630
* Pagination with the first page index being as 0 and the last page index being as `total - 1`
1731
*/
@@ -20,24 +34,6 @@ const Pagination = ({ length, pageIndex, pageSize, onChange }) => {
2034
const perPageOptions = utils.createDropdownOptions(PAGINATION_PER_PAGES);
2135
utils.setSelectedDropdownOption(perPageOptions, `${pageSize}`);
2236

23-
const createDisplayPages = (p, n) => {
24-
const pages = [];
25-
for (
26-
let start = utils.clamp(p - N, 0, n),
27-
end = utils.clamp(p + N, 0, n),
28-
i = start;
29-
i < end;
30-
i += 1
31-
) {
32-
pages.push(i);
33-
}
34-
return pages.slice(-N);
35-
};
36-
37-
const [displayPages, setDisplayPages] = useState(
38-
createDisplayPages(pageIndex, total)
39-
);
40-
4137
const onChangePageSize = (options) => {
4238
const selectedOption = utils.getSelectedDropdownOption(options);
4339
const newPageSize = +selectedOption.label;
@@ -59,33 +55,45 @@ const Pagination = ({ length, pageIndex, pageSize, onChange }) => {
5955
}
6056
};
6157

62-
const latestPropsRef = useRef(null);
63-
latestPropsRef.current = { displayPages, pageIndex };
58+
const previousPropsRef = useRef();
59+
const [displayPages, setDisplayPages] = useState([]);
6460

6561
useEffect(() => {
66-
const newTotal = Math.ceil(length / pageSize);
67-
const _pageIndex = latestPropsRef.current.pageIndex;
68-
setDisplayPages(createDisplayPages(_pageIndex, newTotal));
69-
}, [length, pageSize]);
62+
let _displayPages = displayPages;
7063

71-
useEffect(() => {
72-
const _displayPages = latestPropsRef.current.displayPages;
73-
const start = _displayPages[0];
74-
const end = _displayPages[_displayPages.length - 1];
75-
76-
const updateDisplayPages = [];
77-
if (pageIndex < start) {
78-
for (let i = pageIndex; i < pageIndex + N; i += 1) {
79-
updateDisplayPages.push(i);
80-
}
81-
setDisplayPages(updateDisplayPages);
82-
} else if (pageIndex > end) {
83-
for (let i = pageIndex; i > pageIndex - N; i -= 1) {
84-
updateDisplayPages.unshift(i);
64+
if (
65+
!previousPropsRef.current ||
66+
previousPropsRef.current.length !== length ||
67+
previousPropsRef.current.pageSize !== pageSize
68+
) {
69+
const newTotal = Math.ceil(length / pageSize);
70+
_displayPages = createDisplayPages(pageIndex, newTotal);
71+
setDisplayPages(_displayPages);
72+
}
73+
74+
if (
75+
!previousPropsRef.current ||
76+
previousPropsRef.current.pageIndex !== pageIndex
77+
) {
78+
const start = _displayPages[0];
79+
const end = _displayPages[_displayPages.length - 1];
80+
81+
const updateDisplayPages = [];
82+
if (pageIndex < start) {
83+
for (let i = pageIndex; i < pageIndex + N; i += 1) {
84+
updateDisplayPages.push(i);
85+
}
86+
setDisplayPages(updateDisplayPages);
87+
} else if (pageIndex > end) {
88+
for (let i = pageIndex; i > pageIndex - N; i -= 1) {
89+
updateDisplayPages.unshift(i);
90+
}
91+
setDisplayPages(updateDisplayPages);
8592
}
86-
setDisplayPages(updateDisplayPages);
8793
}
88-
}, [pageIndex]);
94+
95+
previousPropsRef.current = { length, pageSize, pageIndex };
96+
}, [length, pageSize, pageIndex, displayPages, setDisplayPages]);
8997

9098
const formatPage = (p) => `${p + 1}`;
9199

0 commit comments

Comments
 (0)