fix: validate document expiry dates before countdown

This commit is contained in:
2026-09-06 16:29:06 +03:00
parent 5a4371f5ed
commit 2d1667940a
2 changed files with 15 additions and 1 deletions
+9 -1
View File
@@ -140,7 +140,14 @@ const DocumentVaultSession = ({signedIn}) => {
try { setDurum(await updateDocumentMeta(id, { sonKullanma: tarih || null })); }
catch (e) { setHata(e.message); }
};
const kalanGun = (b) => (b.son_kullanma ? Math.ceil((new Date(b.son_kullanma).getTime() - Date.now()) / 86400000) : null);
const kalanGun = (b) => {
const value=String(b.son_kullanma || '');
if (!/^\d{4}-\d{2}-\d{2}$/.test(value)) return null;
const date=new Date(value+'T00:00:00Z');
if (Number.isNaN(date.getTime()) || date.toISOString().slice(0,10)!==value) return null;
return Math.ceil((date.getTime() - Date.now()) / 86400000);
};
const gecersizSonKullanma = (b) => Boolean(b.son_kullanma) && kalanGun(b) === null;
const suresiDolan = (durum?.belgeler || []).filter((b) => kalanGun(b) != null && kalanGun(b) < 0);
const yakinda = (durum?.belgeler || []).filter((b) => kalanGun(b) != null && kalanGun(b) >= 0 && kalanGun(b) <= 30);
@@ -319,6 +326,7 @@ const DocumentVaultSession = ({signedIn}) => {
{kalanGun(d) < 0 ? `${-kalanGun(d)} gün önce doldu` : `${kalanGun(d)} gün kaldı`}
</span>
)}
{gecersizSonKullanma(d) && <span role="alert" className="font-bold text-red-700">Tarih doğrulanmalı</span>}
</label>
</div>
<div className="flex flex-wrap items-center gap-1">