github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/build-blockchain-insurance-app-master/web/src/shared/DateInput.js (about) 1 /*global IBMCore*/ 2 'use strict'; 3 4 import React, { Props } from 'react'; 5 import PropTypes from 'prop-types'; 6 import { injectIntl, intlShape } from 'react-intl'; 7 import moment from 'moment'; 8 import 'moment/locale/de'; 9 10 class DateInput extends React.Component { 11 12 static get propTypes() { 13 return { 14 onChange: PropTypes.func, 15 value: PropTypes.number, 16 intl: intlShape.isRequired 17 }; 18 } 19 20 constructor(props) { 21 super(props); 22 23 this.onChange = this.onChange.bind(this); 24 } 25 26 componentDidMount() { 27 IBMCore.common.widget.datepicker.init(this.refs.dateInputElement, {}); 28 let self = this; 29 setTimeout(() => { 30 self.picker = jQuery(this.refs.dateInputElement).pickadate('picker'); 31 self.picker.on('set', self.onChange); 32 }, 500); 33 } 34 35 componentWillUnmount() { 36 this.picker.off('set', this.onChange); 37 } 38 39 onChange(value) { 40 if (typeof this.props.onChange === 'function') { 41 this.props.onChange(value.select); 42 } 43 } 44 45 render() { 46 let formattedDate; 47 if (this.props.value && this.props.value > 0) { 48 formattedDate = moment(new Date(this.props.value)).format('L', this.props.intl.locale); 49 } 50 return ( 51 <input type='text' readOnly ref='dateInputElement' value={formattedDate} /> 52 ); 53 } 54 } 55 56 export default injectIntl(DateInput);