Skip to content

Commit 5a72bee

Browse files
committed
wip
1 parent 62b8485 commit 5a72bee

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

hwproj.front/src/components/Common/GroupSelector.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ interface GroupSelectorProps {
3232
}
3333

3434
const GroupSelector: FC<GroupSelectorProps> = (props) => {
35-
const groups = [...(props.groups || []), {id: undefined, name: "Все студенты"}]
35+
const groups = [{id: -1, name: "Новая группа"}, {id: undefined, name: "Все студенты"}, ...(props.groups || [])]
3636
const selectedGroup = groups.find(g => g.id === props.selectedGroupId)
3737

3838
const [isDialogOpen, setIsDialogOpen] = useState(false);
@@ -76,7 +76,7 @@ const GroupSelector: FC<GroupSelectorProps> = (props) => {
7676
const handleSubmitEdit = async () => {
7777
setIsSubmitting(true);
7878
try {
79-
if (selectedGroup) {
79+
if (selectedGroup && selectedGroup.id! > 0) {
8080
await ApiSingleton.courseGroupsApi.courseGroupsUpdateCourseGroup(
8181
props.courseId,
8282
selectedGroup.id!,
@@ -116,11 +116,19 @@ const GroupSelector: FC<GroupSelectorProps> = (props) => {
116116
disableClearable={props.selectedGroupId === undefined}
117117
fullWidth
118118
options={[...groups]}
119+
renderOption={(props, option) => {
120+
if (option.id === -1)
121+
return <li {...props} style={{color: "#2979ff"}} key={option.id}>+ Добавить новую
122+
группу</li>
123+
if (option.id === undefined)
124+
return <li {...props} key={option.id}><b>{option.name}</b></li>
125+
return <li {...props} key={option.id}>{option.name}</li>
126+
}}
119127
getOptionLabel={(option) => typeof option === 'string' ? option : option?.name || "Все студенты"}
120-
value={groups.find(g => g.id == props.selectedGroupId)}
128+
value={formState.name}
121129
onChange={(_, newGroup) => {
122130
if (typeof newGroup === 'string') return
123-
props.onGroupIdChange(newGroup?.id)
131+
if (props.selectedGroupId !== newGroup?.id) props.onGroupIdChange(newGroup?.id)
124132
}}
125133
onInputChange={(_, newInputValue, reason) => {
126134
if (reason === 'input' && props.selectedGroupId !== undefined) {

0 commit comments

Comments
 (0)