mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-22 22:48:15 +02:00
Update reconciliation module to use new comment system
Replaces the old 'note' table usage with the 'ReconciliationComments' component and associated mutation logic in the BLReconciliation page. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 95e8aab4-f39f-4b48-aa57-a759ec15ba3d Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/95e8aab4-f39f-4b48-aa57-a759ec15ba3d/2QB13hj
This commit is contained in:
1 parent
fdebcbba26
commit
d2f2a532a5
1 file changed
+14
-87
@@ -17,6 +17,7 @@ import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "
|
|||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { Textarea } from "@/components/ui/textarea";
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
|
import ReconciliationComments from "@/components/ReconciliationComments";
|
||||||
import ReconciliationModal from "@/components/modals/ReconciliationModal";
|
import ReconciliationModal from "@/components/modals/ReconciliationModal";
|
||||||
|
|
||||||
export default function BLReconciliation() {
|
export default function BLReconciliation() {
|
||||||
@@ -70,7 +71,6 @@ export default function BLReconciliation() {
|
|||||||
// État pour le modal de commentaire
|
// État pour le modal de commentaire
|
||||||
const [showCommentModal, setShowCommentModal] = useState(false);
|
const [showCommentModal, setShowCommentModal] = useState(false);
|
||||||
const [selectedDeliveryForComment, setSelectedDeliveryForComment] = useState<any>(null);
|
const [selectedDeliveryForComment, setSelectedDeliveryForComment] = useState<any>(null);
|
||||||
const [commentText, setCommentText] = useState("");
|
|
||||||
|
|
||||||
// Récupérer les fournisseurs pour la logique automatique
|
// Récupérer les fournisseurs pour la logique automatique
|
||||||
const { data: suppliers = [] } = useQuery<any[]>({
|
const { data: suppliers = [] } = useQuery<any[]>({
|
||||||
@@ -143,43 +143,6 @@ export default function BLReconciliation() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Mutation pour créer un nouveau commentaire de rapprochement
|
|
||||||
const createCommentMutation = useMutation({
|
|
||||||
mutationFn: async ({ deliveryId, content }: { deliveryId: number; content: string }) => {
|
|
||||||
const response = await apiRequest(`/api/deliveries/${deliveryId}/reconciliation-comments`, 'POST', {
|
|
||||||
content
|
|
||||||
});
|
|
||||||
return response;
|
|
||||||
},
|
|
||||||
onSuccess: () => {
|
|
||||||
toast({
|
|
||||||
title: "Commentaire ajouté",
|
|
||||||
description: "Le commentaire a été ajouté avec succès",
|
|
||||||
});
|
|
||||||
// Rafraîchir les données
|
|
||||||
queryClient.invalidateQueries({ queryKey: ['/api/deliveries/bl'] });
|
|
||||||
queryClient.invalidateQueries({ queryKey: ['/api/deliveries'] });
|
|
||||||
handleCloseCommentModal();
|
|
||||||
},
|
|
||||||
onError: (error) => {
|
|
||||||
console.error('Erreur ajout commentaire:', error);
|
|
||||||
toast({
|
|
||||||
title: "Erreur",
|
|
||||||
description: "Impossible d'ajouter le commentaire",
|
|
||||||
variant: "destructive",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Fonction pour sauvegarder le commentaire
|
|
||||||
const handleSaveComment = () => {
|
|
||||||
if (!selectedDeliveryForComment || !commentText.trim()) return;
|
|
||||||
|
|
||||||
createCommentMutation.mutate({
|
|
||||||
deliveryId: selectedDeliveryForComment.id,
|
|
||||||
content: commentText
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Fonction pour déclencher la vérification
|
// Fonction pour déclencher la vérification
|
||||||
const handleVerifyInvoice = (delivery: any, forceRefresh: boolean = false) => {
|
const handleVerifyInvoice = (delivery: any, forceRefresh: boolean = false) => {
|
||||||
@@ -394,14 +357,12 @@ export default function BLReconciliation() {
|
|||||||
// Fonctions pour le modal de commentaire
|
// Fonctions pour le modal de commentaire
|
||||||
const handleOpenCommentModal = (delivery: any) => {
|
const handleOpenCommentModal = (delivery: any) => {
|
||||||
setSelectedDeliveryForComment(delivery);
|
setSelectedDeliveryForComment(delivery);
|
||||||
setCommentText(delivery.notes || "");
|
|
||||||
setShowCommentModal(true);
|
setShowCommentModal(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCloseCommentModal = () => {
|
const handleCloseCommentModal = () => {
|
||||||
setShowCommentModal(false);
|
setShowCommentModal(false);
|
||||||
setSelectedDeliveryForComment(null);
|
setSelectedDeliveryForComment(null);
|
||||||
setCommentText("");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCloseInvoiceModal = () => {
|
const handleCloseInvoiceModal = () => {
|
||||||
@@ -987,8 +948,8 @@ export default function BLReconciliation() {
|
|||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => handleOpenCommentModal(delivery)}
|
onClick={() => handleOpenCommentModal(delivery)}
|
||||||
className={`h-8 w-8 p-0 ${delivery.notes ? 'text-blue-600 hover:text-blue-700' : 'text-gray-400 hover:text-gray-600'} ${delivery.reconciled ? 'opacity-70' : ''}`}
|
className={`h-8 w-8 p-0 text-gray-600 hover:text-gray-700 ${delivery.reconciled ? 'opacity-70' : ''}`}
|
||||||
title={delivery.reconciled ? (delivery.notes ? "Voir commentaire (lecture seule)" : "Aucun commentaire") : (delivery.notes ? "Voir/Modifier commentaire" : "Ajouter commentaire")}
|
title="Voir/Gérer les commentaires"
|
||||||
>
|
>
|
||||||
<MessageSquare className="h-4 w-4" />
|
<MessageSquare className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
@@ -1197,12 +1158,8 @@ export default function BLReconciliation() {
|
|||||||
)}
|
)}
|
||||||
<button
|
<button
|
||||||
onClick={() => handleOpenCommentModal(delivery)}
|
onClick={() => handleOpenCommentModal(delivery)}
|
||||||
className={`transition-colors duration-200 p-1 rounded ${
|
className={`transition-colors duration-200 p-1 rounded text-gray-600 hover:text-gray-700 hover:bg-gray-50 ${delivery.reconciled ? 'opacity-70' : ''}`}
|
||||||
delivery.notes
|
title="Voir/Gérer les commentaires"
|
||||||
? 'text-blue-600 hover:text-blue-700 hover:bg-blue-50'
|
|
||||||
: 'text-gray-400 hover:text-gray-600 hover:bg-gray-50'
|
|
||||||
} ${delivery.reconciled ? 'opacity-70' : ''}`}
|
|
||||||
title={delivery.reconciled ? (delivery.notes ? "Voir commentaire (lecture seule)" : "Aucun commentaire") : (delivery.notes ? "Voir/Modifier commentaire" : "Ajouter commentaire")}
|
|
||||||
>
|
>
|
||||||
<MessageSquare className="h-4 w-4" />
|
<MessageSquare className="h-4 w-4" />
|
||||||
</button>
|
</button>
|
||||||
@@ -1384,16 +1341,13 @@ export default function BLReconciliation() {
|
|||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
||||||
{/* Modal de commentaire */}
|
{/* Modal de commentaires de rapprochement */}
|
||||||
<Dialog open={showCommentModal} onOpenChange={setShowCommentModal}>
|
<Dialog open={showCommentModal} onOpenChange={setShowCommentModal}>
|
||||||
<DialogContent className="sm:max-w-[600px]">
|
<DialogContent className="sm:max-w-[800px]">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle className="flex items-center space-x-2">
|
<DialogTitle className="flex items-center space-x-2">
|
||||||
<MessageSquare className="w-5 h-5 text-blue-600" />
|
<MessageSquare className="w-5 h-5 text-blue-600" />
|
||||||
<span>Commentaire de livraison</span>
|
<span>Commentaires de rapprochement</span>
|
||||||
{selectedDeliveryForComment?.reconciled && (
|
|
||||||
<span className="text-sm bg-gray-100 text-gray-600 px-2 py-1 rounded">Lecture seule</span>
|
|
||||||
)}
|
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
@@ -1412,29 +1366,11 @@ export default function BLReconciliation() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid gap-2">
|
{/* Composant de commentaires de rapprochement */}
|
||||||
<Label htmlFor="comment">Commentaire</Label>
|
<ReconciliationComments
|
||||||
<Textarea
|
deliveryId={selectedDeliveryForComment.id}
|
||||||
id="comment"
|
className="max-h-[400px] overflow-y-auto"
|
||||||
placeholder={selectedDeliveryForComment?.reconciled ? "Aucun commentaire" : "Ajouter un commentaire sur cette livraison..."}
|
/>
|
||||||
value={commentText}
|
|
||||||
onChange={(e) => setCommentText(e.target.value)}
|
|
||||||
rows={4}
|
|
||||||
className="min-h-[100px]"
|
|
||||||
disabled={selectedDeliveryForComment?.reconciled}
|
|
||||||
readOnly={selectedDeliveryForComment?.reconciled}
|
|
||||||
/>
|
|
||||||
{!selectedDeliveryForComment?.reconciled && (
|
|
||||||
<div className="text-xs text-gray-500">
|
|
||||||
{commentText.length}/500 caractères
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{selectedDeliveryForComment?.reconciled && (
|
|
||||||
<div className="text-xs text-orange-600">
|
|
||||||
Le commentaire ne peut pas être modifié car le rapprochement est validé
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -1442,18 +1378,9 @@ export default function BLReconciliation() {
|
|||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={handleCloseCommentModal}
|
onClick={handleCloseCommentModal}
|
||||||
disabled={createCommentMutation.isPending}
|
|
||||||
>
|
>
|
||||||
{selectedDeliveryForComment?.reconciled ? "Fermer" : "Annuler"}
|
Fermer
|
||||||
</Button>
|
</Button>
|
||||||
{!selectedDeliveryForComment?.reconciled && (
|
|
||||||
<Button
|
|
||||||
onClick={handleSaveComment}
|
|
||||||
disabled={createCommentMutation.isPending || commentText.length > 500}
|
|
||||||
>
|
|
||||||
{createCommentMutation.isPending ? "Sauvegarde..." : "Enregistrer"}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|||||||
Reference in new issue
Block a user