Skip to content

Commit 68a1e28

Browse files
authored
Merge pull request #1321 from nursoltan-s/issue-1320
add single control to start date
2 parents 4fd840f + 5a8d255 commit 68a1e28

File tree

4 files changed

+186
-13
lines changed

4 files changed

+186
-13
lines changed

package-lock.json

Lines changed: 137 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"@fortawesome/fontawesome-svg-core": "^1.2.14",
88
"@fortawesome/free-solid-svg-icons": "^5.7.1",
99
"@fortawesome/react-fontawesome": "^0.1.4",
10+
"@nateradebaugh/react-datetime": "^4.4.11",
1011
"@popperjs/core": "^2.5.4",
1112
"@svgr/webpack": "2.4.1",
1213
"axios": "^0.19.0",
@@ -53,6 +54,7 @@
5354
"mini-css-extract-plugin": "0.4.3",
5455
"moment": "^2.24.0",
5556
"moment-duration-format": "^2.2.2",
57+
"moment-timezone": "^0.5.34",
5658
"node-sass": "^4.14.0",
5759
"optimize-css-assets-webpack-plugin": "5.0.1",
5860
"pnp-webpack-plugin": "1.1.0",

src/components/PhaseInput/PhaseInput.module.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
@import "../../styles/includes";
2-
@i
2+
3+
:global {
4+
div[data-reach-popover] {
5+
z-index: 10;
6+
}
7+
}
38

49
.container {
510
display: flex;

src/components/PhaseInput/index.js

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
11
import _ from 'lodash'
2-
import moment from 'moment'
2+
import moment from 'moment-timezone'
33
import React, { Component } from 'react'
44
import PropTypes from 'prop-types'
55
import styles from './PhaseInput.module.scss'
66
import cn from 'classnames'
7-
import DayPickerInput from 'react-day-picker/DayPickerInput'
8-
import TimePicker from 'rc-time-picker'
9-
import {
10-
formatDate,
11-
parseDate
12-
} from 'react-day-picker/moment'
137
import 'react-day-picker/lib/style.css'
148
import 'rc-time-picker/assets/index.css'
159
import Select from '../Select'
10+
import DateTime from '@nateradebaugh/react-datetime'
11+
import isAfter from 'date-fns/isAfter'
12+
import subDays from 'date-fns/subDays'
13+
import '@nateradebaugh/react-datetime/scss/styles.scss'
1614

17-
const timeFormat = 'HH:mm'
18-
const dateFormat = 'MM/DD/YYYY'
15+
const dateFormat = 'MM/DD/YYYY HH:mm'
16+
// const tcTimeZone = 'America/New_York'
1917

2018
class PhaseInput extends Component {
19+
constructor (props) {
20+
super(props)
21+
22+
this.onDateChange = this.onDateChange.bind(this)
23+
}
24+
25+
onDateChange (e) {
26+
const { onUpdatePhase } = this.props
27+
28+
onUpdatePhase(moment(e, dateFormat))
29+
}
30+
2131
render () {
2232
const { phase, onUpdateSelect, onUpdatePhase, withDates, withDuration, endDate, readOnly } = this.props
2333
if (_.isEmpty(phase)) return null
34+
2435
const date = moment(phase.date).format(dateFormat)
25-
const time = moment(phase.date)
2636

2737
return (
2838
<div className={styles.container}>
@@ -33,13 +43,32 @@ class PhaseInput extends Component {
3343
withDuration && endDate && (
3444
<div className={styles.previewDates}>
3545
<span>Ends:</span>
36-
{moment(endDate).format(`${dateFormat} ${timeFormat}`)}
46+
{moment(endDate).local().format(`${dateFormat}`)}
3747
</div>
3848
)
3949
}
4050
</div>
4151
<div className={cn(styles.field, styles.col2)}>
4252
{
53+
withDates && (
54+
<div className={styles.dayPicker}>
55+
{
56+
readOnly ? (
57+
<span className={styles.readOnlyValue}>{date}</span>
58+
)
59+
: (
60+
<DateTime
61+
value={date}
62+
onChange={this.onDateChange}
63+
isValidDate={(current) => {
64+
const yesterday = subDays(new Date(), 1)
65+
return isAfter(current, yesterday)
66+
}}
67+
/>)}
68+
</div>
69+
)
70+
}
71+
{/* {
4372
withDates && (
4473
<div className={styles.dayPicker}>
4574
{readOnly ? (
@@ -62,7 +91,7 @@ class PhaseInput extends Component {
6291
/>)}
6392
</div>
6493
)
65-
}
94+
} */}
6695
{
6796
withDuration && (
6897
<div className={styles.durationPicker}>

0 commit comments

Comments
 (0)