@@ -68,22 +68,25 @@ function AddLogModal({ isOpen, onClose, onAdd }) {
6868 const validateForm = ( ) => {
6969 const newErrors = { } ;
7070 const timeRegex = / ^ ( [ 0 - 1 ] \d | 2 [ 0 - 3 ] ) : ( [ 0 - 5 ] \d ) : ( [ 0 - 5 ] \d ) $ / ;
71+ const textRegex = / ^ [ a - z A - Z \s ] + $ / ;
7172
7273 if ( ! formData . user . trim ( ) ) newErrors . user = 'User is required' ;
7374
74- if ( ! timeRegex . test ( formData . timeDuration ) ) {
75+ if ( ! formData . timeDuration . trim ( ) ) {
76+ newErrors . timeDuration = 'Time/Duration is required' ;
77+ } else if ( ! timeRegex . test ( formData . timeDuration ) ) {
7578 newErrors . timeDuration = 'Time must be in HH:MM:SS format' ;
7679 }
7780
7881 if ( ! formData . facilities . trim ( ) ) {
7982 newErrors . facilities = 'Facilities is required' ;
80- } else if ( ! / ^ [ a - z A - Z \s ] + $ / . test ( formData . facilities ) ) {
83+ } else if ( ! textRegex . test ( formData . facilities ) ) {
8184 newErrors . facilities = 'Facilities should contain only letters' ;
8285 }
8386
8487 if ( ! formData . materials . trim ( ) ) {
8588 newErrors . materials = 'Materials is required' ;
86- } else if ( ! / ^ [ a - z A - Z \s ] + $ / . test ( formData . materials ) ) {
89+ } else if ( ! textRegex . test ( formData . materials ) ) {
8790 newErrors . materials = 'Materials should contain only letters' ;
8891 }
8992
@@ -95,13 +98,6 @@ function AddLogModal({ isOpen, onClose, onAdd }) {
9598 const handleSubmit = e => {
9699 e . preventDefault ( ) ;
97100
98- const error = validateForm ( ) ;
99-
100- if ( error ) {
101- setValidationError ( error ) ;
102- return ;
103- }
104-
105101 const validationErrors = validateForm ( ) ;
106102
107103 if ( Object . keys ( validationErrors ) . length > 0 ) {
@@ -119,6 +115,7 @@ function AddLogModal({ isOpen, onClose, onAdd }) {
119115 date : '' ,
120116 } ) ;
121117
118+ setErrors ( { } ) ;
122119 onClose ( ) ;
123120 } ;
124121
@@ -149,9 +146,9 @@ function AddLogModal({ isOpen, onClose, onAdd }) {
149146 ) ) }
150147
151148 < div className = { styles . formGroup } >
152- < label htmlFor = "date" > Date</ label >
149+ < label htmlFor = "resource- date" > Date</ label >
153150 < input
154- id = "date"
151+ id = "resource- date"
155152 name = "date"
156153 type = "date"
157154 value = { formData . date }
@@ -161,17 +158,6 @@ function AddLogModal({ isOpen, onClose, onAdd }) {
161158 { errors . date && < span className = { styles . errorText } > { errors . date } </ span > }
162159 </ div >
163160
164- < div className = { styles . formGroup } >
165- < label htmlFor = "date" > Date</ label >
166- < input
167- id = "date"
168- name = "date"
169- type = "date"
170- value = { formData . date }
171- onChange = { handleChange }
172- />
173- </ div >
174-
175161 < div className = { styles . modalActions } >
176162 < button type = "submit" className = { styles . submitButton } >
177163 Save Log
0 commit comments