import React, { PureComponent } from 'react'; import { kebabCase, defaultTo } from 'lodash'; import PropTypes from 'prop-types'; import { Button } from 'react-bootstrap'; import { FullWidthRow } from '../../../helperComponents'; import { BlockSaveButton } from '../formHelpers'; import { Link } from '../../../Router'; import SolutionViewer from './SolutionViewer.jsx'; const jsFormPropTypes = { challenges: PropTypes.arrayOf(PropTypes.string), claimCert: PropTypes.func.isRequired, hardGoTo: PropTypes.func.isRequired, isCertClaimed: PropTypes.bool, jsProjects: PropTypes.objectOf( PropTypes.oneOfType([ PropTypes.arrayOf(PropTypes.object), PropTypes.string ]) ), projectBlockName: PropTypes.string, superBlock: PropTypes.string, username: PropTypes.string }; const jsProjectPath = '/challenges/javascript-algorithms-and-data-structures-' + 'projects/'; class JSAlgoAndDSForm extends PureComponent { constructor(props) { super(props); this.state = {}; this.handleSolutionToggle = this.handleSolutionToggle.bind(this); this.handleSubmit = this.handleSubmit.bind(this); } handleSolutionToggle(e) { e.persist(); return this.setState(state => ({ ...state, [e.target.id]: !state[e.target.id] })); } handleSubmit(e) { e.preventDefault(); const { username, superBlock, isCertClaimed } = this.props; if (isCertClaimed) { return this.props.hardGoTo(`/certification/${username}/${superBlock}`); } return this.props.claimCert(superBlock); } render() { const { projectBlockName, challenges = [], jsProjects = {}, isCertClaimed } = this.props; const completeCount = Object.values(jsProjects) .map(val => defaultTo(val, {})) .filter(challengeInfo => Object.keys(challengeInfo).length !== 0) .length; return (

{ projectBlockName }

To complete this certification, you must first complete the JavaScript Algorithms and Data Structures project challenges

{ Object.keys(jsProjects).length === completeCount ?
{ isCertClaimed ? 'Show' : 'Claim'} Certification
: null }
); } } JSAlgoAndDSForm.displayName = 'JSAlgoAndDSForm'; JSAlgoAndDSForm.propTypes = jsFormPropTypes; export default JSAlgoAndDSForm;