@@ -6,12 +6,12 @@ import { CreateTeamPayload, useCreateTeam } from '../../hooks/teams.hooks';
66import ErrorPage from '../ErrorPage' ;
77import LoadingIndicator from '../../components/LoadingIndicator' ;
88import NERFormModal from '../../components/NERFormModal' ;
9- import { FormControl , FormHelperText , FormLabel } from '@mui/material' ;
9+ import { FormControl , FormLabel } from '@mui/material' ;
1010import ReactHookTextField from '../../components/ReactHookTextField' ;
1111import { useAllUsers } from '../../hooks/users.hooks' ;
12- import { User , isHead } from 'shared' ;
12+ import { isHead } from 'shared' ;
1313import NERAutocomplete from '../../components/NERAutocomplete' ;
14- import { fullNamePipe } from '../../utils/pipes ' ;
14+ import { userComparator , userToAutocompleteOption } from '../../utils/teams.utils ' ;
1515
1616const schema = yup . object ( ) . shape ( {
1717 teamName : yup . string ( ) . required ( 'Team Name is Required' ) ,
@@ -25,10 +25,6 @@ interface CreateTeamModalProps {
2525 handleClose : ( ) => void ;
2626}
2727
28- const userToAutocompleteOption = ( user : User ) : { label : string ; id : string } => {
29- return { label : `${ fullNamePipe ( user ) } (${ user . email } )` , id : `${ user . userId } ` } ;
30- } ;
31-
3228const CreateTeamModal = ( { showModal, handleClose } : CreateTeamModalProps ) => {
3329 const { isLoading, mutateAsync } = useCreateTeam ( ) ;
3430 const { isLoading : allUsersIsLoading , isError : allUsersIsError , error : allUsersError , data : users } = useAllUsers ( ) ;
@@ -68,7 +64,7 @@ const CreateTeamModal = ({ showModal, handleClose }: CreateTeamModalProps) => {
6864
6965 const headOptions = users
7066 . filter ( ( user ) => isHead ( user . role ) )
71- . sort ( ( a , b ) => ( a . firstName > b . firstName ? 1 : - 1 ) )
67+ . sort ( userComparator )
7268 . map ( userToAutocompleteOption ) ;
7369
7470 return (
@@ -84,8 +80,7 @@ const CreateTeamModal = ({ showModal, handleClose }: CreateTeamModalProps) => {
8480 >
8581 < FormControl fullWidth >
8682 < FormLabel > Team Name</ FormLabel >
87- < ReactHookTextField name = "teamName" control = { control } fullWidth />
88- < FormHelperText error > { errors . teamName ?. message } </ FormHelperText >
83+ < ReactHookTextField name = "teamName" control = { control } fullWidth errorMessage = { errors . teamName } />
8984 </ FormControl >
9085 < FormControl fullWidth >
9186 < FormLabel > Head</ FormLabel >
@@ -100,20 +95,25 @@ const CreateTeamModal = ({ showModal, handleClose }: CreateTeamModalProps) => {
10095 id = "create-team-head"
10196 size = "small"
10297 placeholder = "Choose a user"
98+ errorMessage = { errors . headId }
10399 />
104100 ) }
105101 />
106- < FormHelperText error > { errors . headId ?. message } </ FormHelperText >
107102 </ FormControl >
108103 < FormControl fullWidth >
109104 < FormLabel > Slack Channel ID</ FormLabel >
110- < ReactHookTextField name = "slackId" control = { control } fullWidth />
111- < FormHelperText error > { errors . slackId ?. message } </ FormHelperText >
105+ < ReactHookTextField name = "slackId" control = { control } fullWidth errorMessage = { errors . slackId } />
112106 </ FormControl >
113107 < FormControl fullWidth >
114108 < FormLabel > Description</ FormLabel >
115- < ReactHookTextField name = "description" control = { control } fullWidth multiline rows = { 5 } />
116- < FormHelperText error > { errors . description ?. message } </ FormHelperText >
109+ < ReactHookTextField
110+ name = "description"
111+ control = { control }
112+ fullWidth
113+ multiline
114+ rows = { 5 }
115+ errorMessage = { errors . description }
116+ />
117117 </ FormControl >
118118 </ NERFormModal >
119119 ) ;
0 commit comments