...
 
Commits (2)
...@@ -47,28 +47,30 @@ class CropEditPage extends React.Component<ICropEditPageProps, any> { ...@@ -47,28 +47,30 @@ class CropEditPage extends React.Component<ICropEditPageProps, any> {
private onSave = async (updatedCrop: any) => { private onSave = async (updatedCrop: any) => {
const { article, createArticle, updateArticle, saveCrop, navigateTo, shortName } = this.props; const { article, createArticle, updateArticle, saveCrop, navigateTo, shortName } = this.props;
const { article: editedArticle } = updatedCrop; const { article: editedArticle } = updatedCrop;
const { id } = this.props.crop; const id = this.props.crop && this.props.crop.id;
let receivedArticle: Article; let receivedArticle: Article;
try { if (id) {
if (article && !_.isEqual(editedArticle, article.body)) { try {
receivedArticle = await updateArticle({ ...article, ...{ body: editedArticle } }, shortName); if (article && !_.isEqual(editedArticle, article.body)) {
} else if (!article && editedArticle) { receivedArticle = await updateArticle({...article, ...{body: editedArticle}}, shortName);
const article = new Article(); } else if (!article && editedArticle) {
article.body = editedArticle; const article = new Article();
article.targetId = id; article.body = editedArticle;
receivedArticle = await createArticle(article, shortName); 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) { delete updatedCrop.article;
this.setState({article: receivedArticle});
}
} catch (e) {
return console.log('updating description error', e);
} }
delete updatedCrop.article;
saveCrop(updatedCrop) saveCrop(updatedCrop)
.then(() => navigateTo(`/c/${updatedCrop.shortName}/edit`)); .then(() => navigateTo(`/c/${updatedCrop.shortName}/edit`));
} }
......
...@@ -42,14 +42,16 @@ const CropForm = ({error, handleSubmit, initialValues, onDelete, cropNames, t, l ...@@ -42,14 +42,16 @@ const CropForm = ({error, handleSubmit, initialValues, onDelete, cropNames, t, l
<h4>{ t('crop.admin.c.cropForm.otherNames') }</h4> <h4>{ t('crop.admin.c.cropForm.otherNames') }</h4>
<ItemsEditor name="otherNames" itemLabel={ t('crop.admin.c.cropForm.otherNames') } addItem={ onAddString } removeItem={ onRemoveString } component={ stringField }/> <ItemsEditor name="otherNames" itemLabel={ t('crop.admin.c.cropForm.otherNames') } addItem={ onAddString } removeItem={ onRemoveString } component={ stringField }/>
</div> </div>
<div className="mt-15"> {initialValues.id && (
<h4>{ t('crop.admin.c.cropForm.article', {lang}) }</h4> <div className="mt-15">
<h4>{t('crop.admin.c.cropForm.article', {lang})}</h4>
<Field <Field
required required
name="article" name="article"
component={ HtmlEditField } component={HtmlEditField}
/> />
</div> </div>
) }
<div>{ error && <strong>{ error }</strong> }</div> <div>{ error && <strong>{ error }</strong> }</div>
<Divider/> <Divider/>
......