@@ -49,10 +49,10 @@ const GroupSelector: FC<GroupSelectorProps> = (props) => {
4949 const [ isSubmitting , setIsSubmitting ] = useState ( false ) ;
5050 const [ isError , setIsError ] = useState ( false ) ;
5151
52- const studentsWithoutGroup = useMemo ( ( ) => {
53- const studentsInGroups = groups . flatMap ( g => g . studentsIds )
54- return props . courseStudents . filter ( ( cm ) => ! studentsInGroups . includes ( cm . userId ) )
55- } , [ groups , props . courseStudents ] ) ;
52+ const studentsInGroups = useMemo ( ( ) => groups . flatMap ( g => g . studentsIds ) ,
53+ [ groups , props . groups ] ) ;
54+ const studentsWithoutGroup = useMemo ( ( ) => props . courseStudents . filter ( ( cm ) => ! studentsInGroups . includes ( cm . userId ) ) ,
55+ [ groups , props . courseStudents ] ) ;
5656
5757 const handleSubmitEdit = async ( ) => {
5858 setIsSubmitting ( true ) ;
@@ -92,6 +92,7 @@ const GroupSelector: FC<GroupSelectorProps> = (props) => {
9292 disableClearable = { props . selectedGroupId == undefined }
9393 fullWidth
9494 options = { props . selectedGroupId == undefined ? groups : [ ] }
95+ disabled = { props . choiceDisabled }
9596 renderOption = { ( props , option ) => {
9697 if ( option . id === - 1 )
9798 return < li { ...props } style = { { color : "#2979ff" } } key = { option . id } > + Добавить новую
@@ -126,36 +127,27 @@ const GroupSelector: FC<GroupSelectorProps> = (props) => {
126127 < Autocomplete
127128 multiple
128129 fullWidth
129- options = { studentsWithoutGroup }
130+ options = { props . courseStudents }
130131 value = { props . courseStudents ?. filter ( s => formState . memberIds . includes ( s . userId ! ) ) || [ ] }
131132 getOptionLabel = { ( option ) =>
132133 `${ option . surname ?? "" } ${ option . name ?? "" } / ${ option . email ?? "" } ` . trim ( )
133134 }
134135 filterSelectedOptions
135- onChange = { ( _ , values ) => {
136- if ( selectedGroup ) {
137- // При редактировании выбранной группы можно только добавлять студентов
138- setFormState ( prev => ( {
139- ...prev ,
140- memberIds : [ ...formState . memberIds ,
141- ...values . map ( x => ! formState . memberIds . includes ( x . userId ! ) ? x . userId ! : "" ) . filter ( Boolean ) ]
142- } ) )
143- } else {
144- setFormState ( prev => ( {
145- ...prev ,
146- memberIds : values
147- . map ( x => x . userId ! )
148- . filter ( Boolean )
149- } ) )
150- }
136+ onChange = { ( _ , value ) => {
137+ if ( value . map ( x => x . userId ! ) . filter ( Boolean ) . length === 0 ) return ;
138+ setFormState ( prev => ( {
139+ ...prev ,
140+ memberIds : value
141+ . map ( x => x . userId ! )
142+ . filter ( Boolean )
143+ } ) )
151144 } }
152145 disabled = { isSubmitting }
153146 renderTags = { ( tagValue , getTagProps ) =>
154147 tagValue . map ( ( option , index ) => (
155148 < Chip
156149 { ...getTagProps ( { index} ) }
157150 label = { `${ option . surname ?? "" } ${ option . name ?? "" } / ${ option . email ?? "" } ` . trim ( ) }
158- onDelete = { selectedGroup ? undefined : getTagProps ( { index} ) . onDelete }
159151 key = { option . userId }
160152 />
161153 ) )
0 commit comments