-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathAdvancedStudentOptionsDialog.js
More file actions
78 lines (72 loc) · 2.14 KB
/
Copy pathAdvancedStudentOptionsDialog.js
File metadata and controls
78 lines (72 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// @flow
import * as React from 'react';
import { I18n } from '@lingui/react';
import { t, Trans } from '@lingui/macro';
import Dialog from '../../../../UI/Dialog';
import FlatButton from '../../../../UI/FlatButton';
import { CompactToggleField } from '../../../../UI/CompactToggleField';
import { Line } from '../../../../UI/Grid';
import TeamContext from '../../../../Profile/Team/TeamContext';
type Props = {|
onClose: () => void,
|};
const AdvancedStudentOptionsDialog = ({ onClose }: Props): React.Node => {
const { team, onUpdateTeam } = React.useContext(TeamContext);
const [isUpdatingTeam, setIsUpdatingTeam] = React.useState<boolean>(false);
const onToggleStudentsAskAi = React.useCallback(
async (allowed: boolean) => {
setIsUpdatingTeam(true);
try {
await onUpdateTeam({ classrooms: { hideAskAi: !allowed } });
} catch (error) {
console.error(
'An error occurred while updating the team AI setting:',
error
);
} finally {
setIsUpdatingTeam(false);
}
},
[onUpdateTeam]
);
return (
<I18n>
{({ i18n }) => (
<Dialog
title={<Trans>Advanced student options</Trans>}
actions={[
<FlatButton
label={<Trans>Close</Trans>}
disabled={isUpdatingTeam}
key="close"
primary={false}
onClick={onClose}
/>,
]}
maxWidth="sm"
cannotBeDismissed={isUpdatingTeam}
onRequestClose={onClose}
open
>
<Line noMargin>
<CompactToggleField
label={i18n._(
t`Allow students to use GDevelop's AI (disabled by default)`
)}
checked={
!!team &&
!!team.classrooms &&
team.classrooms.hideAskAi === false
}
onCheck={allowed => {
onToggleStudentsAskAi(allowed);
}}
disabled={isUpdatingTeam}
/>
</Line>
</Dialog>
)}
</I18n>
);
};
export default AdvancedStudentOptionsDialog;