Don't continue until user selects courses - or none

This commit is contained in:
Tanner Collin 2019-01-28 16:20:47 -07:00
parent 95291af594
commit 6a448aca85

View File

@ -33,6 +33,7 @@ class App extends Component {
connected: false, connected: false,
network: true, network: true,
selectedCourses: null, selectedCourses: null,
selectedNone: false,
}; };
} }
@ -63,7 +64,7 @@ class App extends Component {
if (response.ok) { if (response.ok) {
response.json().then(data => this.setState({ response.json().then(data => this.setState({
toolData: data, toolData: data,
selectedCourses: data.courses.map(() => false), selectedCourses: data.courses.map(x => false),
})); }));
} else { } else {
this.noNetwork(); this.noNetwork();
@ -161,7 +162,12 @@ class App extends Component {
toggleCourse = (i, data) => { toggleCourse = (i, data) => {
let selectedCourses = this.state.selectedCourses; let selectedCourses = this.state.selectedCourses;
selectedCourses[i] = data.checked; selectedCourses[i] = data.checked;
this.setState({ selectedCourses: selectedCourses }); this.setState({ selectedCourses: selectedCourses, selectedNone: false });
}
selectNone = (data) => {
let selectedCourses = this.state.selectedCourses.map(x => false);
this.setState({ selectedCourses: selectedCourses, selectedNone: data.checked });
} }
submitCourses = () => { submitCourses = () => {
@ -194,6 +200,7 @@ class App extends Component {
const connected = this.state.connected; const connected = this.state.connected;
const network = this.state.network; const network = this.state.network;
const selectedCourses = this.state.selectedCourses; const selectedCourses = this.state.selectedCourses;
const selectedNone = this.state.selectedNone;
console.log(this.state); console.log(this.state);
@ -256,8 +263,13 @@ class App extends Component {
key={i} key={i}
/> />
)} )}
<Form.Checkbox
checked={selectedNone}
onChange={(e, data) => this.selectNone(data)}
label='None'
/>
<br /> <br />
<Button type='submit'>Submit</Button> <Button type='submit' disabled={!selectedCourses.some(x => x) && !selectedNone}>Submit</Button>
</Form> </Form>
<br />Note: your selection will be reviewed by a lockout admin <br />Note: your selection will be reviewed by a lockout admin
</div> </div>