QuickAdd.jsx 1.64 KB
Newer Older
Zac Wood's avatar
Zac Wood committed
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
import React from 'react';
import Cart from 'src/Cart';

export default class QuickAdd extends React.Component {
    constructor(props) {
        super(props);
        this.state = { crnString: '' };
    }

    add = e => {
        e.preventDefault();
        const crns = this.state.crnString.split(',');
        crns.forEach(c => c.length === 5 && Cart.addCrn(c));
        this.props.loadCalendar();
    };

    render() {
        return (
            <div>
                <h3 className="quick-add-header">Quick add</h3>
                <p>Want to quickly generate a calendar populated with your semester's classes? Enter the CRNs in a comma separated list below.</p>
                <form onSubmit={this.add} className="form">
                    <div className="input-group">
                        <input
                            id="crns"
                            name="crns"
                            type="text"
                            value={this.state.crns}
                            onChange={e => this.setState({ crnString: e.target.value })}
                            className="form-control"
                            placeholder="12345,54321,..."
                            aria-describedby="basic-addon2"
                            autoComplete="off"
                        />
                        <div className="input-group-append">
                            <button type="submit" className="btn btn-primary" type="button">
                                Populate Calendar
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        );
    }
}