Fix guest demo UX and enforce guest limits
This commit is contained in:
@@ -233,10 +233,13 @@ class PackageLimitEvaluator
|
||||
config('package-limits.photo_thresholds', [])
|
||||
);
|
||||
|
||||
$guestSummary = $this->buildUsageSummary(
|
||||
(int) $eventPackage->used_guests,
|
||||
$limits['max_guests'],
|
||||
config('package-limits.guest_thresholds', [])
|
||||
$guestSummary = $this->applyGuestGrace(
|
||||
$this->buildUsageSummary(
|
||||
(int) $eventPackage->used_guests,
|
||||
$limits['max_guests'],
|
||||
config('package-limits.guest_thresholds', [])
|
||||
),
|
||||
(int) $eventPackage->used_guests
|
||||
);
|
||||
|
||||
$gallerySummary = $this->buildGallerySummary(
|
||||
@@ -429,4 +432,37 @@ class PackageLimitEvaluator
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{limit: ?int, used: int, remaining: ?int, percentage: ?float, state: string, threshold_reached: ?float, next_threshold: ?float, thresholds: array} $summary
|
||||
* @return array{limit: ?int, used: int, remaining: ?int, percentage: ?float, state: string, threshold_reached: ?float, next_threshold: ?float, thresholds: array}
|
||||
*/
|
||||
private function applyGuestGrace(array $summary, int $used): array
|
||||
{
|
||||
$limit = $summary['limit'] ?? null;
|
||||
if ($limit === null || $limit <= 0) {
|
||||
return $summary;
|
||||
}
|
||||
|
||||
$grace = (int) config('package-limits.guest_grace', 10);
|
||||
$hardLimit = $limit + max(0, $grace);
|
||||
|
||||
if ($used >= $hardLimit) {
|
||||
$summary['state'] = 'limit_reached';
|
||||
$summary['threshold_reached'] = 1.0;
|
||||
$summary['next_threshold'] = null;
|
||||
$summary['remaining'] = 0;
|
||||
|
||||
return $summary;
|
||||
}
|
||||
|
||||
if ($used >= $limit) {
|
||||
$summary['state'] = 'warning';
|
||||
$summary['threshold_reached'] = 1.0;
|
||||
$summary['next_threshold'] = null;
|
||||
$summary['remaining'] = 0;
|
||||
}
|
||||
|
||||
return $summary;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user