mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 04:11:13 -05:00
Add email secrets
This commit is contained in:
@@ -150,17 +150,41 @@ export function SubmissionReviewManager({
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const { supabase } = await import('@/integrations/supabase/client');
|
||||
const selectedItems = items.filter(item => selectedItemIds.has(item.id));
|
||||
await approveSubmissionItems(selectedItems, user.id);
|
||||
|
||||
// Call the edge function for backend processing
|
||||
const { data, error } = await supabase.functions.invoke('process-selective-approval', {
|
||||
body: {
|
||||
itemIds: Array.from(selectedItemIds),
|
||||
userId: user.id,
|
||||
submissionId
|
||||
}
|
||||
});
|
||||
|
||||
if (error) {
|
||||
throw new Error(error.message || 'Failed to process approval');
|
||||
}
|
||||
|
||||
if (!data?.success) {
|
||||
throw new Error(data?.error || 'Approval processing failed');
|
||||
}
|
||||
|
||||
const successCount = data.results.filter((r: any) => r.success).length;
|
||||
const failCount = data.results.filter((r: any) => !r.success).length;
|
||||
|
||||
toast({
|
||||
title: 'Success',
|
||||
description: `Approved ${selectedItems.length} item(s)`,
|
||||
title: 'Approval Complete',
|
||||
description: failCount > 0
|
||||
? `Approved ${successCount} item(s), ${failCount} failed`
|
||||
: `Successfully approved ${successCount} item(s)`,
|
||||
variant: failCount > 0 ? 'destructive' : 'default',
|
||||
});
|
||||
|
||||
onComplete();
|
||||
onOpenChange(false);
|
||||
} catch (error: any) {
|
||||
console.error('Error approving items:', error);
|
||||
toast({
|
||||
title: 'Error',
|
||||
description: error.message || 'Failed to approve items',
|
||||
@@ -238,16 +262,37 @@ export function SubmissionReviewManager({
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
await escalateSubmission(submissionId, reason, user.id);
|
||||
|
||||
toast({
|
||||
title: 'Escalated',
|
||||
description: 'Submission escalated to admin for review',
|
||||
const { supabase } = await import('@/integrations/supabase/client');
|
||||
|
||||
// Call the escalation notification edge function
|
||||
const { data, error } = await supabase.functions.invoke('send-escalation-notification', {
|
||||
body: {
|
||||
submissionId,
|
||||
escalationReason: reason,
|
||||
escalatedBy: user.id
|
||||
}
|
||||
});
|
||||
|
||||
if (error) {
|
||||
console.error('Edge function error:', error);
|
||||
// Fallback to direct database update if email fails
|
||||
await escalateSubmission(submissionId, reason, user.id);
|
||||
toast({
|
||||
title: 'Escalated (Email Failed)',
|
||||
description: 'Submission escalated but notification email failed to send',
|
||||
variant: 'default',
|
||||
});
|
||||
} else {
|
||||
toast({
|
||||
title: 'Escalated Successfully',
|
||||
description: 'Submission escalated and admin notified via email',
|
||||
});
|
||||
}
|
||||
|
||||
onComplete();
|
||||
onOpenChange(false);
|
||||
} catch (error: any) {
|
||||
console.error('Error escalating submission:', error);
|
||||
toast({
|
||||
title: 'Error',
|
||||
description: error.message || 'Failed to escalate submission',
|
||||
|
||||
Reference in New Issue
Block a user