@@ -4,17 +4,54 @@ import { MantineReactTable, type MRT_ColumnDef } from 'mantine-react-table';
44import  {  z  }  from  'zod' ; 
55import  {  OrganizationList  }  from  '@common/orgs' ; 
66
7+ const  OrganizationListEnum  =  z . enum ( OrganizationList ) ; 
8+ 
79const  userSchema  =  z . object ( { 
810  netid : z . string ( ) . min ( 1 ) , 
9-   org : z . enum ( OrganizationList ) , 
11+   org : OrganizationListEnum , 
1012  firstName : z . string ( ) . min ( 1 ) , 
1113  middleName : z . string ( ) . optional ( ) , 
1214  lastName : z . string ( ) . min ( 1 ) , 
1315} ) ; 
16+ 
17+ const  orgSuperRowSchema  =  userSchema . extend ( { 
18+   netid : z . string ( ) . max ( 0 ) , 
19+   firstName : z . string ( ) . max ( 0 ) , 
20+   lastName : z . string ( ) . max ( 0 ) , 
21+   subRows : userSchema . array ( ) , 
22+ } ) ; 
23+ 
1424export  type  User  =  z . infer < typeof  userSchema > ; 
25+ export  type  OrgSuperRow  =  z . infer < typeof  orgSuperRowSchema > ; 
26+ export  type  Org  =  z . infer < typeof  OrganizationListEnum > ; 
27+ 
28+ function  groupUsersByOrg ( users : User [ ] ) : OrgSuperRow [ ]  { 
29+   const  grouped : Record < Org ,  User [ ] >  =  { }  as  Record < Org ,  User [ ] > ; 
30+ 
31+   // Group users by organization 
32+   users . forEach ( ( user )  =>  { 
33+     if  ( ! grouped [ user . org ] )  { 
34+       grouped [ user . org ]  =  [ ] ; 
35+     } 
36+     grouped [ user . org ] . push ( user ) ; 
37+   } ) ; 
38+ 
39+   // Transform into the desired structure 
40+   const  reformatted  =  Object . entries ( grouped ) . map ( ( [ org ,  subRows ] )  => 
41+     orgSuperRowSchema . parse ( { 
42+       netid : '' , 
43+       org, 
44+       firstName : '' , 
45+       lastName : '' , 
46+       subRows, 
47+     } ) 
48+   ) ; 
49+ 
50+   return  reformatted ; 
51+ } 
1552
1653export  const  ScreenComponent : React . FC  =  ( )  =>  { 
17-   const  [ userList ,  setUserList ]  =  useState < User [ ] > ( [ ] ) ; 
54+   const  [ userList ,  setUserList ]  =  useState < OrgSuperRow [ ] > ( [ ] ) ; 
1855  const  columns  =  useMemo < MRT_ColumnDef < User > [ ] > ( 
1956    ( )  =>  [ 
2057      { 
@@ -119,7 +156,8 @@ export const ScreenComponent: React.FC = () => {
119156        return  {  ...orgObj ,  ...nameObj  }  as  User ; 
120157      } ) ; 
121158
122-       setUserList ( mergedResponse ) ; 
159+       // console.log(mergedResponse); 
160+       setUserList ( groupUsersByOrg ( mergedResponse ) ) ; 
123161    } ; 
124162    getUsers ( ) ; 
125163  } ,  [ ] ) ; 
0 commit comments