@@ -13,9 +13,10 @@ import { useEmployees } from '../../context/EmployeesContext';
1313import { useToast , ToastStatus } from '../../context/toastContext' ;
1414import axios from '../../util/axios' ;
1515import { extractNetIdFromEmail } from 'util/userUtils' ;
16+ import { EmployeeType } from '@carriage-web/shared/types/employee' ;
1617
1718type AdminData = {
18- type : string [ ] ;
19+ adminRoles : string [ ] ;
1920 isDriver : boolean ;
2021} ;
2122
@@ -37,23 +38,22 @@ type EmployeeEntity = {
3738 photoLink ?: string ;
3839} ;
3940
40- // both for formating to current api data expections
41- function extractAdminData ( employeeData : EmployeeEntity ) {
41+ // both for formatting to current api data expectations
42+ function extractAdminData ( employeeData : EmployeeEntity ) : Omit < EmployeeType , 'id' > {
4243 return {
4344 firstName : employeeData . firstName ,
4445 lastName : employeeData . lastName ,
45- type : ( employeeData . admin ?. type || [ ] ) as (
46- | 'sds-admin'
47- | 'redrunner-admin'
48- ) [ ] ,
46+ adminRoles : employeeData . admin ?. adminRoles || [ ] ,
47+ isAdmin : true ,
4948 isDriver : employeeData . admin ?. isDriver || false ,
5049 phoneNumber : employeeData . phoneNumber ,
5150 email : employeeData . email ,
5251 photoLink : employeeData . photoLink ,
52+ availability : employeeData . driver ?. availability || [ ] ,
5353 } ;
5454}
5555
56- function extractDriverData ( employeeData : EmployeeEntity ) {
56+ function extractDriverData ( employeeData : EmployeeEntity ) : Partial < EmployeeType > {
5757 return {
5858 firstName : employeeData . firstName ,
5959 lastName : employeeData . lastName ,
@@ -62,6 +62,7 @@ function extractDriverData(employeeData: EmployeeEntity) {
6262 joinDate : employeeData . driver ?. startDate ,
6363 email : employeeData . email ,
6464 photoLink : employeeData . photoLink ,
65+ isDriver : true ,
6566 } ;
6667}
6768
@@ -93,13 +94,12 @@ const EmployeeModal = ({
9394 // Initialize form and roles when modal opens or existing employee changes
9495 React . useEffect ( ( ) => {
9596 if ( existingEmployee && isOpen ) {
96- // Initialize roles
97+ // Initialize roles, normalizing Prisma enum values (SDS_ADMIN → sds-admin)
98+ const normalizeRole = ( r : string ) =>
99+ r . toLowerCase ( ) . replace ( / _ / g, '-' ) ;
97100 const roles : string [ ] = [ ] ;
98- if ( existingEmployee . admin ) {
99- // Add admin roles
100- if ( existingEmployee . admin . type ) {
101- roles . push ( ...existingEmployee . admin . type ) ;
102- }
101+ if ( existingEmployee . admin ?. adminRoles ) {
102+ roles . push ( ...existingEmployee . admin . adminRoles . map ( normalizeRole ) ) ;
103103 }
104104 if ( existingEmployee . driver ) {
105105 roles . push ( 'driver' ) ;
@@ -131,8 +131,9 @@ const EmployeeModal = ({
131131
132132 const closeModal = ( ) => {
133133 methods . clearErrors ( ) ;
134- setImageBase64 ( '' ) ; // Reset image state
135- setIsUploadingImage ( false ) ; // Reset upload state
134+ setImageBase64 ( '' ) ;
135+ setIsUploadingImage ( false ) ;
136+ setSelectedRole ( [ ] ) ;
136137 setIsOpen ( false ) ;
137138 } ;
138139
@@ -178,7 +179,7 @@ const EmployeeModal = ({
178179 switch ( endpoint ) {
179180 case '/api/drivers' :
180181 // Use optimistic create from context
181- await createDriver ( extractDriverData ( employeeData ) ) ;
182+ await createDriver ( extractDriverData ( employeeData ) as Omit < EmployeeType , 'id' > ) ;
182183 res = employeeData ; // The context will handle server response and ID assignment
183184 break ;
184185 case '/api/admins' :
@@ -330,7 +331,7 @@ const EmployeeModal = ({
330331
331332 if ( hasAdmin ) {
332333 admin_data = {
333- type : selectedRoles . filter ( ( role ) => role !== 'driver' ) ,
334+ adminRoles : selectedRoles . filter ( ( role ) => role !== 'driver' ) ,
334335 isDriver : hasDriver ,
335336 } ;
336337 }
@@ -436,8 +437,13 @@ const EmployeeModal = ({
436437 phone = { existingEmployee ?. phoneNumber }
437438 />
438439
440+ < RoleSelector
441+ selectedRoles = { selectedRoles }
442+ setSelectedRoles = { setSelectedRole }
443+ />
444+
439445 { ( selectedRoles . includes ( 'driver' ) ||
440- existingEmployee ?. driver ?. availability ) && (
446+ existingEmployee ?. driver != null ) && (
441447 < >
442448 < StartDate existingDate = { existingEmployee ?. driver ?. startDate } />
443449 < WorkingHours
@@ -447,11 +453,6 @@ const EmployeeModal = ({
447453 </ >
448454 ) }
449455
450- < RoleSelector
451- selectedRoles = { selectedRoles }
452- setSelectedRoles = { setSelectedRole }
453- />
454-
455456 < Button className = { styles . submit } type = "submit" >
456457 { existingEmployee ? 'Save' : 'Add' }
457458 </ Button >
0 commit comments