Skip to content

Commit

Permalink
#106 Fix issue with initialValues on edit
Browse files Browse the repository at this point in the history
  • Loading branch information
blms committed Dec 30, 2020
1 parent 72afe57 commit 97aba77
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/components/DocumentForm/DocumentForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,19 @@ const DocumentForm = ({
? useState(deserializeHTMLToDocument({ plugins, element: txtHtml.body }))
: useState(slateInitialValue);

const getInitialValues = (mode === 'edit' && data && (!data.uploadContentType || data.uploadContentType === ''))
? {
...data,
textSlate: deserializeHTMLToDocument({ plugins, element: txtHtml.body }),
let initialValues = {};

if (mode === 'edit' && data) {
if (!data.uploadContentType || data.uploadContentType === '') {
initialValues = {
...data,
textSlate: deserializeHTMLToDocument({ plugins, element: txtHtml.body }),
};
} else {
initialValues = data;
}
: {
} else {
initialValues = {
textSlate: slateInitialValue,
resourceType: 'Book',
rightsStatus: 'Copyrighted',
Expand All @@ -294,6 +301,7 @@ const DocumentForm = ({
groups: [],
state: 'draft',
};
}

const schema = yup.object({
title: yup.string().required('Required'),
Expand Down Expand Up @@ -337,7 +345,7 @@ const DocumentForm = ({
}, 1000);
}}
validationSchema={schema}
initialValues={getInitialValues}
initialValues={initialValues}
enableReinitialize
>
{(props) => (
Expand Down

0 comments on commit 97aba77

Please sign in to comment.