mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
Improve task data handling and prevent errors during edits
Add null checks and default values to prevent runtime errors in the Avoirs component, improving data integrity and user experience. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 9fcf4b21-eb0c-4e53-a567-e2ce4a6ad869 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/9fcf4b21-eb0c-4e53-a567-e2ce4a6ad869/H30E1Dv
This commit is contained in:
1 parent
df42a3d53a
commit
d3e4f1e83c
3 files changed
+223
-14
No files matched your search
+18
-14
@@ -323,29 +323,33 @@ export default function Avoirs() {
|
||||
|
||||
// Handle edit action
|
||||
const handleEdit = (avoir: Avoir) => {
|
||||
if (!avoir || !avoir.id) return;
|
||||
|
||||
setSelectedAvoir(avoir);
|
||||
editForm.reset({
|
||||
supplierId: avoir.supplierId,
|
||||
groupId: avoir.groupId,
|
||||
supplierId: avoir.supplierId || 0,
|
||||
groupId: avoir.groupId || 0,
|
||||
invoiceReference: avoir.invoiceReference || "",
|
||||
amount: avoir.amount,
|
||||
comment: avoir.comment || "",
|
||||
commercialProcessed: avoir.commercialProcessed,
|
||||
status: avoir.status as "En attente de demande" | "Demandé" | "Reçu",
|
||||
commercialProcessed: avoir.commercialProcessed || false,
|
||||
status: avoir.status || "En attente de demande",
|
||||
});
|
||||
setIsEditDialogOpen(true);
|
||||
};
|
||||
|
||||
// Handle delete action
|
||||
const handleDelete = (avoir: Avoir) => {
|
||||
if (!avoir || !avoir.id) return;
|
||||
|
||||
setSelectedAvoir(avoir);
|
||||
setIsDeleteDialogOpen(true);
|
||||
};
|
||||
|
||||
// Handle status change
|
||||
const handleStatusChange = (avoirId: number, newStatus: string) => {
|
||||
const avoir = avoirs.find(a => a.id === avoirId);
|
||||
if (avoir) {
|
||||
const avoir = avoirs?.find(a => a?.id === avoirId);
|
||||
if (avoir && avoir.supplierId && avoir.groupId) {
|
||||
editAvoirMutation.mutate({
|
||||
id: avoirId,
|
||||
data: {
|
||||
@@ -1096,7 +1100,7 @@ export default function Avoirs() {
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
<Select
|
||||
value={avoir.status}
|
||||
value={avoir?.status || ''}
|
||||
onValueChange={(newStatus) => handleStatusChange(avoir.id, newStatus)}
|
||||
>
|
||||
<SelectTrigger className="w-full">
|
||||
@@ -1173,7 +1177,7 @@ export default function Avoirs() {
|
||||
<td className="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
||||
<div className="flex items-center space-x-2">
|
||||
{/* 📋 Icône Upload pour avoirs "Reçu" */}
|
||||
{avoir.status === 'Reçu' && (
|
||||
{avoir?.status === 'Reçu' && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
@@ -1233,7 +1237,7 @@ export default function Avoirs() {
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
{!canEditDelete && avoir.status !== 'Reçu' && (
|
||||
{!canEditDelete && avoir?.status !== 'Reçu' && (
|
||||
<span className="text-gray-400 text-xs">Lecture seule</span>
|
||||
)}
|
||||
</div>
|
||||
@@ -1407,9 +1411,9 @@ export default function Avoirs() {
|
||||
{selectedAvoir && (
|
||||
<div className="mt-4 p-3 bg-gray-50 rounded-lg">
|
||||
<div className="text-sm">
|
||||
<div><strong>Fournisseur:</strong> {selectedAvoir.supplier?.name || 'Fournisseur non défini'}</div>
|
||||
<div><strong>Référence:</strong> {selectedAvoir.invoiceReference || 'Sans référence'}</div>
|
||||
<div><strong>Montant:</strong> {selectedAvoir.amount !== null && selectedAvoir.amount !== undefined ? `${selectedAvoir.amount.toFixed(2)} €` : 'Non spécifié'}</div>
|
||||
<div><strong>Fournisseur:</strong> {selectedAvoir?.supplier?.name || 'Fournisseur non défini'}</div>
|
||||
<div><strong>Référence:</strong> {selectedAvoir?.invoiceReference || 'Sans référence'}</div>
|
||||
<div><strong>Montant:</strong> {selectedAvoir?.amount !== null && selectedAvoir?.amount !== undefined ? `${selectedAvoir.amount.toFixed(2)} €` : 'Non spécifié'}</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
@@ -1443,10 +1447,10 @@ export default function Avoirs() {
|
||||
Référence: {selectedAvoirForUpload.invoiceReference || 'Non renseigné'}
|
||||
</div>
|
||||
<div className="text-gray-600">
|
||||
Magasin: {selectedAvoirForUpload.group?.name || 'Magasin non défini'}
|
||||
Magasin: {selectedAvoirForUpload?.group?.name || 'Magasin non défini'}
|
||||
</div>
|
||||
<div className="text-gray-600">
|
||||
Montant: {selectedAvoirForUpload.amount !== null && selectedAvoirForUpload.amount !== undefined ? `${selectedAvoirForUpload.amount.toFixed(2)} €` : 'Non spécifié'}
|
||||
Montant: {selectedAvoirForUpload?.amount !== null && selectedAvoirForUpload?.amount !== undefined ? `${selectedAvoirForUpload.amount.toFixed(2)} €` : 'Non spécifié'}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user