Refactor Honesty (#39726)

* remove unused prop from Honesty component

* convert Honesty into a functional component
This commit is contained in:
max-voronov
2020-10-01 17:11:45 +03:00
committed by GitHub
parent 2b60d14b5c
commit 17a6a8868b

View File

@@ -1,4 +1,4 @@
import React, { Component } from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Button, Panel } from '@freecodecamp/react-bootstrap'; import { Button, Panel } from '@freecodecamp/react-bootstrap';
@@ -10,20 +10,11 @@ import './honesty.css';
const propTypes = { const propTypes = {
isHonest: PropTypes.bool, isHonest: PropTypes.bool,
policy: PropTypes.arrayOf(PropTypes.string),
updateIsHonest: PropTypes.func.isRequired updateIsHonest: PropTypes.func.isRequired
}; };
class Honesty extends Component { const Honesty = ({ isHonest, updateIsHonest }) => {
handleAgreeClick = () => this.props.updateIsHonest({ isHonest: true }); const button = isHonest ? (
renderAgreeButton = () => (
<Button block={true} bsStyle='primary' onClick={this.handleAgreeClick}>
Agree
</Button>
);
renderIsHonestAgreed = () => (
<Button <Button
block={true} block={true}
bsStyle='primary' bsStyle='primary'
@@ -32,25 +23,28 @@ class Honesty extends Component {
> >
<p>You have accepted our Academic Honesty Policy.</p> <p>You have accepted our Academic Honesty Policy.</p>
</Button> </Button>
) : (
<Button
block={true}
bsStyle='primary'
onClick={() => updateIsHonest({ isHonest: true })}
>
Agree
</Button>
); );
return (
render() { <section className='honesty-policy'>
const { isHonest } = this.props; <SectionHeader>Academic Honesty Policy</SectionHeader>
<FullWidthRow>
return ( <Panel className='honesty-panel'>
<section className='honesty-policy'> <HonestyPolicy />
<SectionHeader>Academic Honesty Policy</SectionHeader> </Panel>
<FullWidthRow> <br />
<Panel className='honesty-panel'> {button}
<HonestyPolicy /> </FullWidthRow>
</Panel> </section>
<br /> );
{isHonest ? this.renderIsHonestAgreed() : this.renderAgreeButton()} };
</FullWidthRow>
</section>
);
}
}
Honesty.displayName = 'Honesty'; Honesty.displayName = 'Honesty';
Honesty.propTypes = propTypes; Honesty.propTypes = propTypes;