fix: funcitonal certification button added

This commit is contained in:
Ahmad Abdolsaheb
2019-03-21 11:53:21 +03:00
committed by Mrugesh Mohapatra
parent 17a2bae5b9
commit a45a61fb47

View File

@ -232,6 +232,7 @@ class CertificationSettings extends Component {
); );
renderProjectsFor = (certName, isCert) => { renderProjectsFor = (certName, isCert) => {
console.log(isCert);
const { username, isHonest, createFlashMessage, verifyCert } = this.props; const { username, isHonest, createFlashMessage, verifyCert } = this.props;
const { superBlock } = first(projectMap[certName]); const { superBlock } = first(projectMap[certName]);
const certLocation = `/certification/${username}/${superBlock}`; const certLocation = `/certification/${username}/${superBlock}`;
@ -278,55 +279,36 @@ class CertificationSettings extends Component {
// legacy projects rendering // legacy projects rendering
handleSubmit() { handleSubmit(values) {
console.log('handle'); console.log(values);
} }
renderLegacyCertifications = certName => { renderLegacyCertifications = certName => {
const { username, isHonest, createFlashMessage, verifyCert } = this.props;
const { superBlock } = first(legacyProjectMap[certName]);
const certLocation = `/certification/${username}/${superBlock}`;
const challengeTitles = legacyProjectMap[certName].map(item => item.title); const challengeTitles = legacyProjectMap[certName].map(item => item.title);
const { completedChallenges } = this.props; const { completedChallenges } = this.props;
const isCertClaimed = this.getUserIsCertMap()[certName];
const initialObject = {}; const initialObject = {};
let fullform = 0; let filledforms = 0;
legacyProjectMap[certName].forEach(element => { legacyProjectMap[certName].forEach(element => {
let completedProject = find(completedChallenges, function(challenge) { let completedProject = find(completedChallenges, function(challenge) {
return challenge['id'] === element['id']; return challenge['id'] === element['id'];
}); });
if (!completedProject) { if (!completedProject) {
initialObject[element.title] = ''; initialObject[element.title] = '';
} else { } else {
initialObject[element.title] = completedProject.solution; initialObject[element.title] = completedProject.solution;
fullform++; filledforms++;
} }
}); });
console.log(fullform); const fullForm = filledforms === challengeTitles.length;
return (
<FullWidthRow key={certName}>
<Spacer />
<h3>{certName}</h3>
<Form
buttonText={'Claim Certification'}
formFields={challengeTitles}
id={certName}
initialValues={{
...initialObject
}}
submit={this.handleSubmit}
/>
</FullWidthRow>
);
};
renderLegacyProjectsFor = (certName, isCert) => {
const { username, isHonest, createFlashMessage, verifyCert } = this.props;
const { superBlock } = first(legacyProjectMap[certName]);
const certLocation = `/certification/${username}/${superBlock}`;
const createClickHandler = superBlock => e => { const createClickHandler = superBlock => e => {
e.preventDefault(); e.preventDefault();
if (isCert) { if (isCertClaimed) {
return navigate(certLocation); return navigate(certLocation);
} }
return isHonest return isHonest
@ -339,123 +321,45 @@ class CertificationSettings extends Component {
}); });
}; };
return legacyProjectMap[certName] const buttonStyle = {
.map(({ title, id }) => ( marginBottom: '1.45rem'
<tr className='project-row' key={id}> };
<td className='project-title col-sm-8'>
<h3>{title}</h3> return (
</td> <FullWidthRow key={certName}>
<td className='project-solution col-sm-4'> <Spacer />
{this.getLegacyProjectSolution(id, title)} <h3>{certName}</h3>
</td> <Form
</tr> buttonText={fullForm ? 'Claim Certification' : 'Save Progress'}
)) enableSubmit={fullForm}
.concat([ formFields={challengeTitles}
<tr key={`cert-${superBlock}-button`}> hideButton={isCertClaimed}
<td colSpan={2}> id={certName}
initialValues={{
...initialObject
}}
submit={this.handleSubmit}
/>
{isCertClaimed ? (
<div className={'col-xs-12'}>
<Button <Button
block={true} bsSize='sm'
bsStyle='primary' bsStyle='primary'
className={'col-xs-12'}
href={certLocation} href={certLocation}
onClick={createClickHandler(superBlock)} onClick={createClickHandler(superBlock)}
style={buttonStyle}
target='_blank'
> >
{isCert ? 'Show Certification' : 'Claim Certification'} Show Certification
</Button> </Button>
</td> </div>
</tr> ) : null}
]); </FullWidthRow>
};
getLegacyProjectSolution = (projectId, projectTitle) => {
const { completedChallenges } = this.props;
const completedProject = find(
completedChallenges,
({ id }) => projectId === id
);
if (!completedProject) {
return null;
}
const { solution, githubLink, files } = completedProject;
const onClickHandler = () =>
this.setState({
solutionViewer: {
projectTitle,
files,
solution,
isOpen: true
}
});
if (files && files.length) {
return (
<Button
block={true}
bsStyle='primary'
className='btn-invert'
onClick={onClickHandler}
>
Show Code
</Button>
);
}
if (githubLink) {
return (
<div className='solutions-dropdown'>
<DropdownButton
block={true}
bsStyle='primary'
className='btn-invert'
id={`dropdown-for-${projectId}`}
title='Show Solutions'
>
<MenuItem
bsStyle='primary'
href={solution}
rel='noopener noreferrer'
target='_blank'
>
Front End
</MenuItem>
<MenuItem
bsStyle='primary'
href={githubLink}
rel='noopener noreferrer'
target='_blank'
>
Back End
</MenuItem>
</DropdownButton>
</div>
);
}
if (maybeUrlRE.test(solution)) {
return (
<Button
block={true}
bsStyle='primary'
className='btn-invert'
href={solution}
rel='noopener noreferrer'
target='_blank'
>
Show Solution
</Button>
);
}
return (
<Button
block={true}
bsStyle='primary'
className='btn-invert'
onClick={onClickHandler}
>
Show Code
</Button>
); );
}; };
render() { render() {
// console.log(this.props.completedChallenges);
// console.log(getUserIsCertMap);
const { const {
solutionViewer: { files, solution, isOpen, projectTitle } solutionViewer: { files, solution, isOpen, projectTitle }
} = this.state; } = this.state;