@@ -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,21 @@ export type DaycareAclRole = Extract<
74
76
| 'EARLY_CHILDHOOD_EDUCATION_SECRETARY'
75
77
>
76
78
79
+ const roleOrder = ( role : UserRole ) => {
80
+ switch ( role ) {
81
+ case 'UNIT_SUPERVISOR' :
82
+ return 0
83
+ case 'SPECIAL_EDUCATION_TEACHER' :
84
+ return 1
85
+ case 'EARLY_CHILDHOOD_EDUCATION_SECRETARY' :
86
+ return 2
87
+ case 'STAFF' :
88
+ return 3
89
+ default :
90
+ return 999 // not expected
91
+ }
92
+ }
93
+
77
94
function GroupListing ( {
78
95
unitGroups,
79
96
groupIds
@@ -235,14 +252,7 @@ function AclTable({
235
252
orderBy (
236
253
rows . filter ( ( row ) => ! row . employee . temporary ) ,
237
254
[
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 ,
255
+ ( row ) => roleOrder ( row . role ) ,
246
256
( row ) => row . employee . firstName ,
247
257
( row ) => row . employee . lastName
248
258
]
@@ -313,6 +323,52 @@ function AclTable({
313
323
)
314
324
}
315
325
326
+ function ScheduledAclTable ( { rows } : { rows : ScheduledDaycareAclRow [ ] } ) {
327
+ const { i18n } = useTranslation ( )
328
+
329
+ const orderedRows = useMemo (
330
+ ( ) =>
331
+ orderBy ( rows , [
332
+ ( row ) => roleOrder ( row . role ) ,
333
+ ( row ) => row . firstName ,
334
+ ( row ) => row . lastName
335
+ ] ) ,
336
+ [ rows ]
337
+ )
338
+
339
+ return (
340
+ < Table data-qa = "scheduled-acl-table" >
341
+ < Thead >
342
+ < Tr >
343
+ < Th > { i18n . unit . accessControl . role } </ Th >
344
+ < Th > { i18n . common . form . name } </ Th >
345
+ < Th > { i18n . unit . accessControl . aclStartDate } </ Th >
346
+ < Th > { i18n . unit . accessControl . aclEndDate } </ Th >
347
+ </ Tr >
348
+ </ Thead >
349
+ < Tbody >
350
+ { orderedRows . map ( ( row ) => (
351
+ < Tr key = { row . id } data-qa = { `scheduled-acl-row-${ row . id } ` } >
352
+ < Td >
353
+ < span data-qa = "role" > { i18n . roles . adRoles [ row . role ] } </ span >
354
+ </ Td >
355
+ < Td >
356
+ < FixedSpaceColumn spacing = "zero" >
357
+ < span data-qa = "name" >
358
+ { formatName ( row . firstName , row . lastName , i18n ) }
359
+ </ span >
360
+ < EmailSpan data-qa = "email" > { row . email } </ EmailSpan >
361
+ </ FixedSpaceColumn >
362
+ </ Td >
363
+ < Td > { row . startDate . format ( ) } </ Td >
364
+ < Td > { row . endDate ?. format ( ) } </ Td >
365
+ </ Tr >
366
+ ) ) }
367
+ </ Tbody >
368
+ </ Table >
369
+ )
370
+ }
371
+
316
372
function TemporaryEmployeesTable ( {
317
373
unitId,
318
374
unitGroups,
@@ -521,6 +577,9 @@ export default React.memo(function UnitAccessControl({
521
577
522
578
const employees = useQueryResult ( getEmployeesQuery ( ) )
523
579
const daycareAclRows = useQueryResult ( unitAclQuery ( { unitId } ) )
580
+ const scheduledDaycareAclRows = useQueryResult (
581
+ unitScheduledAclQuery ( { unitId } )
582
+ )
524
583
const temporaryEmployees = useQueryResult (
525
584
permittedActions . includes ( 'READ_TEMPORARY_EMPLOYEE' )
526
585
? temporaryEmployeesQuery ( { unitId } )
@@ -649,6 +708,11 @@ export default React.memo(function UnitAccessControl({
649
708
650
709
< Gap size = "XL" />
651
710
711
+ < H3 noMargin > { i18n . unit . accessControl . scheduledAclRoles } </ H3 >
712
+ { renderResult ( scheduledDaycareAclRows , ( scheduledDaycareAclRows ) => (
713
+ < ScheduledAclTable rows = { scheduledDaycareAclRows } />
714
+ ) ) }
715
+
652
716
< FixedSpaceRow justifyContent = "space-between" alignItems = "center" >
653
717
< H3 noMargin > { i18n . unit . accessControl . temporaryEmployees . title } </ H3 >
654
718
{ permittedActions . includes ( 'CREATE_TEMPORARY_EMPLOYEE' ) && (
0 commit comments