Skip to content

Commit

Permalink
Merge pull request #130 from mitaai/blms/edit-docs
Browse files Browse the repository at this point in the history
#126 Edit docx/odt uploads
  • Loading branch information
blms authored Jan 7, 2021
2 parents 7ba09dd + f009ec2 commit 0d5d1db
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/components/DocumentForm/DocumentForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ const DocumentForm = ({
const { id, slug, uploadContentType } = data;
const patchUrl = `/api/document/${id}`;
const { text, ...rest } = values;
const valuesWithSerializedText = (uploadContentType && uploadContentType !== '')
const valuesWithSerializedText = (uploadContentType && (data.uploadContentType.includes('pdf') && data.uploadContentType.includes('epub')))
? rest
: {
...values,
Expand Down Expand Up @@ -282,14 +282,16 @@ const DocumentForm = ({
type: DEFAULTS_PARAGRAPH.p.type,
},
];
const [slateValue, setSlateValue] = (mode === 'edit' && data && (!data.uploadContentType || data.uploadContentType === ''))
const [slateValue, setSlateValue] = (mode === 'edit' && data && (!data.uploadContentType
|| (!data.uploadContentType.includes('pdf') && !data.uploadContentType.includes('epub'))))
? useState(deserializeHTMLToDocument({ plugins, element: txtHtml.body }))
: useState(slateInitialValue);

let initialValues = {};

if (mode === 'edit' && data) {
if (!data.uploadContentType || data.uploadContentType === '') {
if (!data.uploadContentType
|| (!data.uploadContentType.includes('pdf') && !data.uploadContentType.includes('epub'))) {
initialValues = {
...data,
textSlate: deserializeHTMLToDocument({ plugins, element: txtHtml.body }),
Expand Down Expand Up @@ -362,7 +364,9 @@ const DocumentForm = ({
{(props) => (
<Form onSubmit={props.handleSubmit} noValidate className="pt-2">
{(!data
|| (data && data.state === 'draft' && (!data.uploadContentType || data.uploadContentType === ''))
|| (data && data.state === 'draft' && (!data.uploadContentType
|| (!data.uploadContentType.includes('pdf') && !data.uploadContentType.includes('epub')))
)
) && (
<Form.Row>
<Col>
Expand Down

0 comments on commit 0d5d1db

Please sign in to comment.