Improve how verified documents are loaded from the server cache

Update the Avoirs page to fetch invoice verification status from a POST request to the server, utilizing the existing cache if available, and store the results in the component's state.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 9fcf4b21-eb0c-4e53-a567-e2ce4a6ad869
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/9fcf4b21-eb0c-4e53-a567-e2ce4a6ad869/uMhb9Na
This commit is contained in:
michaelschal committed 2025-09-08 19:54:45 +00:00
1 parent c55044f89e
commit a62e1783a2
1 file changed
+23 -8
+23 -8
View File
@@ -176,7 +176,7 @@ export default function Avoirs() {
enabled: !!user,
});
// 🔄 Charger les vérifications du cache au démarrage
// 🔄 Charger les vérifications depuis le cache serveur au démarrage
useEffect(() => {
const loadCachedVerifications = async () => {
console.log('🔍 LoadCache - Début vérification:', {
@@ -187,19 +187,34 @@ export default function Avoirs() {
if (!avoirs || avoirs.length === 0) return;
const cachedResults: Record<number, any> = {};
// Charger les vérifications depuis le cache serveur pour TOUS les avoirs avec référence
for (const avoir of avoirs) {
console.log('🔍 LoadCache - Avoir analysé:', {
id: avoir.id,
hasInvoiceRef: !!avoir.invoiceReference?.trim(),
invoiceReference: avoir.invoiceReference,
nocodbVerified: avoir.nocodbVerified,
shouldCache: !!(avoir.invoiceReference?.trim() && avoir.nocodbVerified)
nocodbVerified: avoir.nocodbVerified
});
if (avoir.invoiceReference?.trim() && avoir.nocodbVerified) {
// Si l'avoir est validé, marquer comme vérifié
cachedResults[avoir.id] = { exists: true, fromCache: true, permanent: true };
console.log('✅ LoadCache - Avoir ajouté au cache:', avoir.id);
// Si l'avoir a une référence de facture, vérifier le cache serveur
if (avoir.invoiceReference?.trim()) {
try {
const result = await apiRequest(`/api/avoirs/${avoir.id}/verify-invoice`, 'POST', {
invoiceReference: avoir.invoiceReference,
forceRefresh: false // Utiliser le cache si disponible
});
console.log('🔍 LoadCache - Résultat cache serveur pour avoir', avoir.id, ':', result);
if (result.exists !== undefined) {
cachedResults[avoir.id] = result;
console.log('✅ LoadCache - Avoir ajouté au cache depuis serveur:', avoir.id);
}
} catch (error) {
console.log('⚠️ LoadCache - Erreur cache serveur pour avoir', avoir.id, ':', error);
// Continuer sans erreur si le cache échoue
}
}
}
@@ -210,7 +225,7 @@ export default function Avoirs() {
if (Object.keys(cachedResults).length > 0) {
setAvoirVerificationResults(prev => ({ ...prev, ...cachedResults }));
console.log('✅ Vérifications cachées chargées et appliquées:', cachedResults);
console.log('✅ Vérifications chargées depuis le serveur:', cachedResults);
}
};