Merge pull request #295 from R0m1k3/1.1

Streamline invoice sending by removing document type selection
This commit is contained in:
LogiFlow authored and GitHub committed 2025-08-22 12:12:06 +02:00
commit e8d92fbc11
1 file changed
+7 -23
+7 -23
View File
@@ -54,7 +54,6 @@ export default function BLReconciliation() {
// État pour le modal d'envoi de facture // État pour le modal d'envoi de facture
const [showInvoiceModal, setShowInvoiceModal] = useState(false); const [showInvoiceModal, setShowInvoiceModal] = useState(false);
const [selectedDeliveryForInvoice, setSelectedDeliveryForInvoice] = useState<any>(null); const [selectedDeliveryForInvoice, setSelectedDeliveryForInvoice] = useState<any>(null);
const [invoiceType, setInvoiceType] = useState<string>("");
const [selectedFile, setSelectedFile] = useState<File | null>(null); const [selectedFile, setSelectedFile] = useState<File | null>(null);
const [isUploading, setIsUploading] = useState(false); const [isUploading, setIsUploading] = useState(false);
@@ -305,7 +304,6 @@ export default function BLReconciliation() {
// Nouvelles fonctions pour le modal d'envoi de facture // Nouvelles fonctions pour le modal d'envoi de facture
const handleOpenInvoiceModal = (delivery: any) => { const handleOpenInvoiceModal = (delivery: any) => {
setSelectedDeliveryForInvoice(delivery); setSelectedDeliveryForInvoice(delivery);
setInvoiceType("");
setSelectedFile(null); setSelectedFile(null);
setShowInvoiceModal(true); setShowInvoiceModal(true);
}; };
@@ -313,7 +311,6 @@ export default function BLReconciliation() {
const handleCloseInvoiceModal = () => { const handleCloseInvoiceModal = () => {
setShowInvoiceModal(false); setShowInvoiceModal(false);
setSelectedDeliveryForInvoice(null); setSelectedDeliveryForInvoice(null);
setInvoiceType("");
setSelectedFile(null); setSelectedFile(null);
setIsUploading(false); setIsUploading(false);
}; };
@@ -332,10 +329,10 @@ export default function BLReconciliation() {
}; };
const handleSendInvoice = async () => { const handleSendInvoice = async () => {
if (!selectedDeliveryForInvoice || !invoiceType || !selectedFile) { if (!selectedDeliveryForInvoice || !selectedFile) {
toast({ toast({
title: "Erreur", title: "Erreur",
description: "Veuillez remplir tous les champs", description: "Veuillez sélectionner un fichier PDF",
variant: "destructive", variant: "destructive",
}); });
return; return;
@@ -357,7 +354,7 @@ export default function BLReconciliation() {
formData.append('file', selectedFile); formData.append('file', selectedFile);
formData.append('supplier', selectedDeliveryForInvoice.supplier?.name || ''); formData.append('supplier', selectedDeliveryForInvoice.supplier?.name || '');
formData.append('blNumber', selectedDeliveryForInvoice.blNumber || ''); formData.append('blNumber', selectedDeliveryForInvoice.blNumber || '');
formData.append('type', invoiceType); formData.append('type', 'Facture');
const response = await fetch(selectedDeliveryForInvoice.group.webhookUrl, { const response = await fetch(selectedDeliveryForInvoice.group.webhookUrl, {
method: 'POST', method: 'POST',
@@ -370,14 +367,14 @@ export default function BLReconciliation() {
toast({ toast({
title: "Succès", title: "Succès",
description: `${invoiceType} envoyée avec succès via le webhook`, description: "Facture envoyée avec succès via le webhook",
}); });
handleCloseInvoiceModal(); handleCloseInvoiceModal();
} catch (error: any) { } catch (error: any) {
toast({ toast({
title: "Erreur", title: "Erreur",
description: `Impossible d'envoyer la ${invoiceType.toLowerCase()}: ${error.message}`, description: `Impossible d'envoyer la facture: ${error.message}`,
variant: "destructive", variant: "destructive",
}); });
} finally { } finally {
@@ -1087,7 +1084,7 @@ export default function BLReconciliation() {
<Dialog open={showInvoiceModal} onOpenChange={setShowInvoiceModal}> <Dialog open={showInvoiceModal} onOpenChange={setShowInvoiceModal}>
<DialogContent className="sm:max-w-[425px]"> <DialogContent className="sm:max-w-[425px]">
<DialogHeader> <DialogHeader>
<DialogTitle>Envoyer Facture/Avoir</DialogTitle> <DialogTitle>Envoyer Facture</DialogTitle>
</DialogHeader> </DialogHeader>
<div className="grid gap-4 py-4"> <div className="grid gap-4 py-4">
{selectedDeliveryForInvoice && ( {selectedDeliveryForInvoice && (
@@ -1104,19 +1101,6 @@ export default function BLReconciliation() {
</div> </div>
)} )}
<div className="grid gap-2">
<Label htmlFor="invoice-type">Type de document</Label>
<Select value={invoiceType} onValueChange={setInvoiceType}>
<SelectTrigger>
<SelectValue placeholder="Sélectionnez le type" />
</SelectTrigger>
<SelectContent>
<SelectItem value="Facture">Facture</SelectItem>
<SelectItem value="Avoir">Avoir</SelectItem>
</SelectContent>
</Select>
</div>
<div className="grid gap-2"> <div className="grid gap-2">
<Label htmlFor="pdf-file">Fichier PDF</Label> <Label htmlFor="pdf-file">Fichier PDF</Label>
<input <input
@@ -1146,7 +1130,7 @@ export default function BLReconciliation() {
</Button> </Button>
<Button <Button
onClick={handleSendInvoice} onClick={handleSendInvoice}
disabled={!invoiceType || !selectedFile || isUploading} disabled={!selectedFile || isUploading}
> >
{isUploading ? "Envoi..." : "Envoyer"} {isUploading ? "Envoi..." : "Envoyer"}
</Button> </Button>