mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 14:55:23 +02:00
Fix styling: Ensure Weeks of Coverage is visible even with 0 sales
This commit is contained in:
@@ -17,8 +17,22 @@ export const VendorStockBadge: React.FC<VendorStockBadgeProps> = ({ asin, vendor
|
|||||||
const stock = mode === 'uk' ? stockData.uk : stockData.eu;
|
const stock = mode === 'uk' ? stockData.uk : stockData.eu;
|
||||||
|
|
||||||
// Calculate Weeks of Coverage (WOC)
|
// Calculate Weeks of Coverage (WOC)
|
||||||
const woc = (avgWeeklySales && avgWeeklySales > 0) ? stock / avgWeeklySales : null;
|
// If we have sales velocity, calculate coverage.
|
||||||
const wocColor = woc !== null ? (woc < 4 ? 'text-rose-500' : 'text-emerald-500') : 'text-slate-400';
|
// If sales are 0 but we have stock, coverage is effectively infinite (> 4 weeks) -> Green.
|
||||||
|
// If sales are 0 and stock is 0, coverage is 0 -> Red.
|
||||||
|
let woc: number | null = null;
|
||||||
|
const velocity = avgWeeklySales || 0;
|
||||||
|
|
||||||
|
if (velocity > 0) {
|
||||||
|
woc = stock / velocity;
|
||||||
|
} else if (stock > 0) {
|
||||||
|
woc = 999; // Infinite/Safe
|
||||||
|
} else {
|
||||||
|
woc = 0; // No stock, no sales -> Empty/Red
|
||||||
|
}
|
||||||
|
|
||||||
|
const wocColor = woc < 4 ? 'text-rose-500' : 'text-emerald-500';
|
||||||
|
const wocText = woc === 999 ? '> 52 Weeks' : `${woc.toFixed(1)} Weeks Cover`;
|
||||||
|
|
||||||
const themeClasses = "bg-slate-200 text-slate-800 border-slate-300 shadow-sm";
|
const themeClasses = "bg-slate-200 text-slate-800 border-slate-300 shadow-sm";
|
||||||
|
|
||||||
@@ -62,11 +76,9 @@ export const VendorStockBadge: React.FC<VendorStockBadgeProps> = ({ asin, vendor
|
|||||||
<span>{stock.toLocaleString('de-DE')}</span>
|
<span>{stock.toLocaleString('de-DE')}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{woc !== null && (
|
<div className={`text-[9px] font-black uppercase tracking-tighter ${wocColor}`}>
|
||||||
<div className={`text-[9px] font-black uppercase tracking-tighter ${wocColor}`}>
|
{wocText}
|
||||||
{woc.toFixed(1)} Weeks Cover
|
</div>
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user