fix: funcitonal certification button added
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
17a2bae5b9
commit
a45a61fb47
@ -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>
|
|
||||||
</td>
|
|
||||||
<td className='project-solution col-sm-4'>
|
|
||||||
{this.getLegacyProjectSolution(id, title)}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
))
|
|
||||||
.concat([
|
|
||||||
<tr key={`cert-${superBlock}-button`}>
|
|
||||||
<td colSpan={2}>
|
|
||||||
<Button
|
|
||||||
block={true}
|
|
||||||
bsStyle='primary'
|
|
||||||
href={certLocation}
|
|
||||||
onClick={createClickHandler(superBlock)}
|
|
||||||
>
|
|
||||||
{isCert ? 'Show Certification' : 'Claim Certification'}
|
|
||||||
</Button>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
]);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
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 (
|
return (
|
||||||
|
<FullWidthRow key={certName}>
|
||||||
|
<Spacer />
|
||||||
|
<h3>{certName}</h3>
|
||||||
|
<Form
|
||||||
|
buttonText={fullForm ? 'Claim Certification' : 'Save Progress'}
|
||||||
|
enableSubmit={fullForm}
|
||||||
|
formFields={challengeTitles}
|
||||||
|
hideButton={isCertClaimed}
|
||||||
|
id={certName}
|
||||||
|
initialValues={{
|
||||||
|
...initialObject
|
||||||
|
}}
|
||||||
|
submit={this.handleSubmit}
|
||||||
|
/>
|
||||||
|
{isCertClaimed ? (
|
||||||
|
<div className={'col-xs-12'}>
|
||||||
<Button
|
<Button
|
||||||
block={true}
|
bsSize='sm'
|
||||||
bsStyle='primary'
|
bsStyle='primary'
|
||||||
className='btn-invert'
|
className={'col-xs-12'}
|
||||||
onClick={onClickHandler}
|
href={certLocation}
|
||||||
|
onClick={createClickHandler(superBlock)}
|
||||||
|
style={buttonStyle}
|
||||||
|
target='_blank'
|
||||||
>
|
>
|
||||||
Show Code
|
Show Certification
|
||||||
</Button>
|
</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>
|
</div>
|
||||||
);
|
) : null}
|
||||||
}
|
</FullWidthRow>
|
||||||
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;
|
||||||
|
Reference in New Issue
Block a user