@@ -8,16 +8,41 @@ import {
88 TableHead ,
99 TableRow ,
1010} from "@mui/material" ;
11- import PropTypes from "prop-types" ;
1211import { useUserContext } from "../../../contexts/userContext" ;
1312import * as accountService from "../../../services/account-service" ;
1413
15- export default function SecurityTable ( props ) {
14+ export interface Account {
15+ id : number ;
16+ email : string ;
17+ firstName : string ;
18+ lastName : string ;
19+ isAdmin ?: boolean ;
20+ isCoordinator ?: boolean ;
21+ isSecurityAdmin ?: boolean ;
22+ isDataEntry ?: boolean ;
23+ isGlobalAdmin ?: boolean ;
24+ isGlobalReporting ?: boolean ;
25+ }
26+
27+ export interface SecurityTableProps {
28+ accounts : Account [ ] ;
29+ handlePermissionChange : (
30+ userId : number ,
31+ permission : string ,
32+ value : boolean
33+ ) => Promise < void > | void ;
34+ }
35+
36+ export default function SecurityTable ( props : SecurityTableProps ) {
1637 const { user } = useUserContext ( ) ;
1738
1839 // arg `roleType` is expected to be one of:
1940 // 'security', 'admin, 'dataEntry', or 'coordinator'
20- const handleToggle = ( userId , e , roleType ) => {
41+ const handleToggle = (
42+ userId : number ,
43+ e : React . ChangeEvent < HTMLInputElement > ,
44+ roleType : "security" | "admin" | "dataEntry" | "coordinator"
45+ ) => {
2146 if ( roleType === "security" ) {
2247 props . accounts . map ( async ( each ) => {
2348 if ( userId === each . id ) {
@@ -63,7 +88,11 @@ export default function SecurityTable(props) {
6388
6489 // arg `roleType` is expected to be one of:
6590 // 'globalAdmin' or 'globalReporting'
66- const handleGlobalToggle = ( userId , e , roleType ) => {
91+ const handleGlobalToggle = (
92+ userId : number ,
93+ e : React . ChangeEvent < HTMLInputElement > ,
94+ roleType : "globalAdmin" | "globalReporting"
95+ ) => {
6796 if ( roleType === "globalAdmin" ) {
6897 props . accounts . map ( async ( each ) => {
6998 if ( userId === each . id ) {
@@ -165,15 +194,15 @@ export default function SecurityTable(props) {
165194 < >
166195 < TableCell align = "right" >
167196 < Checkbox
168- checked = { row . isGlobalAdmin }
197+ checked = { Boolean ( row . isGlobalAdmin ) }
169198 onChange = { ( e ) =>
170199 handleGlobalToggle ( row . id , e , "globalAdmin" )
171200 }
172201 />
173202 </ TableCell >
174203 < TableCell align = "right" >
175204 < Checkbox
176- checked = { row . isGlobalReporting }
205+ checked = { Boolean ( row . isGlobalReporting ) }
177206 onChange = { ( e ) =>
178207 handleGlobalToggle ( row . id , e , "globalReporting" )
179208 }
@@ -183,25 +212,25 @@ export default function SecurityTable(props) {
183212 ) : null }
184213 < TableCell align = "right" >
185214 < Checkbox
186- checked = { row . isAdmin }
215+ checked = { Boolean ( row . isAdmin ) }
187216 onChange = { ( e ) => handleToggle ( row . id , e , "admin" ) }
188217 />
189218 </ TableCell >
190219 < TableCell align = "right" >
191220 < Checkbox
192- checked = { row . isCoordinator }
221+ checked = { Boolean ( row . isCoordinator ) }
193222 onChange = { ( e ) => handleToggle ( row . id , e , "coordinator" ) }
194223 />
195224 </ TableCell >
196225 < TableCell align = "right" >
197226 < Checkbox
198- checked = { row . isSecurityAdmin }
227+ checked = { Boolean ( row . isSecurityAdmin ) }
199228 onChange = { ( e ) => handleToggle ( row . id , e , "security" ) }
200229 />
201230 </ TableCell >
202231 < TableCell align = "right" >
203232 < Checkbox
204- checked = { row . isDataEntry }
233+ checked = { Boolean ( row . isDataEntry ) }
205234 onChange = { ( e ) => handleToggle ( row . id , e , "dataEntry" ) }
206235 />
207236 </ TableCell >
@@ -212,19 +241,3 @@ export default function SecurityTable(props) {
212241 </ TableContainer >
213242 ) ;
214243}
215-
216- SecurityTable . propTypes = {
217- accounts : PropTypes . arrayOf (
218- PropTypes . shape ( {
219- id : PropTypes . number . isRequired ,
220- email : PropTypes . string . isRequired ,
221- firstName : PropTypes . string . isRequired ,
222- lastName : PropTypes . string . isRequired ,
223- isAdmin : PropTypes . bool ,
224- isCoordinator : PropTypes . bool ,
225- isSecurityAdmin : PropTypes . bool ,
226- isDataEntry : PropTypes . bool ,
227- } ) . isRequired
228- ) ,
229- handlePermissionChange : PropTypes . func . isRequired ,
230- } ;
0 commit comments