Skip to content

Commit dbe99ef

Browse files
committed
feat: add DatePicker to Conferences search page
1 parent ac68cf4 commit dbe99ef

File tree

4 files changed

+189
-8
lines changed

4 files changed

+189
-8
lines changed

client/.eslintrc.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,6 @@ module.exports = {
7070
'import/no-unresolved': 2,
7171
'import/no-webpack-loader-syntax': 0,
7272
'import/prefer-default-export': 0,
73-
indent: [
74-
2,
75-
2,
76-
{
77-
SwitchCase: 1,
78-
},
79-
],
8073
'react/destructuring-assignment': 0,
8174
'react/jsx-closing-tag-location': 0,
8275
'react/forbid-prop-types': 0,

client/src/components/ConferencesSearch/ConferencesSearch.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import React, { Component } from 'react'
2+
import PropTypes from 'prop-types'
23
import { Section, Container, Row, TextInput } from 'react-materialize'
4+
import DatePicker from 'components/DatePicker'
35
import SearchButton from 'components/SearchButton'
46

57
class SearchConference extends Component {
8+
static propTypes = {
9+
className: PropTypes.string,
10+
}
11+
612
state = {}
713

814
render() {
@@ -36,6 +42,15 @@ class SearchConference extends Component {
3642
})
3743
}}
3844
/>
45+
<DatePicker
46+
s={12}
47+
label="Conference date"
48+
onChange={date => {
49+
this.setState({
50+
date: new Date(date).toISOString(),
51+
})
52+
}}
53+
/>
3954
</Row>
4055
</Container>
4156
</Section>
@@ -46,7 +61,15 @@ class SearchConference extends Component {
4661
Object.keys(this.state).length
4762
? `?filter=${Object.entries(this.state)
4863
.filter(([, value]) => value.length)
49-
.map(([field, value]) => encodeURIComponent(`${field} iLike %${value}%`))
64+
.map(([field, value]) => {
65+
switch (field) {
66+
case 'date':
67+
return encodeURIComponent(`${field} eq ${value}`)
68+
69+
default:
70+
return encodeURIComponent(`${field} iLike %${value}%`)
71+
}
72+
})
5073
.join(',')}`
5174
: ''
5275
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
import React from 'react'
2+
import PropTypes from 'prop-types'
3+
import { TextInput } from 'react-materialize'
4+
import idgen from 'libs/idgen'
5+
6+
class DatePicker extends React.Component {
7+
constructor(props) {
8+
super(props)
9+
10+
this.id = props.id || `datepicker${idgen()}`
11+
}
12+
13+
componentDidMount() {
14+
if (typeof window.M !== 'undefined') {
15+
const { onChange } = this.props
16+
const elem = document.getElementById(this.id)
17+
const options = onChange ? { onSelect: onChange, ...this.props.options } : this.props.options
18+
19+
this.instance = window.M.Datepicker.init(elem, options)
20+
}
21+
}
22+
23+
componentWillUnmount() {
24+
if (this.instance) {
25+
this.instance.destroy()
26+
}
27+
}
28+
29+
render() {
30+
const { ...other } = this.props
31+
32+
return <TextInput id={this.id} inputClassName="datepicker" {...other} />
33+
}
34+
}
35+
36+
DatePicker.propTypes = {
37+
/**
38+
* Event called when Time has been selected
39+
*/
40+
onChange: PropTypes.func,
41+
/**
42+
* id passed to datepicker, also used for init method
43+
*/
44+
id: PropTypes.string,
45+
/**
46+
* options passed to init method
47+
* more info: https://materializecss.com/pickers.html#date-picker
48+
*/
49+
options: PropTypes.shape({
50+
/**
51+
* Automatically close picker when date is selected.
52+
*/
53+
autoClose: PropTypes.bool,
54+
/**
55+
* The date output format for the input field value.
56+
* @default 'mmm dd, yyyy'
57+
*/
58+
format: PropTypes.string,
59+
/**
60+
* Used to create date object from current input string.
61+
* @default null
62+
*/
63+
parse: PropTypes.any,
64+
/**
65+
* The initial date to view when first opened.
66+
* @default null
67+
*/
68+
defaultDate: PropTypes.any,
69+
/**
70+
* Make the defaultDate the initial selected value.
71+
* @default false
72+
*/
73+
setDefaultDate: PropTypes.bool,
74+
/**
75+
* Prevent selection of any date on the weekend.
76+
* @default false
77+
*/
78+
disableWeekends: PropTypes.bool,
79+
/**
80+
* Custom function to disable certain days.
81+
* @default null
82+
*/
83+
disableDayFn: PropTypes.any,
84+
/**
85+
* First day of week (0: Sunday, 1: Monday etc).
86+
* @default 0
87+
*/
88+
firstDay: PropTypes.number,
89+
/**
90+
* The earliest date that can be selected.
91+
* @default null
92+
*/
93+
minDate: PropTypes.any,
94+
/**
95+
* The latest date that can be selected.
96+
* @default null
97+
*/
98+
maxDate: PropTypes.any,
99+
/**
100+
* Number of years either side, or array of upper/lower range.
101+
* @default 10
102+
*/
103+
yearRange: PropTypes.oneOf([PropTypes.number, PropTypes.array]),
104+
/**
105+
* Changes Datepicker to RTL.
106+
* @default false
107+
*/
108+
isRTL: PropTypes.bool,
109+
/**
110+
* Show month after year in Datepicker title.
111+
* @default false
112+
*/
113+
showMonthAfterYear: PropTypes.bool,
114+
/**
115+
* Render days of the calendar grid that fall in the next or previous month.
116+
* @default false
117+
*/
118+
showDaysInNextAndPreviousMonths: PropTypes.bool,
119+
/**
120+
* Specify a DOM element to render the calendar in, by default it will be placed before the input.
121+
* @default null
122+
*/
123+
container: PropTypes.any,
124+
/**
125+
* Show the clear button in the datepicker.
126+
* @default false
127+
*/
128+
showClearBtn: PropTypes.bool,
129+
/**
130+
* Internationalization options.
131+
* @default See i18n documentation.
132+
*/
133+
i18n: PropTypes.any,
134+
/**
135+
* An array of string returned by `Date.toDateString()`, indicating there are events in the specified days.
136+
* @default []
137+
*/
138+
events: PropTypes.array,
139+
/**
140+
* Callback function when date is selected, first parameter is the newly selected date.
141+
* @default null
142+
*/
143+
onSelect: PropTypes.any,
144+
/**
145+
* Callback function when Datepicker is opened.
146+
* @default null
147+
*/
148+
onOpen: PropTypes.any,
149+
/**
150+
* Callback function when Datepicker is closed.
151+
* @default null
152+
*/
153+
onClose: PropTypes.any,
154+
/**
155+
* Callback function when Datepicker HTML is refreshed.
156+
* @default null
157+
*/
158+
onDraw: PropTypes.any,
159+
}),
160+
}
161+
162+
export default DatePicker
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"main": "DatePicker.js"
3+
}

0 commit comments

Comments
 (0)