QuickAdd.jsx 1.64 KB
Newer Older
1 2 3 4 5 6
import React from 'react';
import Cart from 'src/Cart';

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

    add = e => {
        e.preventDefault();
12
        const crns = this.state.crnString.split(',');
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
        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}
29
                            onChange={e => this.setState({ crnString: e.target.value })}
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
                            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>
        );
    }
}