@@ -142,6 +142,15 @@ export class FormBodyApplicationComponent implements OnInit, OnDestroy {
142142 }
143143
144144 onSubmit ( ) : void {
145+ if ( this . serializedStartDate . invalid ) {
146+ // Depending on what date component is used, it might use its own highlighting
147+ this . handleError ( this . buildErrorMessage ( 'MESSAGE.INVALID-DATE' ) , 'application.startDate' ) ;
148+ return ;
149+ } else if ( this . serializedEndDate . invalid ) {
150+ this . handleError ( this . buildErrorMessage ( 'MESSAGE.INVALID-DATE' ) , 'application.endDate' ) ;
151+ return ;
152+ }
153+
145154 this . application . organizationId = this . sharedVariableService . getSelectedOrganisationId ( ) ;
146155 this . application . startDate = this . serializedStartDate . value ?. toISOString ( ) ;
147156 this . application . endDate = this . serializedEndDate . value ?. toISOString ( ) ;
@@ -154,6 +163,14 @@ export class FormBodyApplicationComponent implements OnInit, OnDestroy {
154163 }
155164 }
156165
166+ private buildErrorMessage ( message : string ) : Pick < HttpErrorResponse , 'error' > {
167+ return {
168+ error : {
169+ message,
170+ } ,
171+ } ;
172+ }
173+
157174 updateApplication ( id : number ) : void {
158175 this . applicationService
159176 . updateApplication ( this . application , id )
@@ -181,21 +198,21 @@ export class FormBodyApplicationComponent implements OnInit, OnDestroy {
181198 ) ;
182199 }
183200
184- private handleError ( error : HttpErrorResponse ) {
201+ private handleError ( error : Pick < HttpErrorResponse , 'error' > , errorField ?: string ) {
185202 this . errorFields = [ ] ;
186203 this . errorMessages = [ ] ;
187204
188205 // Temp fix till we standardise backend error handling
189206 if ( error . error ?. message [ 0 ] ?. property ) {
190207 this . externalError ( error ) ;
191208 } else {
192- this . backendError ( error ) ;
209+ this . backendError ( error , errorField ) ;
193210 }
194211
195212 this . formFailedSubmit = true ;
196213 }
197214
198- externalError ( error : HttpErrorResponse ) {
215+ externalError ( error : Pick < HttpErrorResponse , 'error' > ) {
199216 error . error . message . forEach ( ( err ) => {
200217 this . errorFields . push ( err . property ) ;
201218 this . errorMessages = this . errorMessages . concat (
@@ -205,12 +222,12 @@ export class FormBodyApplicationComponent implements OnInit, OnDestroy {
205222 this . formFailedSubmit = true ;
206223 }
207224
208- backendError ( error : HttpErrorResponse ) {
225+ backendError ( error : Pick < HttpErrorResponse , 'error' > , errorField = 'name' ) {
209226 this . translate . get ( [ error . error . message ] )
210227 . subscribe ( translations => {
211228 this . errorMessages . push ( translations [ error . error . message ] ) ;
212229 } ) ;
213- this . errorFields . push ( 'name' ) ;
230+ this . errorFields . push ( errorField ) ;
214231 }
215232
216233 routeBack ( ) : void {
0 commit comments