diff --git a/src/components/moderation/ModerationQueue.tsx b/src/components/moderation/ModerationQueue.tsx index 8f909f13..49060726 100644 --- a/src/components/moderation/ModerationQueue.tsx +++ b/src/components/moderation/ModerationQueue.tsx @@ -383,6 +383,31 @@ export const ModerationQueue = forwardRef((props, ref) => { } }, [activeEntityFilter, activeStatusFilter, user]); + const handleResetToPending = async (item: ModerationItem) => { + setActionLoading(item.id); + try { + const { resetRejectedItemsToPending } = await import('@/lib/submissionItemsService'); + + await resetRejectedItemsToPending(item.id); + + toast({ + title: "Reset Complete", + description: "Submission and all items have been reset to pending status", + }); + + fetchItems(activeEntityFilter, activeStatusFilter); + } catch (error: any) { + console.error('Error resetting submission:', error); + toast({ + title: "Reset Failed", + description: error.message, + variant: "destructive", + }); + } finally { + setActionLoading(null); + } + }; + const handleRetryFailedItems = async (item: ModerationItem) => { setActionLoading(item.id); try { @@ -1536,14 +1561,36 @@ export const ModerationQueue = forwardRef((props, ref) => { )} - {/* Retry button for partially approved items */} + {/* Reset button for rejected items */} + {item.status === 'rejected' && item.type === 'content_submission' && ( +
+
+ +
+

This submission was rejected

+

You can reset it to pending to re-review and approve it.

+
+
+ +
+ )} + + {/* Retry/Reset buttons for partially approved items */} {item.status === 'partially_approved' && item.type === 'content_submission' && (

This submission was partially approved

-

Some items failed to process. Click "Retry Failed Items" to process them again.

+

Some items failed. You can retry them or reset everything to pending.

@@ -1559,13 +1606,22 @@ export const ModerationQueue = forwardRef((props, ref) => { Review Items +
diff --git a/src/lib/submissionItemsService.ts b/src/lib/submissionItemsService.ts index eb0e489a..4e9dc6a2 100644 --- a/src/lib/submissionItemsService.ts +++ b/src/lib/submissionItemsService.ts @@ -733,6 +733,45 @@ function resolveDependencies(data: any, dependencyMap: Map): any return resolved; } +/** + * Reset rejected items back to pending status + */ +export async function resetRejectedItemsToPending( + submissionId: string +): Promise { + // Reset rejected submission items to pending + const { error: itemsError } = await supabase + .from('submission_items') + .update({ + status: 'pending', + rejection_reason: null, + updated_at: new Date().toISOString() + }) + .eq('submission_id', submissionId) + .eq('status', 'rejected'); + + if (itemsError) { + throw new Error(`Failed to reset items: ${itemsError.message}`); + } + + // Reset parent submission to pending + const { error: submissionError } = await supabase + .from('content_submissions') + .update({ + status: 'pending', + reviewed_at: null, + reviewer_id: null, + reviewer_notes: null, + updated_at: new Date().toISOString() + }) + .eq('id', submissionId) + .in('status', ['rejected', 'partially_approved']); + + if (submissionError) { + throw new Error(`Failed to reset submission: ${submissionError.message}`); + } +} + /** * Reject multiple items with optional cascade to dependents */