Use admin-set sale end dates in countdown banner
- Countdown now uses actual sale_end_date from database instead of hardcoded Sunday - Shows time until earliest sale end date when multiple sales are active - Falls back to next Sunday if no end dates are set - Banner now reflects real deadlines set in admin panel
This commit is contained in:
@@ -12,9 +12,10 @@ interface TimeLeft {
|
||||
interface SaleCountdownProps {
|
||||
hasActiveSale: boolean;
|
||||
maxSalePercentage?: number;
|
||||
saleEndDate?: string | null;
|
||||
}
|
||||
|
||||
export function SaleCountdown({ hasActiveSale, maxSalePercentage = 5 }: SaleCountdownProps) {
|
||||
export function SaleCountdown({ hasActiveSale, maxSalePercentage = 5, saleEndDate }: SaleCountdownProps) {
|
||||
const [timeLeft, setTimeLeft] = useState<TimeLeft>({ days: 0, hours: 0, minutes: 0, seconds: 0 });
|
||||
const [mounted, setMounted] = useState(false);
|
||||
|
||||
@@ -26,16 +27,24 @@ export function SaleCountdown({ hasActiveSale, maxSalePercentage = 5 }: SaleCoun
|
||||
if (!mounted) return;
|
||||
|
||||
const calculateTimeLeft = (): TimeLeft => {
|
||||
// Get next Sunday at 23:59:59
|
||||
const now = new Date();
|
||||
const nextSunday = new Date();
|
||||
const daysUntilSunday = (7 - now.getDay()) % 7;
|
||||
const targetDay = daysUntilSunday === 0 ? 7 : daysUntilSunday; // If today is Sunday, target next Sunday
|
||||
|
||||
nextSunday.setDate(now.getDate() + targetDay);
|
||||
nextSunday.setHours(23, 59, 59, 999);
|
||||
let targetDate: Date;
|
||||
|
||||
const difference = nextSunday.getTime() - now.getTime();
|
||||
if (saleEndDate) {
|
||||
// Use the sale end date from admin
|
||||
targetDate = new Date(saleEndDate);
|
||||
} else {
|
||||
// Fallback to next Sunday at 23:59:59
|
||||
const nextSunday = new Date();
|
||||
const daysUntilSunday = (7 - now.getDay()) % 7;
|
||||
const targetDay = daysUntilSunday === 0 ? 7 : daysUntilSunday;
|
||||
|
||||
nextSunday.setDate(now.getDate() + targetDay);
|
||||
nextSunday.setHours(23, 59, 59, 999);
|
||||
targetDate = nextSunday;
|
||||
}
|
||||
|
||||
const difference = targetDate.getTime() - now.getTime();
|
||||
|
||||
if (difference > 0) {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user