Commit workspace changes
This commit is contained in:
@@ -348,6 +348,7 @@ export default function useUploadMachine({
|
||||
tags: Array.isArray(metadata.tags) ? metadata.tags.join(', ') : '',
|
||||
license: Boolean(metadata.rightsAccepted),
|
||||
is_mature: Boolean(metadata.isMature),
|
||||
group: String(metadata.group || '').trim() || null,
|
||||
})
|
||||
|
||||
const draftIdCandidate = Number(draftResponse?.data?.artwork_id ?? draftResponse?.data?.id)
|
||||
@@ -515,7 +516,7 @@ export default function useUploadMachine({
|
||||
* handlePublish
|
||||
*
|
||||
* @param {boolean} canPublish
|
||||
* @param {{ mode?: 'now'|'schedule', publishAt?: string|null, timezone?: string, visibility?: string }} [opts]
|
||||
* @param {{ mode?: 'now'|'schedule', publishAt?: string|null, timezone?: string, visibility?: string, action?: 'publish'|'submit_review' }} [opts]
|
||||
*/
|
||||
const handlePublish = useCallback(async (canPublish, opts = {}) => {
|
||||
if (!canPublish || publishLockRef.current) return
|
||||
@@ -523,7 +524,7 @@ export default function useUploadMachine({
|
||||
publishLockRef.current = true
|
||||
dispatchMachine({ type: 'PUBLISH_START' })
|
||||
|
||||
const { mode = 'now', publishAt = null, timezone = null, visibility = 'public' } = opts
|
||||
const { mode = 'now', publishAt = null, timezone = null, visibility = 'public', action = 'publish' } = opts
|
||||
|
||||
const resolvedCategoryId = metadata.subCategoryId || metadata.rootCategoryId || null
|
||||
|
||||
@@ -533,6 +534,23 @@ export default function useUploadMachine({
|
||||
category: resolvedCategoryId ? String(resolvedCategoryId) : null,
|
||||
tags: Array.isArray(metadata.tags) ? metadata.tags : [],
|
||||
is_mature: Boolean(metadata.isMature),
|
||||
group: String(metadata.group || '').trim() || null,
|
||||
primary_author_user_id: metadata.primaryAuthorUserId ? Number(metadata.primaryAuthorUserId) : null,
|
||||
contributor_user_ids: Array.isArray(metadata.contributorUserIds) ? metadata.contributorUserIds.map((id) => Number(id)).filter((id) => Number.isFinite(id) && id > 0) : [],
|
||||
contributor_credits: Array.isArray(metadata.contributorUserIds)
|
||||
? metadata.contributorUserIds
|
||||
.map((id) => Number(id))
|
||||
.filter((id) => Number.isFinite(id) && id > 0)
|
||||
.map((id) => {
|
||||
const creditMeta = metadata.contributorCredits?.[id] || metadata.contributorCredits?.[String(id)] || {}
|
||||
|
||||
return {
|
||||
user_id: id,
|
||||
credit_role: typeof creditMeta.creditRole === 'string' && creditMeta.creditRole.trim() !== '' ? creditMeta.creditRole.trim() : null,
|
||||
is_primary: Boolean(creditMeta.isPrimary),
|
||||
}
|
||||
})
|
||||
: [],
|
||||
mode,
|
||||
...(mode === 'schedule' && publishAt ? { publish_at: publishAt } : {}),
|
||||
...(timezone ? { timezone } : {}),
|
||||
@@ -546,7 +564,9 @@ export default function useUploadMachine({
|
||||
if (resolvedArtworkIdRef.current && resolvedArtworkIdRef.current > 0) {
|
||||
const publishController = registerController()
|
||||
const publishRes = await window.axios.post(
|
||||
uploadEndpoints.publish(String(resolvedArtworkIdRef.current)),
|
||||
action === 'submit_review'
|
||||
? uploadEndpoints.submitReview(String(resolvedArtworkIdRef.current))
|
||||
: uploadEndpoints.publish(String(resolvedArtworkIdRef.current)),
|
||||
buildPayload(),
|
||||
{ signal: publishController.signal }
|
||||
)
|
||||
@@ -555,9 +575,13 @@ export default function useUploadMachine({
|
||||
dispatchMachine({ type: mode === 'schedule' ? 'SCHEDULED' : 'PUBLISH_SUCCESS', slug: publishedSlug })
|
||||
onNotice?.(mapUploadResultNotice(publishRes?.data || {}, {
|
||||
fallbackType: 'success',
|
||||
fallbackMessage: mode === 'schedule' ? 'Artwork scheduled successfully.' : 'Artwork published successfully.',
|
||||
fallbackMessage: action === 'submit_review'
|
||||
? 'Artwork submitted for group review.'
|
||||
: mode === 'schedule'
|
||||
? 'Artwork scheduled successfully.'
|
||||
: 'Artwork published successfully.',
|
||||
}))
|
||||
emitUploadEvent('upload_publish', { id: publishTargetId, mode })
|
||||
emitUploadEvent(action === 'submit_review' ? 'upload_submit_review' : 'upload_publish', { id: publishTargetId, mode })
|
||||
return
|
||||
}
|
||||
|
||||
@@ -565,7 +589,9 @@ export default function useUploadMachine({
|
||||
|
||||
const publishController = registerController()
|
||||
const publishRes2 = await window.axios.post(
|
||||
uploadEndpoints.publish(publishTargetId),
|
||||
action === 'submit_review'
|
||||
? uploadEndpoints.submitReview(publishTargetId)
|
||||
: uploadEndpoints.publish(publishTargetId),
|
||||
buildPayload(),
|
||||
{ signal: publishController.signal }
|
||||
)
|
||||
@@ -574,9 +600,13 @@ export default function useUploadMachine({
|
||||
dispatchMachine({ type: mode === 'schedule' ? 'SCHEDULED' : 'PUBLISH_SUCCESS', slug: publishedSlug2 })
|
||||
onNotice?.(mapUploadResultNotice(publishRes2?.data || {}, {
|
||||
fallbackType: 'success',
|
||||
fallbackMessage: mode === 'schedule' ? 'Artwork scheduled successfully.' : 'Artwork published successfully.',
|
||||
fallbackMessage: action === 'submit_review'
|
||||
? 'Artwork submitted for group review.'
|
||||
: mode === 'schedule'
|
||||
? 'Artwork scheduled successfully.'
|
||||
: 'Artwork published successfully.',
|
||||
}))
|
||||
emitUploadEvent('upload_publish', { id: publishTargetId, mode })
|
||||
emitUploadEvent(action === 'submit_review' ? 'upload_submit_review' : 'upload_publish', { id: publishTargetId, mode })
|
||||
} catch (error) {
|
||||
if (error?.name === 'CanceledError' || error?.code === 'ERR_CANCELED') return
|
||||
const notice = mapUploadErrorNotice(error, 'Publish failed.')
|
||||
|
||||
Reference in New Issue
Block a user