diff options
| author | Kamran Ahmed <kamranahmed.se@gmail.com> | 2018-08-29 12:10:53 +0500 |
|---|---|---|
| committer | Kamran Ahmed <kamranahmed.se@gmail.com> | 2018-08-29 12:10:53 +0500 |
| commit | 3f41f6994743358a457d4c92625c7412de399658 (patch) | |
| tree | 5900c759e4971477ee5af21761f3887a096086c3 /src/components/options-form/index.js | |
| parent | Componentize options form (diff) | |
| download | githunt-3f41f6994743358a457d4c92625c7412de399658.tar.gz | |
Save options functionality
Diffstat (limited to '')
| -rw-r--r-- | src/components/options-form/index.js | 75 |
1 files changed, 53 insertions, 22 deletions
diff --git a/src/components/options-form/index.js b/src/components/options-form/index.js index 393ab93..f83bfe3 100644 --- a/src/components/options-form/index.js +++ b/src/components/options-form/index.js @@ -1,29 +1,60 @@ import React from 'react'; import { Link } from 'react-router-dom'; +import PropTypes from 'prop-types'; import './styles.css'; -const OptionsForm = () => ( - <div className="options-form"> - <div className="form-field"> - <h2>Add the Token</h2> - <p className="text-muted">Generate a token and add it below to avoid hitting the rate limit.</p> - <hr/> - <ul> - <li> - Go to the <a href="https://github.com/settings/tokens" target="_blank" rel="noopener noreferrer"><i className="fa fa-external-link mr-1"></i> Settings <i className="fa fa-angle-right"></i> Personal Access Tokens</a> of your github profile - </li> - <li>Click <span>Generate New Token</span>. Enter the description and select the <span>scope</span> called <span>public_repo</span> under repo and click <span>Generate Token</span>.</li> - <li>You will be presented with the generated token. Copy the token and add it below</li> - </ul> - <input type="text" className="form-control"/> - </div> - <button className="btn btn-dark btn-lg btn-save shadow"> - <i className="fa fa-cog mr-2"></i> - Save Settings - </button> - <Link className='btn btn-primary shadow btn-block btn-lg' to='/'><i className="fa fa-arrow-left"></i> Go Home</Link> - </div> -); +class OptionsForm extends React.Component { + + state = { + token: this.props.options.token + }; + + saveOptions = () => { + this.props.updateOptions({ + token: this.state.token + }); + }; + + onChange = (e) => { + this.setState({ + [e.target.name]: e.target.value + }); + }; + + render() { + return ( + <div className="options-form"> + <div className="form-field"> + <h2>Add the Token</h2> + <p className="text-muted">Generate a token and add it below to avoid hitting the rate limit.</p> + <hr/> + <ul> + <li> + Go to the <a href="https://github.com/settings/tokens" target="_blank" rel="noopener noreferrer"><i className="fa fa-external-link mr-1"></i> Settings <i className="fa fa-angle-right"></i> Personal Access Tokens</a> of your github profile + </li> + <li>Click <span>Generate New Token</span>. Enter the description and select the <span>scope</span> called <span>public_repo</span> under repo and click <span>Generate Token</span>.</li> + <li>You will be presented with the generated token. Copy the token and add it below</li> + </ul> + <input type="text" + name='token' + onChange={ this.onChange } + className="form-control" + value={ this.state.token }/> + </div> + <button className="btn btn-dark btn-lg btn-save shadow" onClick={ this.saveOptions }> + <i className="fa fa-cog mr-2"></i> + Save Token + </button> + <Link className='btn btn-primary shadow btn-block btn-lg' to='/'><i className="fa fa-arrow-left"></i> Go Home</Link> + </div> + ); + } +} + +OptionsForm.propTypes = { + updateOptions: PropTypes.func.isRequired, + options: PropTypes.object.isRequired +}; export default OptionsForm; |
