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