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

Commit 8177028

Browse files
committed
fix review feedbacks (WIP)
1 parent c5138aa commit 8177028

File tree

47 files changed

+674
-160
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+674
-160
lines changed

src/actions/auth.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/actions/challenges.js

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ async function doGetChallenges(filter) {
77
return service.getChallenges(filter);
88
}
99

10-
async function getActiveChallenges(filter) {
10+
async function getAllActiveChallenges(filter) {
1111
const activeFilter = {
1212
...util.createChallengeCriteria(filter),
13-
...util.createActiveChallengeCriteria(),
13+
...util.createAllActiveChallengeCriteria(),
1414
};
1515
return doGetChallenges(activeFilter);
1616
}
@@ -23,14 +23,20 @@ async function getOpenForRegistrationChallenges(filter) {
2323
return doGetChallenges(openForRegistrationFilter);
2424
}
2525

26-
async function getPastChallenges(filter) {
26+
async function getClosedChallenges(filter) {
2727
const pastFilter = {
2828
...util.createChallengeCriteria(filter),
29-
...util.createPastChallengeCriteria(),
29+
...util.createClosedChallengeCriteria(),
3030
};
3131
return doGetChallenges(pastFilter);
3232
}
3333

34+
async function getRecommendedChallenges(filter) {
35+
const result = []
36+
result.meta = { total: 0 }
37+
return result;
38+
}
39+
3440
function doFilterBySubSommunities(challenges) {
3541
return challenges;
3642
}
@@ -43,46 +49,69 @@ function doFilterByPrizeTo(challenges) {
4349

4450
async function getChallenges(filter, change) {
4551
const FILTER_BUCKETS = constants.FILTER_BUCKETS;
46-
let challenges;
47-
let challengesFiltered;
48-
let total;
49-
let filterChange = change;
50-
51-
const getChallengesByBucket = async (f) => {
52-
switch (f.bucket) {
53-
case FILTER_BUCKETS[0]:
54-
return getActiveChallenges(f);
55-
case FILTER_BUCKETS[1]:
56-
return getOpenForRegistrationChallenges(f);
57-
case FILTER_BUCKETS[2]:
58-
return getPastChallenges(f);
59-
default:
60-
return [];
61-
}
52+
const BUCKET_ALL_ACTIVE_CHALLENGES = FILTER_BUCKETS[0];
53+
const BUCKET_OPEN_FOR_REGISTRATION = FILTER_BUCKETS[1];
54+
const BUCKET_PAST_CHALLENGES = FILTER_BUCKETS[2];
55+
const filterChange = change;
56+
const bucket = filter.bucket;
57+
58+
const getChallengesByBuckets = async (f) => {
59+
return FILTER_BUCKETS.includes(f.bucket)
60+
? Promise.all([
61+
getAllActiveChallenges(f),
62+
f.recommended ? getRecommendedChallenges() : getOpenForRegistrationChallenges(f),
63+
getClosedChallenges(f)
64+
])
65+
: [[], [], []]
6266
};
6367

68+
if (!filterChange) {
69+
let [allActiveChallenges, openForRegistrationChallenges, closedChallenges] = await getChallengesByBuckets(filter)
70+
let challenges;
71+
let openForRegistrationCount;
72+
let total;
73+
74+
switch (bucket) {
75+
case BUCKET_ALL_ACTIVE_CHALLENGES: challenges = allActiveChallenges; break;
76+
case BUCKET_OPEN_FOR_REGISTRATION: challenges = openForRegistrationChallenges; break;
77+
case BUCKET_PAST_CHALLENGES: challenges = closedChallenges; break;
78+
}
79+
openForRegistrationCount = openForRegistrationChallenges.meta.total;
80+
total = challenges.meta.total;
81+
82+
return { challenges, total, openForRegistrationCount, allActiveChallenges, openForRegistrationChallenges, closedChallenges };
83+
}
84+
6485
if (!util.checkRequiredFilterAttributes(filter)) {
6586
return { challenges: [], challengesFiltered: [], total: 0 };
6687
}
6788

68-
if (!filterChange) {
69-
const chs = await getChallengesByBucket(filter);
70-
return { challenges: chs, challengesFiltered: chs, total: chs.meta.total };
71-
}
89+
let allActiveChallenges;
90+
let openForRegistrationChallenges;
91+
let closedChallenges;
92+
let challenges;
93+
let openForRegistrationCount;
94+
let total;
7295

7396
if (util.shouldFetchChallenges(filterChange)) {
74-
challenges = await getChallengesByBucket(filter);
97+
[allActiveChallenges, openForRegistrationChallenges, closedChallenges] = await getChallengesByBuckets(filter)
98+
switch (bucket) {
99+
case BUCKET_ALL_ACTIVE_CHALLENGES: challenges = allActiveChallenges; break;
100+
case BUCKET_OPEN_FOR_REGISTRATION: challenges = openForRegistrationChallenges; break;
101+
case BUCKET_PAST_CHALLENGES: challenges = closedChallenges; break;
102+
}
75103
}
76104

77-
challengesFiltered = challenges;
105+
openForRegistrationCount = openForRegistrationChallenges.meta.total;
78106
total = challenges.meta.total;
107+
79108
if (util.shouldFilterChallenges(filterChange)) {
80-
challengesFiltered = doFilterBySubSommunities(challengesFiltered);
81-
challengesFiltered = doFilterByPrizeFrom(challengesFiltered);
82-
challengesFiltered = doFilterByPrizeTo(challengesFiltered);
109+
challenges = doFilterBySubSommunities(challenges);
110+
challenges = doFilterByPrizeFrom(challenges);
111+
challenges = doFilterByPrizeTo(challenges);
83112
}
84113

85-
return { challenges, challengesFiltered, total };
114+
return { challenges, total, openForRegistrationCount, allActiveChallenges, openForRegistrationChallenges, closedChallenges };
86115
}
87116

88117
export default createActions({

src/actions/filter.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { createActions } from "redux-actions";
22

3+
function restoreFilter (filter) {
4+
return filter;
5+
}
6+
37
function updateFilter(partialUpdate) {
48
return partialUpdate;
59
}
610

711
export default createActions({
12+
RESTORE_FILTER: restoreFilter,
813
UPDATE_FILTER: updateFilter,
914
});

src/assets/icons/card-view.svg

Lines changed: 10 additions & 0 deletions
Loading

src/assets/icons/list-view.svg

Lines changed: 10 additions & 0 deletions
Loading
1.26 KB
Loading

src/components/Button/index.jsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PT from "prop-types";
44
import "./styles.scss";
55

66
const Button = ({ children, onClick }) => (
7-
<button styleName="button" onClick={onClick}>
7+
<button styleName="button" onClick={onClick} type="button">
88
{children}
99
</button>
1010
);
@@ -14,4 +14,20 @@ Button.propTypes = {
1414
onClick: PT.func,
1515
};
1616

17+
const ButtonIcon = ({ children, onClick }) => (
18+
<button styleName="button-icon" onClick={onClick} type="button">
19+
{children}
20+
</button>
21+
)
22+
23+
ButtonIcon.propTypes = {
24+
children: PT.node,
25+
onClick: PT.func,
26+
};
27+
28+
export {
29+
Button,
30+
ButtonIcon,
31+
}
32+
1733
export default Button;

src/components/Button/styles.scss

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,15 @@
2222
background-color: $green;
2323
}
2424

25-
.button-lg {}
26-
.button-sm {}
25+
.button-icon {
26+
width: 32px;
27+
height: 32px;
28+
padding: 0;
29+
line-height: 0;
30+
text-align: center;
31+
vertical-align: middle;
32+
appearance: none;
33+
background: none;
34+
border: 0;
35+
border-radius: 50%;
36+
}

src/components/Checkbox/index.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Checkbox component.
33
*/
4-
import React, { useRef, useState } from "react";
4+
import React, { useRef, useState, useEffect } from "react";
55
import PT from "prop-types";
66
import _ from "lodash";
77
import "./styles.scss";
@@ -22,6 +22,10 @@ function Checkbox({ checked, onChange, size, errorMsg }) {
2222
_.debounce((q, cb) => cb(q), process.env.GUIKIT.DEBOUNCE_ON_CHANGE_TIME) // eslint-disable-line no-undef
2323
).current;
2424

25+
useEffect(() => {
26+
setCheckedInternal(checked)
27+
}, [checked])
28+
2529
return (
2630
<label styleName={`container ${sizeStyle}`}>
2731
<input
Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,78 @@
1-
import React from "react";
1+
import React, { useRef, useEffect } from "react";
22
import PT from "prop-types";
33
import TextInput from "../../TextInput";
4+
import CalendarIcon from 'assets/icons/icon-calendar.svg';
45

56
import "./styles.scss";
67

7-
const DateInput = ({ value, onClick }) => (
8-
<div onClick={onClick} styleName="date-range-input">
9-
<TextInput label="From" size="xs" value={value} readonly />
10-
</div>
11-
);
8+
const DateInput = ({
9+
id,
10+
isStartDateActive,
11+
startDateString,
12+
onStartDateChange,
13+
onStartDateFocus,
14+
isEndDateActive,
15+
endDateString,
16+
onEndDateChange,
17+
onEndDateFocus,
18+
error,
19+
onClickCalendarIcon
20+
}) => {
21+
const ref = useRef(null);
1222

13-
DateInput.propTypes = {};
23+
let rangeText;
24+
if (startDateString && endDateString) {
25+
rangeText = `${startDateString} - ${endDateString}`;
26+
} else {
27+
rangeText = `${startDateString}${endDateString}`;
28+
}
29+
30+
const onChangeRangeText = (value) => {
31+
const [start, end] = value.trim().split(' - ')
32+
const event = { startDateString: start, endDateString: end }
33+
onStartDateChange(event)
34+
onEndDateChange(event)
35+
}
36+
37+
const onFocusInput = (e) => {
38+
if (startDateString) {
39+
onEndDateFocus()
40+
} else {
41+
onStartDateFocus()
42+
}
43+
}
44+
45+
useEffect(() => {
46+
const inputElement = ref.current.querySelector('input');
47+
inputElement.addEventListener('focus', onFocusInput);
48+
49+
return () => {
50+
inputElement.removeEventListener('focus', onFocusInput);
51+
}
52+
})
53+
54+
const onClickIcon = () => {
55+
if (startDateString) {
56+
onClickCalendarIcon('end')
57+
} else {
58+
onClickCalendarIcon('start')
59+
}
60+
}
61+
62+
return (
63+
<div styleName={`container ${error ? 'isError' : ''}`}>
64+
<div styleName="date-range-input input-group" ref={ref}>
65+
<TextInput label="From" size="xs" value={rangeText} onChange={onChangeRangeText} />
66+
<div id="input-date-range-calendar-icon" styleName="icon" role="button" onClick={onClickIcon}><CalendarIcon /></div>
67+
</div>
68+
<div styleName="errorHint">{error}</div>
69+
</div>
70+
);
71+
}
72+
73+
74+
DateInput.propTypes = {
75+
onClick: PT.func,
76+
};
1477

1578
export default DateInput;
Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,44 @@
11
@import "styles/variables";
22

3+
.container {
4+
&.isError {
5+
input {
6+
border: 1px solid $tc-level-5;
7+
}
8+
9+
.errorHint {
10+
display: block;
11+
color: $tc-level-5;
12+
font-size: 12px;
13+
padding: 4px 0;
14+
height: 20px;
15+
}
16+
}
17+
}
18+
319
.date-range-input {
420
width: 230px;
21+
margin-top: -12px;
522
font-size: $font-size-sm;
23+
}
24+
25+
.input-group {
26+
position: relative;
27+
28+
.icon {
29+
position: absolute;
30+
top: 22px;
31+
right: 14px;
32+
z-index: 1;
33+
display: block;
34+
cursor: pointer;
35+
}
636

737
input {
8-
color: $body-color !important;
9-
border-color: $tc-gray-30 !important;
38+
padding-right: 46px !important;
1039
}
1140
}
41+
42+
.errorHint {
43+
display: none;
44+
}

src/components/DateRangePicker/helpers.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ const staticRangeHandler = {
5050
* @return {object[]} list of defined ranges
5151
*/
5252
export function createStaticRanges() {
53-
const now = moment();
54-
const pastWeek = moment().subtract(1, "week");
55-
const pastMonth = moment().subtract(1, "month");
56-
const past6Months = moment().subtract(6, "month");
57-
const pastYear = moment().subtract(1, "year");
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");
5858

5959
const ranges = [
6060
{

0 commit comments

Comments
 (0)