Skip to content

Commit

Permalink
fix(draft): create new draft if user tries to upload cover
Browse files Browse the repository at this point in the history
  • Loading branch information
robertu7 committed Oct 6, 2023
1 parent 7622a61 commit 56f7893
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/components/Editor/SetCover/Uploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import {
TextIcon,
toast,
Translate,
useCreateDraft,
useMutation,
useRoute,
useUnloadConfirm,
} from '~/components'
import { updateDraftAssets } from '~/components/GQL'
Expand Down Expand Up @@ -76,6 +78,9 @@ const Uploader: React.FC<UploaderProps> = ({
{ showToast: false }
)

const { isInPath } = useRoute()
const { createDraft } = useCreateDraft()

const acceptTypes = ACCEPTED_UPLOAD_IMAGE_TYPES.join(',')
const fieldId = 'editor-cover-upload-form'

Expand All @@ -95,6 +100,16 @@ const Uploader: React.FC<UploaderProps> = ({
}

try {
// create draft if not exist
const isInDraftDetail = isInPath('ME_DRAFT_DETAIL')
if (isInDraftDetail && !entityId) {
await createDraft({
onCreate: (newDraftId) => {
entityId = newDraftId
},
})
}

const variables = {
input: {
file,
Expand Down

0 comments on commit 56f7893

Please sign in to comment.