fix: validate document expiry dates before countdown
This commit is contained in:
@@ -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">
|
||||
|
||||
Reference in New Issue
Block a user