11// @flow
22import * as React from 'react' ;
33import { FormattedMessage } from 'react-intl' ;
4+ import isNaN from 'lodash/isNaN' ;
45
56import DatePicker from '../../../../components/date-picker' ;
67import SingleSelectField from '../../../../components/select-field/SingleSelectField' ;
@@ -13,6 +14,7 @@ import type { ConditionValueType } from '../../flowTypes';
1314import '../../styles/Condition.scss' ;
1415
1516type Props = {
17+ error ?: React . Node ,
1618 onChange : ( value : Array < ConditionValueType > ) => void ,
1719 selectedValues : Array < ConditionValueType > ,
1820 valueOptions : Array < Object > ,
@@ -25,8 +27,9 @@ const getDateValue = selectedValues => {
2527 }
2628
2729 const value = selectedValues [ 0 ] ;
28- if ( value instanceof Date ) {
29- return value ;
30+ const date = new Date ( value ) ;
31+ if ( ! isNaN ( date . valueOf ( ) ) ) {
32+ return date ;
3033 }
3134
3235 throw new Error ( 'Expected Date' ) ;
@@ -45,7 +48,7 @@ const getStringValue = selectedValues => {
4548 throw new Error ( 'Expected string' ) ;
4649} ;
4750
48- const ValueField = ( { onChange, selectedValues, valueOptions, valueType } : Props ) => {
51+ const ValueField = ( { error , onChange, selectedValues, valueOptions, valueType } : Props ) => {
4952 const value = selectedValues . length > 0 ? selectedValues [ 0 ] : '' ;
5053 const onInputChange = e => {
5154 return e . target . value !== '' ? onChange ( [ e . target . value ] ) : onChange ( [ ] ) ;
@@ -58,6 +61,8 @@ const ValueField = ({ onChange, selectedValues, valueOptions, valueType }: Props
5861 return (
5962 < div className = "filter-dropdown-text-field-container" >
6063 < TextInput
64+ error = { error }
65+ errorPosition = "middle-left"
6166 hideLabel
6267 label = "Text Input"
6368 name = "text"
0 commit comments