Skip to content

Commit 5654050

Browse files
committed
Fixing proper error reporting in GroupsTeacher page for group creation/binding operations.
1 parent a9ccb1f commit 5654050

File tree

3 files changed

+40
-19
lines changed

3 files changed

+40
-19
lines changed

src/locales/cs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
"app.groupsTeacher.createParentGroupLabelExplanation": "Zobrazují se pouze skupiny, které jsou umístěny zároveň pod skupinou předmětu `{course}` a skupinou semestru `{term}`.",
123123
"app.groupsTeacher.lastRefreshInfo": "Seznam předmětů, které vyučujete, byl naposledy stažen ze SISu",
124124
"app.groupsTeacher.noActiveTerms": "V tuto chvíli nejsou učitelům dostupné žádné semestry.",
125+
"app.groupsTeacher.noGroupsForSelection": "Nejsou dostupné žádné vhodné skupiny pro výběr...",
125126
"app.groupsTeacher.notTeacher": "Tato stránka je dostupná pouze učitelům.",
126127
"app.groupsTeacher.scheduledAt": "Rozvrženo na",
127128
"app.groupsTeacher.selectGroupForBinding": "Vyberte skupinu pro svázání",

src/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
"app.groupsTeacher.createParentGroupLabelExplanation": "Only groups that are located in the hierarchy under both `{course}` course group and `{term}` term group are listed.",
123123
"app.groupsTeacher.lastRefreshInfo": "The list of courses taught by you was last downloaded from SIS",
124124
"app.groupsTeacher.noActiveTerms": "There are currently no terms available for teachers.",
125+
"app.groupsTeacher.noGroupsForSelection": "There are no suitable groups to select from...",
125126
"app.groupsTeacher.notTeacher": "This page is available only to teachers.",
126127
"app.groupsTeacher.scheduledAt": "Scheduled at",
127128
"app.groupsTeacher.selectGroupForBinding": "Select Group for Binding",

src/pages/GroupsTeacher/GroupsTeacher.js

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,15 @@ class GroupsTeacher extends Component {
8686
selectedGroupId: '',
8787
};
8888

89-
startBind = (bindEvent, selectGroups) => this.setState({ bindEvent, selectGroups });
89+
startBind = (bindEvent, selectGroups) => {
90+
const selectedGroupId = selectGroups[0]?.id || '';
91+
this.setState({ bindEvent, selectGroups, selectedGroupId });
92+
};
9093

91-
startCreate = (createEvent, selectGroups) => this.setState({ createEvent, selectGroups });
94+
startCreate = (createEvent, selectGroups) => {
95+
const selectedGroupId = selectGroups[0]?.id || '';
96+
this.setState({ createEvent, selectGroups, selectedGroupId });
97+
};
9298

9399
closeModal = () =>
94100
this.setState({
@@ -102,25 +108,29 @@ class GroupsTeacher extends Component {
102108

103109
handleGroupChange = ev => this.setState({ selectedGroupId: ev.target.value });
104110

105-
completeModalOperation = () => {
111+
completeModalOperation = async () => {
106112
const { loggedInUserId, bind, create, loadAsync } = this.props;
107113

108-
this.setState({ modalPending: true });
109-
if (this.state.bindEvent !== null) {
110-
bind(this.state.selectedGroupId, this.state.bindEvent).then(
111-
() => loadAsync(loggedInUserId).then(this.closeModal),
112-
error => this.setState({ modalPending: false, modalError: error?.message || 'unknown error' })
113-
);
114-
} else if (this.state.createEvent !== null) {
115-
create(this.state.selectedGroupId, this.state.createEvent)
116-
.then(
117-
() => loadAsync(loggedInUserId),
118-
error => this.setState({ modalPending: false, modalError: error?.message || 'unknown error' })
119-
)
120-
.then(this.closeModal);
121-
} else {
114+
if (!this.state.bindEvent && !this.state.createEvent) {
122115
this.closeModal();
116+
return;
117+
}
118+
119+
this.setState({ modalPending: true });
120+
121+
try {
122+
if (this.state.bindEvent !== null) {
123+
await bind(this.state.selectedGroupId, this.state.bindEvent);
124+
} else if (this.state.createEvent !== null) {
125+
await create(this.state.selectedGroupId, this.state.createEvent);
126+
}
127+
} catch (error) {
128+
this.setState({ modalPending: false, modalError: error?.message || 'unknown error' });
129+
return;
123130
}
131+
132+
await loadAsync(loggedInUserId);
133+
this.closeModal();
124134
};
125135

126136
unbindAndReload = (groupId, eventId) => {
@@ -376,10 +386,10 @@ class GroupsTeacher extends Component {
376386
</FormLabel>
377387
<InputGroup>
378388
<FormSelect
379-
className="form-control"
389+
className={'form-control' + (!this.state.selectGroups?.length ? ' text-danger' : '')}
380390
value={this.state.selectedGroupId}
391+
disabled={!this.state.selectGroups?.length}
381392
onChange={this.handleGroupChange}>
382-
<option value="">...</option>
383393
{this.state.selectGroups?.map(group => (
384394
<option key={group.id} value={group.id}>
385395
{group.fullName}&nbsp;&nbsp;
@@ -393,6 +403,15 @@ class GroupsTeacher extends Component {
393403
)}
394404
</option>
395405
))}
406+
407+
{!this.state.selectGroups?.length && (
408+
<option value="">
409+
<FormattedMessage
410+
id="app.groupsTeacher.noGroupsForSelection"
411+
defaultMessage="There are no suitable groups to select from..."
412+
/>
413+
</option>
414+
)}
396415
</FormSelect>
397416
</InputGroup>
398417
</FormGroup>

0 commit comments

Comments
 (0)