fix(courses): course cover image not saved on create/edit
The admin course form sent a stray upload id (imageId/uploadId) that didn't match any field the API accepts; the API expects cover_media_id with the media id returned from the upload endpoint. Also switch course displays to the coverUrl field the API actually returns.
This commit is contained in:
@@ -154,7 +154,7 @@ const form = ref({
|
||||
templateId: '',
|
||||
title: '',
|
||||
capacity: '',
|
||||
imageId: null,
|
||||
coverMediaId: null,
|
||||
isActive: false,
|
||||
})
|
||||
|
||||
@@ -212,10 +212,10 @@ watch(existingCourse, (course) => {
|
||||
templateId: '',
|
||||
title: course.title || '',
|
||||
capacity: course.capacity ?? '',
|
||||
imageId: course.imageId || null,
|
||||
coverMediaId: course.coverMediaId || null,
|
||||
isActive: course.isActive ?? false,
|
||||
}
|
||||
if (course.image) image.value = { url: course.image }
|
||||
if (course.coverUrl) image.value = { url: course.coverUrl }
|
||||
})
|
||||
|
||||
const uploadMutation = useUploadMediaMutation()
|
||||
@@ -225,8 +225,8 @@ const onImageCropped = async (file) => {
|
||||
const formData = objectToFormData({ file, purpose: 'cover', context: 'course' })
|
||||
const response = await uploadMutation.mutateAsync(formData)
|
||||
const payload = response?.data ?? response
|
||||
image.value = { url: payload?.url, uploadId: payload?.uploadId, ...payload }
|
||||
form.value.imageId = payload?.uploadId || payload?.id
|
||||
image.value = { url: payload?.url, ...payload }
|
||||
form.value.coverMediaId = payload?.id
|
||||
} catch {
|
||||
/* handled globally */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user