Fix order_created email by waiting for send-notification before navigation
The early termination issue was caused by the page navigating away before the send-notification function call could complete. Changed from fire-and-forget to awaiting the email send result before redirecting. Changes: - Checkout.tsx: Changed send-notification call to use await instead of .then()/.catch() - Now waits for email send to complete before navigating to order detail page - Email failures are caught in try/catch but navigation still proceeds Technical details: - Browser was terminating pending requests when navigate() was called immediately - Early termination: isolate warning indicated function was being killed mid-execution - Awaiting the function call ensures it completes before page navigation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -116,12 +116,13 @@ export default function Checkout() {
|
|||||||
throw new Error(paymentError.message || 'Gagal membuat pembayaran');
|
throw new Error(paymentError.message || 'Gagal membuat pembayaran');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send order_created email with QR code (non-blocking, fire-and-forget)
|
// Send order_created email with QR code (wait for completion before navigating)
|
||||||
console.log('[CHECKOUT] About to send order_created email for order:', order.id);
|
console.log('[CHECKOUT] About to send order_created email for order:', order.id);
|
||||||
console.log('[CHECKOUT] User email:', user.email);
|
console.log('[CHECKOUT] User email:', user.email);
|
||||||
console.log('[CHECKOUT] Payment data QR string:', paymentData?.qr_string);
|
console.log('[CHECKOUT] Payment data QR string:', paymentData?.qr_string);
|
||||||
|
|
||||||
supabase.functions.invoke('send-notification', {
|
try {
|
||||||
|
const result = await supabase.functions.invoke('send-notification', {
|
||||||
body: {
|
body: {
|
||||||
template_key: 'order_created',
|
template_key: 'order_created',
|
||||||
recipient_email: user.email,
|
recipient_email: user.email,
|
||||||
@@ -144,15 +145,14 @@ export default function Checkout() {
|
|||||||
qr_expiry_time: paymentData?.expired_at ? new Date(paymentData.expired_at).toLocaleString('id-ID') : ''
|
qr_expiry_time: paymentData?.expired_at ? new Date(paymentData.expired_at).toLocaleString('id-ID') : ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).then(result => {
|
|
||||||
console.log('[CHECKOUT] send-notification called successfully:', result);
|
|
||||||
}).catch(err => {
|
|
||||||
console.error('[CHECKOUT] Failed to send order_created email:', err);
|
|
||||||
console.error('[CHECKOUT] Error details:', JSON.stringify(err));
|
|
||||||
// Don't block checkout flow if email fails
|
|
||||||
});
|
});
|
||||||
|
console.log('[CHECKOUT] send-notification called successfully:', result);
|
||||||
|
} catch (emailErr) {
|
||||||
|
console.error('[CHECKOUT] Failed to send order_created email:', emailErr);
|
||||||
|
// Don't block checkout flow if email fails
|
||||||
|
}
|
||||||
|
|
||||||
console.log('[CHECKOUT] Order creation email call initiated');
|
console.log('[CHECKOUT] Order creation email call completed');
|
||||||
|
|
||||||
// Clear cart and redirect to order detail page to show QR code
|
// Clear cart and redirect to order detail page to show QR code
|
||||||
clearCart();
|
clearCart();
|
||||||
|
|||||||
Reference in New Issue
Block a user