@@ -18,6 +18,7 @@ import {
18
18
DaycareAclRow ,
19
19
DaycareId ,
20
20
EmployeeId ,
21
+ ScheduledDaycareAclRow ,
21
22
UserRole
22
23
} from 'lib-common/generated/api-types/shared'
23
24
import {
@@ -58,7 +59,8 @@ import {
58
59
deleteUnitSupervisorMutation ,
59
60
reactivateTemporaryEmployeeMutation ,
60
61
temporaryEmployeesQuery ,
61
- unitAclQuery
62
+ unitAclQuery ,
63
+ unitScheduledAclQuery
62
64
} from '../queries'
63
65
64
66
import AddAclModal from './acl-modals/AddAclModal'
@@ -74,6 +76,17 @@ export type DaycareAclRole = Extract<
74
76
| 'EARLY_CHILDHOOD_EDUCATION_SECRETARY'
75
77
>
76
78
79
+ const roleOrder = ( role : UserRole ) =>
80
+ role === 'UNIT_SUPERVISOR'
81
+ ? 0
82
+ : role === 'SPECIAL_EDUCATION_TEACHER'
83
+ ? 1
84
+ : role === 'EARLY_CHILDHOOD_EDUCATION_SECRETARY'
85
+ ? 2
86
+ : role === 'STAFF'
87
+ ? 3
88
+ : 999 // not expected
89
+
77
90
function GroupListing ( {
78
91
unitGroups,
79
92
groupIds
@@ -235,14 +248,7 @@ function AclTable({
235
248
orderBy (
236
249
rows . filter ( ( row ) => ! row . employee . temporary ) ,
237
250
[
238
- ( row ) =>
239
- row . role === 'UNIT_SUPERVISOR'
240
- ? 0
241
- : row . role === 'SPECIAL_EDUCATION_TEACHER'
242
- ? 1
243
- : row . role === 'EARLY_CHILDHOOD_EDUCATION_SECRETARY'
244
- ? 2
245
- : 3 ,
251
+ ( row ) => roleOrder ( row . role ) ,
246
252
( row ) => row . employee . firstName ,
247
253
( row ) => row . employee . lastName
248
254
]
@@ -313,6 +319,52 @@ function AclTable({
313
319
)
314
320
}
315
321
322
+ function ScheduledAclTable ( { rows } : { rows : ScheduledDaycareAclRow [ ] } ) {
323
+ const { i18n } = useTranslation ( )
324
+
325
+ const orderedRows = useMemo (
326
+ ( ) =>
327
+ orderBy ( rows , [
328
+ ( row ) => roleOrder ( row . role ) ,
329
+ ( row ) => row . firstName ,
330
+ ( row ) => row . lastName
331
+ ] ) ,
332
+ [ rows ]
333
+ )
334
+
335
+ return (
336
+ < Table data-qa = "scheduled-acl-table" >
337
+ < Thead >
338
+ < Tr >
339
+ < Th > { i18n . unit . accessControl . role } </ Th >
340
+ < Th > { i18n . common . form . name } </ Th >
341
+ < Th > { i18n . unit . accessControl . aclStartDate } </ Th >
342
+ < Th > { i18n . unit . accessControl . aclEndDate } </ Th >
343
+ </ Tr >
344
+ </ Thead >
345
+ < Tbody >
346
+ { orderedRows . map ( ( row ) => (
347
+ < Tr key = { row . id } data-qa = { `scheduled-acl-row-${ row . id } ` } >
348
+ < Td >
349
+ < span data-qa = "role" > { i18n . roles . adRoles [ row . role ] } </ span >
350
+ </ Td >
351
+ < Td >
352
+ < FixedSpaceColumn spacing = "zero" >
353
+ < span data-qa = "name" >
354
+ { formatName ( row . firstName , row . lastName , i18n ) }
355
+ </ span >
356
+ < EmailSpan data-qa = "email" > { row . email } </ EmailSpan >
357
+ </ FixedSpaceColumn >
358
+ </ Td >
359
+ < Td > { row . startDate . format ( ) } </ Td >
360
+ < Td > { row . endDate ?. format ( ) } </ Td >
361
+ </ Tr >
362
+ ) ) }
363
+ </ Tbody >
364
+ </ Table >
365
+ )
366
+ }
367
+
316
368
function TemporaryEmployeesTable ( {
317
369
unitId,
318
370
unitGroups,
@@ -521,6 +573,9 @@ export default React.memo(function UnitAccessControl({
521
573
522
574
const employees = useQueryResult ( getEmployeesQuery ( ) )
523
575
const daycareAclRows = useQueryResult ( unitAclQuery ( { unitId } ) )
576
+ const scheduledDaycareAclRows = useQueryResult (
577
+ unitScheduledAclQuery ( { unitId } )
578
+ )
524
579
const temporaryEmployees = useQueryResult (
525
580
permittedActions . includes ( 'READ_TEMPORARY_EMPLOYEE' )
526
581
? temporaryEmployeesQuery ( { unitId } )
@@ -649,6 +704,11 @@ export default React.memo(function UnitAccessControl({
649
704
650
705
< Gap size = "XL" />
651
706
707
+ < H3 noMargin > { i18n . unit . accessControl . scheduledAclRoles } </ H3 >
708
+ { renderResult ( scheduledDaycareAclRows , ( scheduledDaycareAclRows ) => (
709
+ < ScheduledAclTable rows = { scheduledDaycareAclRows } />
710
+ ) ) }
711
+
652
712
< FixedSpaceRow justifyContent = "space-between" alignItems = "center" >
653
713
< H3 noMargin > { i18n . unit . accessControl . temporaryEmployees . title } </ H3 >
654
714
{ permittedActions . includes ( 'CREATE_TEMPORARY_EMPLOYEE' ) && (
0 commit comments