fix: add initialValues to the form

This commit is contained in:
Ahmad Abdolsaheb
2019-03-20 16:46:50 +03:00
committed by Mrugesh Mohapatra
parent abf8f2777c
commit 17a2bae5b9

View File

@ -16,7 +16,8 @@ import { projectMap, legacyProjectMap } from '../../resources/certProjectMap';
import SectionHeader from './SectionHeader'; import SectionHeader from './SectionHeader';
import SolutionViewer from './SolutionViewer'; import SolutionViewer from './SolutionViewer';
import { FullWidthRow, Spacer } from '../helpers'; import { FullWidthRow, Spacer } from '../helpers';
// import { Form } from '../formHelpers'; import { Form } from '../formHelpers';
import { maybeUrlRE } from '../../utils'; import { maybeUrlRE } from '../../utils';
import './certification.css'; import './certification.css';
@ -113,6 +114,7 @@ class CertificationSettings extends Component {
super(props); super(props);
this.state = { ...initialState }; this.state = { ...initialState };
this.handleSubmit = this.handleSubmit.bind(this);
} }
createHandleLinkButtonClick = to => e => { createHandleLinkButtonClick = to => e => {
@ -230,9 +232,6 @@ class CertificationSettings extends Component {
); );
renderProjectsFor = (certName, isCert) => { renderProjectsFor = (certName, isCert) => {
console.log(certName);
console.log(this.getUserIsCertMap());
console.log(this.getUserIsCertMap()[certName]);
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}`;
@ -277,30 +276,51 @@ class CertificationSettings extends Component {
]); ]);
}; };
renderLegacyCertifications = certName => ( // legacy projects rendering
handleSubmit() {
console.log('handle');
}
renderLegacyCertifications = certName => {
const challengeTitles = legacyProjectMap[certName].map(item => item.title);
const { completedChallenges } = this.props;
const initialObject = {};
let fullform = 0;
legacyProjectMap[certName].forEach(element => {
let completedProject = find(completedChallenges, function(challenge) {
return challenge['id'] === element['id'];
});
if (!completedProject) {
initialObject[element.title] = '';
} else {
initialObject[element.title] = completedProject.solution;
fullform++;
}
});
console.log(fullform);
return (
<FullWidthRow key={certName}> <FullWidthRow key={certName}>
<Spacer /> <Spacer />
<h3>{certName}</h3> <h3>{certName}</h3>
<Table> <Form
<thead> buttonText={'Claim Certification'}
<tr> formFields={challengeTitles}
<th>Project Name</th> id={certName}
<th>Solution</th> initialValues={{
</tr> ...initialObject
</thead> }}
<tbody> submit={this.handleSubmit}
{this.renderLegacyProjectsFor( />
certName,
this.getUserIsCertMap()[certName]
)}
</tbody>
</Table>
</FullWidthRow> </FullWidthRow>
); );
};
renderLegacyProjectsFor = (certName, isCert) => { renderLegacyProjectsFor = (certName, isCert) => {
console.log(certName);
console.log(this.getUserIsCertMap()[certName]);
const { username, isHonest, createFlashMessage, verifyCert } = this.props; const { username, isHonest, createFlashMessage, verifyCert } = this.props;
const { superBlock } = first(legacyProjectMap[certName]); const { superBlock } = first(legacyProjectMap[certName]);
const certLocation = `/certification/${username}/${superBlock}`; const certLocation = `/certification/${username}/${superBlock}`;
@ -318,6 +338,7 @@ class CertificationSettings extends Component {
'honesty policy' 'honesty policy'
}); });
}; };
return legacyProjectMap[certName] return legacyProjectMap[certName]
.map(({ title, id }) => ( .map(({ title, id }) => (
<tr className='project-row' key={id}> <tr className='project-row' key={id}>