mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 18:31:13 -05:00
Add functionality to approve or reject submitted items
Introduces a new `handleItemStatusChange` function to `SubmissionReviewManager` to handle item approvals and rejections, invoking Supabase functions for processing and updating item statuses. Replit-Commit-Author: Agent Replit-Commit-Session-Id: f44f1d1b-1dd8-407b-8603-db12902e1a15 Replit-Commit-Checkpoint-Type: intermediate_checkpoint
This commit is contained in:
@@ -314,6 +314,63 @@ export function SubmissionReviewManager({
|
||||
await loadSubmissionItems();
|
||||
};
|
||||
|
||||
const handleItemStatusChange = async (itemId: string, status: 'approved' | 'rejected') => {
|
||||
if (!user?.id) {
|
||||
toast({
|
||||
title: 'Authentication Required',
|
||||
description: 'You must be logged in to change item status',
|
||||
variant: 'destructive',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
if (status === 'approved') {
|
||||
const { supabase } = await import('@/integrations/supabase/client');
|
||||
const { data, error } = await supabase.functions.invoke('process-selective-approval', {
|
||||
body: {
|
||||
itemIds: [itemId],
|
||||
userId: user.id,
|
||||
submissionId
|
||||
}
|
||||
});
|
||||
|
||||
if (error || !data?.success) {
|
||||
throw new Error(error?.message || data?.error || 'Failed to approve item');
|
||||
}
|
||||
|
||||
toast({
|
||||
title: 'Item Approved',
|
||||
description: 'Successfully approved the item',
|
||||
});
|
||||
} else {
|
||||
const item = items.find(i => i.id === itemId);
|
||||
if (!item) {
|
||||
throw new Error('Item not found');
|
||||
}
|
||||
|
||||
await rejectSubmissionItems([item], 'Quick rejection from review', user.id, false);
|
||||
|
||||
toast({
|
||||
title: 'Item Rejected',
|
||||
description: 'Successfully rejected the item',
|
||||
});
|
||||
}
|
||||
|
||||
await loadSubmissionItems();
|
||||
} catch (error: any) {
|
||||
console.error('Error changing item status:', error);
|
||||
toast({
|
||||
title: 'Error',
|
||||
description: error.message || 'Failed to change item status',
|
||||
variant: 'destructive',
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const pendingCount = items.filter(item => item.status === 'pending').length;
|
||||
const selectedCount = selectedItemIds.size;
|
||||
|
||||
@@ -416,7 +473,7 @@ export function SubmissionReviewManager({
|
||||
<ItemReviewCard
|
||||
item={item}
|
||||
onEdit={() => handleEdit(item)}
|
||||
onStatusChange={(status) => {/* TODO: Update status */}}
|
||||
onStatusChange={(status) => handleItemStatusChange(item.id, status)}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
|
||||
Reference in New Issue
Block a user