This repository has been archived by the owner on Jul 2, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 14
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 #30 from AndresMorelos/update-created-at-date
Giving the ability to update create at date.
- Loading branch information
Showing
7 changed files
with
260 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Libraries | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
// Custom Components | ||
import { Section } from '../shared/Section'; | ||
import CreatedAtPicker from './CreatedAtPicker'; | ||
|
||
// Animation | ||
import _withFadeInAnimation from '../shared/hoc/_withFadeInAnimation'; | ||
|
||
// Component | ||
export class CreatedAt extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { created_at: this.props.created_at }; | ||
this.updateCustomDate = this.updateCustomDate.bind(this); | ||
this.updatePaymentTerm = this.updatePaymentTerm.bind(this); | ||
this.updateCreateAt = this.updateCreateAt.bind(this); | ||
} | ||
|
||
// Handle Clear Form | ||
UNSAFE_componentWillReceiveProps(nextProps) { | ||
const { created_at } = nextProps.created_at; | ||
if (created_at === null) { | ||
this.setState(nextProps.created_at); | ||
} | ||
} | ||
|
||
updateCustomDate(created_at) { | ||
this.setState({ created_at }, () => { | ||
this.updateCreateAt(this.state); | ||
}); | ||
} | ||
|
||
updatePaymentTerm(paymentTerm) { | ||
this.setState({ paymentTerm }, () => { | ||
this.updateCreateAt(this.state); | ||
}); | ||
} | ||
|
||
updateCreateAt(data) { | ||
this.props.updateFieldData('created_at', data); | ||
} | ||
|
||
render() { | ||
const { t } = this.props; | ||
const { created_at } = this.state; | ||
return ( | ||
<Section> | ||
<label className="itemLabel"> | ||
{t('form:fields:createAtDate:name')} | ||
</label> | ||
<CreatedAtPicker | ||
t={t} | ||
created_at={created_at} | ||
updateCustomDate={this.updateCustomDate} | ||
/> | ||
</Section> | ||
); | ||
} | ||
} | ||
|
||
CreatedAt.propTypes = { | ||
created_at: PropTypes.number, | ||
t: PropTypes.func.isRequired, | ||
updateFieldData: PropTypes.func.isRequired, | ||
}; | ||
|
||
// Export | ||
export default _withFadeInAnimation(CreatedAt); |
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,81 @@ | ||
// Libraries | ||
import React, { PureComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import moment from 'moment'; | ||
|
||
// React Dates | ||
import 'react-dates/initialize' | ||
import 'react-dates/lib/css/_datepicker.css' | ||
import { SingleDatePicker } from 'react-dates'; | ||
|
||
// Styles | ||
import styled from 'styled-components'; | ||
import _withFadeInAnimation from '../shared/hoc/_withFadeInAnimation'; | ||
const Container = styled.div` | ||
display: flex; | ||
margin-bottom: 20px; | ||
`; | ||
|
||
// Component | ||
export class CreatedAtPicker 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 created_at = date === null ? null : new Date(date).getTime(); | ||
this.props.updateCustomDate(created_at); | ||
} | ||
|
||
clearDate() { | ||
this.onDateChange(null); | ||
} | ||
|
||
render() { | ||
const { t, created_at } = this.props; | ||
const createdAt = created_at === null ? null : moment(created_at); | ||
return ( | ||
<Container> | ||
<SingleDatePicker | ||
id="invoice-createdAt" | ||
placeholder={t('form:fields:createAtDate:placeHolder')} | ||
firstDayOfWeek={1} | ||
withFullScreenPortal | ||
displayFormat="DD/MM/YYYY" | ||
hideKeyboardShortcutsPanel | ||
date={createdAt} | ||
isOutsideRange={() => false} | ||
focused={this.state.focused} | ||
onFocusChange={this.onFocusChange} | ||
onDateChange={newDate => this.onDateChange(newDate)} | ||
/> | ||
{created_at !== null && ( | ||
<a className="clearDateBtn active" href="#" onClick={this.clearDate}> | ||
<i className="ion-close-circled" /> | ||
</a> | ||
)} | ||
</Container> | ||
); | ||
} | ||
} | ||
|
||
CreatedAtPicker.propTypes = { | ||
created_at: PropTypes.number, | ||
t: PropTypes.func.isRequired, | ||
updateCustomDate: PropTypes.func.isRequired, | ||
}; | ||
|
||
CreatedAtPicker.defaultProps = { | ||
created_at: null, | ||
}; | ||
|
||
// Export | ||
export default _withFadeInAnimation(CreatedAtPicker); |
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
Oops, something went wrong.