Addon-Kauf im Event admin korrigiert.

This commit is contained in:
Codex Agent
2025-12-29 19:31:26 +01:00
parent aaf418a917
commit 902e78cae9
8 changed files with 295 additions and 29 deletions

View File

@@ -0,0 +1,50 @@
import { describe, expect, it } from 'vitest';
import { buildLimitWarnings } from '../limitWarnings';
describe('buildLimitWarnings', () => {
it('renders gallery warning in hours when less than two days remain', () => {
const warnings = buildLimitWarnings(
{
photos: null,
guests: null,
gallery: {
state: 'warning',
expires_at: null,
days_remaining: 1.2,
warning_thresholds: [],
warning_triggered: null,
warning_sent_at: null,
expired_notified_at: null,
},
can_upload_photos: true,
can_add_guests: true,
},
(key, options) => (key === 'galleryWarningHours' ? `hours:${options?.hours}` : key),
);
expect(warnings[0]?.message).toBe('hours:29');
});
it('renders gallery warning in days when two or more days remain', () => {
const warnings = buildLimitWarnings(
{
photos: null,
guests: null,
gallery: {
state: 'warning',
expires_at: null,
days_remaining: 2.1,
warning_thresholds: [],
warning_triggered: null,
warning_sent_at: null,
expired_notified_at: null,
},
can_upload_photos: true,
can_add_guests: true,
},
(key, options) => (key === 'galleryWarningDays' ? `days:${options?.days}` : key),
);
expect(warnings[0]?.message).toBe('days:3');
});
});

View File

@@ -104,12 +104,21 @@ export function buildLimitWarnings(limits: EventLimitSummary, t: TranslateFn): L
} else if (limits.gallery.state === 'warning') {
const days = limits.gallery.days_remaining ?? 0;
const safeDays = Math.max(0, days);
const key = safeDays === 1 ? 'galleryWarningDay' : 'galleryWarningDays';
const useHours = safeDays > 0 && safeDays < 2;
const roundedDays = Math.max(1, Math.ceil(safeDays));
const roundedHours = Math.max(1, Math.ceil(safeDays * 24));
const key = useHours
? roundedHours === 1
? 'galleryWarningHour'
: 'galleryWarningHours'
: roundedDays === 1
? 'galleryWarningDay'
: 'galleryWarningDays';
warnings.push({
id: 'gallery-warning',
scope: 'gallery',
tone: 'warning',
message: t(key, { days: safeDays }),
message: t(key, useHours ? { hours: roundedHours } : { days: roundedDays }),
});
}
}