From 25385a16cf70c5549ae7f2dc8e4941e4cbaa9194 Mon Sep 17 00:00:00 2001 From: Maximiliano Forlenza Date: Wed, 19 Jun 2019 08:36:25 -0300 Subject: [PATCH 1/6] feat(dateUtils): create method to formatToISOString --- src/services/dateUtils.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/services/dateUtils.js b/src/services/dateUtils.js index 68a7aef..6766fa4 100644 --- a/src/services/dateUtils.js +++ b/src/services/dateUtils.js @@ -23,4 +23,8 @@ export default class DateUtilsService { static formatDateTime(input) { return `${DateUtilsService.formatDate(input)} ${DateUtilsService.formatTime(input)}`; } + + static formatToISOString(input = new Date()) { + return input.toISOString(); + } } From 217f1d5317f662554299c355dcc81e2c2f0aab50 Mon Sep 17 00:00:00 2001 From: Maximiliano Forlenza Date: Wed, 19 Jun 2019 08:38:40 -0300 Subject: [PATCH 2/6] refactor(components): format date from dateUtilsService --- src/components/DateField.js | 6 ++++-- src/components/PasswordField.js | 12 ++++++------ src/components/TextField.js | 10 ++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/components/DateField.js b/src/components/DateField.js index d8b76d1..a438aa2 100644 --- a/src/components/DateField.js +++ b/src/components/DateField.js @@ -3,8 +3,10 @@ import PropTypes from 'prop-types'; import {Label, FormGroup} from 'reactstrap'; import DatePicker from 'react-datepicker'; +import {DateUtilsService} from '../services'; + const handleChange = (date, onChange, currentValue, control) => { - const value = date.toISOString(); + const value = DateUtilsService.formatToISOString(date); if (currentValue === value) { return; } @@ -38,10 +40,10 @@ const DateField = ({ ); DateField.propTypes = { + onChange: PropTypes.func.isRequired, control: PropTypes.string.isRequired, label: PropTypes.string.isRequired, value: PropTypes.string, - onChange: PropTypes.func.isRequired, dateFormat: PropTypes.string, maxDate: PropTypes.oneOfType([PropTypes.string, PropTypes.shape({})]), minDate: PropTypes.oneOfType([PropTypes.string, PropTypes.shape({})]), diff --git a/src/components/PasswordField.js b/src/components/PasswordField.js index 11c5bae..f0a0d59 100644 --- a/src/components/PasswordField.js +++ b/src/components/PasswordField.js @@ -4,7 +4,7 @@ import { Label, Input, FormGroup, FormFeedback } from 'reactstrap'; -import {ValidatorService} from '../services'; +import {DateUtilsService, ValidatorService} from '../services'; class PasswordField extends PureComponent { static propTypes = { @@ -47,18 +47,18 @@ class PasswordField extends PureComponent { this.state = {valid: undefined}; } - validateInput = (value, callback) => { + validateInput(value, onChange) { if (this.props.validateInput) { - callback(); + onChange(); return this.props.validateInput; } const {maxLength, minLength} = this.props; const valid = ValidatorService.validatePassword(value, maxLength, minLength); - return this.setState(() => ({valid}), callback); - }; + return this.setState(() => ({valid}), onChange()); + } handleChange(date) { - const value = date.toISOString(); + const value = DateUtilsService.formatToISOString(date); if (this.props.value === value) { return; } diff --git a/src/components/TextField.js b/src/components/TextField.js index 2d93db8..225eab2 100644 --- a/src/components/TextField.js +++ b/src/components/TextField.js @@ -4,7 +4,7 @@ import { Label, Input, FormGroup, FormFeedback } from 'reactstrap'; -import ValidatorService from '../services/validator'; +import {DateUtilsService, ValidatorService} from '../services'; class TextField extends PureComponent { static propTypes = { @@ -47,23 +47,21 @@ class TextField extends PureComponent { this.state = {valid: undefined}; } - validateInput = (value, callback) => { + validateInput(value, callback) { if (this.props.validateInput) { callback(); return this.props.validateInput; } - const {maxLength, minLength} = this.props; const valid = ValidatorService.validateText(value, maxLength, minLength); return this.setState(() => ({valid}), callback); - }; + } handleChange(date) { - const value = date.toISOString(); + const value = DateUtilsService.formatToISOString(date); if (this.props.value === value) { return; } - this.validateInput(value, this.props.onChange({target: {value, id: this.props.control}})); } From a398e1ef1ce50cf6f9c71736adc7d545219854db Mon Sep 17 00:00:00 2001 From: Maximiliano Forlenza Date: Wed, 19 Jun 2019 08:39:40 -0300 Subject: [PATCH 3/6] refactor(dropdown): remove menuPortalTarget --- src/components/Dropdown.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/Dropdown.js b/src/components/Dropdown.js index fbe2ca3..f4089a6 100644 --- a/src/components/Dropdown.js +++ b/src/components/Dropdown.js @@ -1,4 +1,3 @@ -/* global document */ import React from 'react'; import PropTypes from 'prop-types'; import {Label, FormGroup} from 'reactstrap'; @@ -6,7 +5,17 @@ import Select from 'react-select'; import {find, isNil} from 'lodash'; const Dropdown = ({ - value, control, label, getOptionValue, getOptionLabel, disabled, placeholder, options, onChange, isClearable + value, + control, + label, + getOptionValue, + getOptionLabel, + disabled, + placeholder, + options, + onChange, + isClearable, + ...props }) => ( {label && ( @@ -25,7 +34,7 @@ const Dropdown = ({ {...{ options, getOptionValue, getOptionLabel, isClearable, placeholder }} - menuPortalTarget={document.querySelector('body')} + {...props} /> ); From 58e356f74345e5bf52f671473597fd2b28b75c83 Mon Sep 17 00:00:00 2001 From: Maximiliano Forlenza Date: Wed, 19 Jun 2019 08:41:13 -0300 Subject: [PATCH 4/6] refactor(saveButton): change prop bsStyle to color --- src/components/SaveButton.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/SaveButton.js b/src/components/SaveButton.js index dbe8f8d..3d70c30 100644 --- a/src/components/SaveButton.js +++ b/src/components/SaveButton.js @@ -12,7 +12,7 @@ const SaveButton = ({disabled, onClick, saving}) => (