-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #224 from hql287/better-dueDate
Better dueDate (Take 2)
- Loading branch information
Showing
22 changed files
with
708 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Libraries | ||
import React, { PureComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import moment from 'moment'; | ||
|
||
// React Dates | ||
import { SingleDatePicker } from 'react-dates'; | ||
|
||
// Styles | ||
import _withFadeInAnimation from '../shared/hoc/_withFadeInAnimation'; | ||
import styled from 'styled-components'; | ||
const Container = styled.div` | ||
display: flex; | ||
margin-bottom: 20px; | ||
`; | ||
|
||
// Component | ||
export class DueDatePicker extends PureComponent { | ||
constructor(props) { | ||
super(props); | ||
this.state = { focused: false }; | ||
this.onFocusChange = this.onFocusChange.bind(this); | ||
this.onDateChange = this.onDateChange.bind(this); | ||
this.clearDate = this.clearDate.bind(this); | ||
} | ||
|
||
onFocusChange() { | ||
this.setState({ focused: !this.state.focused }); | ||
} | ||
|
||
onDateChange(date) { | ||
const selectedDate = date === null ? null : moment(date).toObject(); | ||
this.props.updateCustomDate(selectedDate); | ||
} | ||
|
||
clearDate() { | ||
this.onDateChange(null); | ||
} | ||
|
||
render() { | ||
const { t, selectedDate } = this.props; | ||
const dueDate = selectedDate === null ? null : moment(selectedDate); | ||
return ( | ||
<Container> | ||
<SingleDatePicker | ||
id="invoice-duedate" | ||
placeholder={t('form:fields:dueDate:placeHolder')} | ||
firstDayOfWeek={1} | ||
withFullScreenPortal | ||
displayFormat="DD/MM/YYYY" | ||
hideKeyboardShortcutsPanel | ||
date={dueDate} | ||
focused={this.state.focused} | ||
onFocusChange={this.onFocusChange} | ||
onDateChange={newDate => this.onDateChange(newDate)} | ||
/> | ||
{selectedDate !== null && ( | ||
<a className="clearDateBtn active" href="#" onClick={this.clearDate}> | ||
<i className="ion-close-circled" /> | ||
</a> | ||
)} | ||
</Container> | ||
); | ||
} | ||
} | ||
|
||
DueDatePicker.propTypes = { | ||
selectedDate: PropTypes.object, | ||
t: PropTypes.func.isRequired, | ||
updateCustomDate: PropTypes.func.isRequired, | ||
}; | ||
|
||
DueDatePicker.defaultProps = { | ||
selectedDate: null, | ||
}; | ||
|
||
// Export | ||
export default _withFadeInAnimation(DueDatePicker); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Libraries | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
// Styles | ||
import _withFadeInAnimation from '../shared/hoc/_withFadeInAnimation'; | ||
import styled from 'styled-components'; | ||
const Container = styled.div` | ||
display: flex; | ||
margin-bottom: 20px; | ||
`; | ||
|
||
// Payment Terms | ||
import { paymentTerms } from '../../../libs/paymentTerms'; | ||
|
||
// Component | ||
export class DueDateTerms extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.handleInputChange = this.handleInputChange.bind(this); | ||
} | ||
|
||
componentWillMount() { | ||
if (this.props.paymentTerm === null) { | ||
this.updateSelectedTerm(paymentTerms[0]); | ||
} | ||
} | ||
|
||
handleInputChange(event) { | ||
this.updateSelectedTerm(event.target.value); | ||
} | ||
|
||
updateSelectedTerm(term) { | ||
const { updatePaymentTerm } = this.props; | ||
updatePaymentTerm(term); | ||
} | ||
|
||
render() { | ||
const { t, paymentTerm } = this.props; | ||
const termOptions = paymentTerms.map(term => ( | ||
<option key={term} value={term}> | ||
{ t(`form:fields:dueDate:paymentTerms:${term}:label`) } | ||
{' - '} | ||
{ t(`form:fields:dueDate:paymentTerms:${term}:description`) } | ||
</option> | ||
)); | ||
return ( | ||
<Container> | ||
<select | ||
onChange={this.handleInputChange} | ||
value={paymentTerm === null ? paymentTerms[0] : paymentTerm} | ||
> | ||
{ termOptions } | ||
</select> | ||
</Container> | ||
); | ||
} | ||
} | ||
|
||
DueDateTerms.propTypes = { | ||
paymentTerm: PropTypes.string, | ||
t: PropTypes.func.isRequired, | ||
updatePaymentTerm: PropTypes.func.isRequired, | ||
}; | ||
|
||
// Export | ||
export default _withFadeInAnimation(DueDateTerms); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.