Commit 400b618a authored by Viacheslav Pavlov's avatar Viacheslav Pavlov

New crop isn`t created

parent 7046ee3d
......@@ -47,28 +47,30 @@ class CropEditPage extends React.Component<ICropEditPageProps, any> {
private onSave = async (updatedCrop: any) => {
const { article, createArticle, updateArticle, saveCrop, navigateTo, shortName } = this.props;
const { article: editedArticle } = updatedCrop;
const { id } = this.props.crop;
const id = this.props.crop && this.props.crop.id;
let receivedArticle: Article;
try {
if (article && !_.isEqual(editedArticle, article.body)) {
receivedArticle = await updateArticle({ ...article, ...{ body: editedArticle } }, shortName);
} else if (!article && editedArticle) {
const article = new Article();
article.body = editedArticle;
article.targetId = id;
receivedArticle = await createArticle(article, shortName);
if (id) {
try {
if (article && !_.isEqual(editedArticle, article.body)) {
receivedArticle = await updateArticle({...article, ...{body: editedArticle}}, shortName);
} else if (!article && editedArticle) {
const article = new Article();
article.body = editedArticle;
article.targetId = id;
receivedArticle = await createArticle(article, shortName);
}
if (receivedArticle) {
this.setState({article: receivedArticle});
}
} catch (e) {
return console.log('updating description error', e);
}
if (receivedArticle) {
this.setState({article: receivedArticle});
}
} catch (e) {
return console.log('updating description error', e);
delete updatedCrop.article;
}
delete updatedCrop.article;
saveCrop(updatedCrop)
.then(() => navigateTo(`/c/${updatedCrop.shortName}/edit`));
}
......
......@@ -42,14 +42,16 @@ const CropForm = ({error, handleSubmit, initialValues, onDelete, cropNames, t, l
<h4>{ t('crop.admin.c.cropForm.otherNames') }</h4>
<ItemsEditor name="otherNames" itemLabel={ t('crop.admin.c.cropForm.otherNames') } addItem={ onAddString } removeItem={ onRemoveString } component={ stringField }/>
</div>
<div className="mt-15">
<h4>{ t('crop.admin.c.cropForm.article', {lang}) }</h4>
{initialValues.id && (
<div className="mt-15">
<h4>{t('crop.admin.c.cropForm.article', {lang})}</h4>
<Field
required
name="article"
component={ HtmlEditField }
component={HtmlEditField}
/>
</div>
</div>
) }
<div>{ error && <strong>{ error }</strong> }</div>
<Divider/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment