Update invoice sending to use direct webhook requests with timeouts

Refactors BLReconciliation.tsx to replace the backend proxy call with a direct fetch to the webhook URL, implementing FormData for file uploads and adding a 60-second timeout using AbortController.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 1e4433b5-47ab-464c-b663-fea2e53367dd
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: 4d220e6b-5c4b-4c79-badc-e764c86cbe43
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/1e4433b5-47ab-464c-b663-fea2e53367dd/qOJ89TE
This commit is contained in:
michaelschal committed 2025-11-04 15:12:48 +00:00
1 parent fb6c06d150
commit 4dffada355
3 files changed
+17 -28

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

+17 -28
View File
@@ -513,37 +513,26 @@ export default function BLReconciliation() {
startProcessingTimer();
try {
// Convertir le fichier en base64 pour l'envoyer via notre route backend
const fileBase64 = await new Promise<string>((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => {
const base64 = (reader.result as string).split(',')[1]; // Retirer le préfixe data:...
resolve(base64);
};
reader.onerror = reject;
reader.readAsDataURL(selectedFile);
const formData = new FormData();
formData.append('file', selectedFile);
formData.append('supplier', selectedDeliveryForInvoice.supplier?.name || '');
formData.append('blNumber', selectedDeliveryForInvoice.blNumber || '');
formData.append('type', 'Facture');
// Créer un AbortController pour gérer le timeout
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 60000); // 60 secondes
const response = await fetch(selectedDeliveryForInvoice.group.webhookUrl, {
method: 'POST',
body: formData,
signal: controller.signal,
});
// Préparer les données pour la route backend proxy
const payload = {
webhookUrl: selectedDeliveryForInvoice.group.webhookUrl,
formDataFields: {
file: {
base64: fileBase64,
filename: selectedFile.name,
contentType: selectedFile.type
},
supplier: selectedDeliveryForInvoice.supplier?.name || '',
blNumber: selectedDeliveryForInvoice.blNumber || '',
type: 'Facture'
}
};
clearTimeout(timeoutId);
// Envoyer via la route backend proxy (évite les problèmes CORS)
const response = await apiRequest('/api/reconciliation/send-invoice-webhook', 'POST', payload);
if (!response || !response.success) {
throw new Error(response?.error || 'Erreur lors de l\'envoi');
if (!response.ok) {
throw new Error(`Erreur ${response.status}: ${response.statusText}`);
}
handleCloseWaitingModal();