1
1
import { useMutation } from '@apollo/client' ;
2
+ import { Box , Typography } from '@mui/material' ;
2
3
import { many , Many } from '@seedcompany/common' ;
4
+ import { FORM_ERROR } from 'final-form' ;
3
5
import { pick } from 'lodash' ;
4
6
import { ComponentType , useMemo } from 'react' ;
5
7
import { Except , Merge } from 'type-fest' ;
6
8
import { invalidateProps } from '~/api' ;
7
9
import { SensitivityList , UpdateProject } from '~/api/schema.graphql' ;
8
10
import {
11
+ CalendarDate ,
9
12
DisplayFieldRegionFragment ,
10
13
DisplayLocationFragment ,
11
14
ExtractStrict ,
@@ -24,6 +27,8 @@ import {
24
27
} from '../../../components/form' ;
25
28
import { LocationField } from '../../../components/form/Lookup' ;
26
29
import { FieldRegionField } from '../../../components/form/Lookup/FieldRegion' ;
30
+ import { FormattedDate } from '../../../components/Formatters' ;
31
+ import { Link } from '../../../components/Routing' ;
27
32
import {
28
33
updateEngagementDateRanges ,
29
34
updatePartnershipsDateRanges ,
@@ -219,6 +224,40 @@ export const UpdateProjectDialog = ({
219
224
} ,
220
225
} ) ;
221
226
} }
227
+ errorHandlers = { {
228
+ EngagementDateOverrideConflict : ( { engagements } ) => {
229
+ const rendered = (
230
+ < >
231
+ < Typography variant = "body2" gutterBottom >
232
+ { engagements . length === 1
233
+ ? 'An engagement has a date outside the new range'
234
+ : 'Some engagements have dates outside the new range' }
235
+ </ Typography >
236
+ < Box component = "ul" sx = { { m : 0 , paddingInlineStart : 4 } } >
237
+ { engagements . map ( ( eng ) => (
238
+ < li key = { eng . id + eng . point } >
239
+ { eng . point === 'start' ? 'Start' : 'End' } date of{ ' ' }
240
+ < Link to = { `/engagements/${ eng . id } ` } color = "inherit" >
241
+ { eng . label }
242
+ </ Link > { ' ' }
243
+ is < FormattedDate date = { CalendarDate . fromISO ( eng . date ) } />
244
+ </ li >
245
+ ) ) }
246
+ </ Box >
247
+ </ >
248
+ ) ;
249
+ const points = new Set ( engagements . map ( ( eng ) => eng . point ) ) ;
250
+ return {
251
+ [ FORM_ERROR ] : rendered ,
252
+ // Mark the field(s) as invalid,
253
+ // even though we show the error in the unified spot.
254
+ project : {
255
+ ...( points . has ( 'start' ) ? { mouStart : ' ' } : { } ) ,
256
+ ...( points . has ( 'end' ) ? { mouEnd : ' ' } : { } ) ,
257
+ } ,
258
+ } ;
259
+ } ,
260
+ } }
222
261
>
223
262
< SubmitError />
224
263
< FieldGroup prefix = "project" >
0 commit comments