Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit c036ddf

Browse files
committed
fixed review items
1 parent bf72bec commit c036ddf

File tree

7 files changed

+23
-20
lines changed

7 files changed

+23
-20
lines changed

src/components/DateInput/index.jsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
import React from "react";
77
import PT from "prop-types";
88
import DatePicker from "react-datepicker";
9+
import cn from "classnames";
910
import "./styles.module.scss";
1011

1112
const DateInput = (props) => {
1213
return (
13-
<div styleName={`datepicker-wrapper ${props.className}`}>
14+
<div styleName={cn("datepicker-wrapper", props.className)}>
1415
<DatePicker
1516
dateFormat="MM/dd/yyyy"
1617
placeholderText={props.placeholder}
@@ -30,6 +31,7 @@ DateInput.propTypes = {
3031
placeholder: PT.string,
3132
onBlur: PT.func,
3233
onFocus: PT.func,
34+
className: PT.string
3335
};
3436

3537
export default DateInput;

src/components/FormField/index.jsx

+6-11
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,11 @@ import ReactSelect from "../../components/ReactSelect";
1313
import DateInput from "../../components/DateInput";
1414
import "./styles.module.scss";
1515

16-
const updateInput = (field, input) => {
17-
field.input = input;
18-
}
19-
2016
const FormField = ({ field, isGroupField }) => {
2117
return (
2218
<Field name={field.name}>
2319
{({ input, meta }) => (
2420
<div styleName={isGroupField ? "field-group-field" : ""}>
25-
{updateInput(field, input)}
2621
{ !field.readonly && (
2722
<label
2823
styleName={
@@ -40,7 +35,7 @@ const FormField = ({ field, isGroupField }) => {
4035
placeholder={field.placeholder}
4136
value={input.value ?? ""}
4237
type="text"
43-
className={meta.error && meta.touched ? "error" : ""}
38+
className={meta.error && (meta.touched || field.showError) ? "error" : ""}
4439
readonly={field.readonly}
4540
onChange={input.onChange}
4641
onBlur={input.onBlur}
@@ -56,7 +51,7 @@ const FormField = ({ field, isGroupField }) => {
5651
onChange={input.onChange}
5752
onBlur={input.onBlur}
5853
onFocus={input.onFocus}
59-
className={meta.error && meta.touched ? "error" : ""}
54+
className={meta.error && (meta.touched || field.showError) ? "error" : ""}
6055
/>
6156
)}
6257
{field.type === FORM_FIELD_TYPE.TEXTAREA && (
@@ -66,7 +61,7 @@ const FormField = ({ field, isGroupField }) => {
6661
onChange={input.onChange}
6762
onBlur={input.onBlur}
6863
onFocus={input.onFocus}
69-
className={meta.error && meta.touched ? "error" : ""}
64+
className={meta.error && (meta.touched || field.showError) ? "error" : ""}
7065
/>
7166
)}
7267
{field.type === FORM_FIELD_TYPE.DATE && (
@@ -76,7 +71,7 @@ const FormField = ({ field, isGroupField }) => {
7671
onChange={input.onChange}
7772
onBlur={input.onBlur}
7873
onFocus={input.onFocus}
79-
className={meta.error && meta.touched ? "error" : ""}
74+
className={meta.error && (meta.touched || field.showError) ? "error" : ""}
8075
/>
8176
)}
8277
{field.type === FORM_FIELD_TYPE.SELECT && (
@@ -89,7 +84,7 @@ const FormField = ({ field, isGroupField }) => {
8984
onFocus={input.onFocus}
9085
/>
9186
)}
92-
{(field.isRequired || field.customValidator) && meta.error && meta.touched && (
87+
{(field.isRequired || field.customValidator) && meta.error && (meta.touched || field.showError) && (
9388
<div styleName="field-error">{meta.error}</div>
9489
)}
9590
</div>
@@ -117,7 +112,7 @@ FormField.prototype = {
117112
maxLength: PT.number,
118113
styleName: PT.string,
119114
readonly: PT.string,
120-
input: PT.object
115+
showError: PT.bool
121116
})
122117
).isRequired,
123118
isGroupField: PT.bool,

src/components/FormField/styles.module.scss

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ input:read-only {
4545
font-family: "Roboto", Helvetica, Arial, sans-serif;
4646
font-weight: 400;
4747
width: 100%;
48-
height: 40px;
49-
line-height: 40px;
50-
padding: 0 10px;
48+
min-height: 40px;
49+
line-height: 20px;
50+
padding: 9px 10px;
5151
margin: 10px 0 5px;
5252
font-size: 15px;
5353
color: #ff5b52;

src/components/TCForm/index.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ TCForm.propTypes = {
120120
maxLength: PT.number,
121121
styleName: PT.string,
122122
readonly: PT.string,
123+
showError: PT.bool
123124
})
124125
).isRequired,
125126
onSubmit: PT.func,

src/components/TCForm/utils.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export const createConfigurationObject = (fields) => {
6868
* @returns {Function} configuration object
6969
*/
7070
export const getValidator = (fields) => {
71-
return (values, inputs) => {
71+
return (values) => {
7272
const errors = {};
7373
fields
7474
.filter((f) => f.isRequired || f.customValidator)
@@ -79,7 +79,6 @@ export const getValidator = (fields) => {
7979
const error = f.customValidator(f, fields, values);
8080
if(error){
8181
errors[f.name] = error;
82-
f.input.onBlur();
8382
}
8483
}
8584
});

src/components/TextInput/index.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
*/
66
import React from "react";
77
import PT from "prop-types";
8+
import cn from "classnames";
89
import "./styles.module.scss";
910

1011
function TextInput(props) {
1112
return (
1213
<input
13-
styleName={`TextInput ${props.className} ${props.readonly ? "readonly" : ""}`}
14+
styleName={cn("TextInput", props.className, {"readonly": props.readonly})}
1415
maxLength={props.maxLength}
1516
min={props.minValue}
1617
onChange={(event) => {

src/routes/ResourceBookingForm/utils.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* utility class
55
*/
66
import moment from 'moment';
7+
import _ from 'lodash';
78
import {
89
STATUS_OPTIONS,
910
FORM_ROW_TYPE,
@@ -47,11 +48,14 @@ export const getEditResourceBookingConfig = (onSubmit) => {
4748
name: "startDate",
4849
placeholder: "Start Date",
4950
customValidator: (field, fields, values) => {
51+
const endDateField = _.find(fields, {'name': 'endDate'});
5052
const startDate = values[field.name];
5153
const endDate = values['endDate'];
5254
if(startDate && endDate && moment(endDate).startOf('day').isBefore(moment(startDate).startOf('day'))){
55+
endDateField.showError = true;
5356
return 'Start Date should not be after End Date';
5457
}
58+
endDateField.showError = false;
5559
return null;
5660
}
5761
},
@@ -61,13 +65,14 @@ export const getEditResourceBookingConfig = (onSubmit) => {
6165
name: "endDate",
6266
placeholder: "End Date",
6367
customValidator: (field, fields, values) => {
68+
const startDateField = _.find(fields, {'name': 'startDate'});
6469
const endDate = values[field.name];
6570
const startDate = values['startDate'];
6671
if(startDate && endDate && moment(endDate).startOf('day').isBefore(moment(startDate).startOf('day'))){
67-
return 'End Date should not be before Start Date';
68-
}else if(!startDate && endDate){
72+
startDateField.showError = true;
6973
return 'End Date should not be before Start Date';
7074
}
75+
startDateField.showError = false;
7176
return null;
7277
}
7378
},

0 commit comments

Comments
 (0)