Fix guest demo UX and enforce guest limits
This commit is contained in:
@@ -63,6 +63,20 @@ function collectFeatures(pkg: Package | null): Set<string> {
|
||||
return new Set(getEnabledPackageFeatures(pkg));
|
||||
}
|
||||
|
||||
const FEATURE_COMPATIBILITY: Record<string, string[]> = {
|
||||
limited_sharing: ['limited_sharing', 'unlimited_sharing'],
|
||||
watermark_base: ['watermark_base', 'watermark_custom', 'no_watermark'],
|
||||
};
|
||||
|
||||
function featureSatisfied(feature: string, candidateFeatures: Set<string>): boolean {
|
||||
const compatible = FEATURE_COMPATIBILITY[feature];
|
||||
if (compatible) {
|
||||
return compatible.some((value) => candidateFeatures.has(value));
|
||||
}
|
||||
|
||||
return candidateFeatures.has(feature);
|
||||
}
|
||||
|
||||
function compareLimit(candidate: number | null, active: number | null): number {
|
||||
if (active === null) {
|
||||
return candidate === null ? 0 : -1;
|
||||
@@ -89,8 +103,8 @@ export function classifyPackageChange(pkg: Package, active: Package | null): Pac
|
||||
const activeFeatures = collectFeatures(active);
|
||||
const candidateFeatures = collectFeatures(pkg);
|
||||
|
||||
const hasFeatureUpgrade = Array.from(candidateFeatures).some((feature) => !activeFeatures.has(feature));
|
||||
const hasFeatureDowngrade = Array.from(activeFeatures).some((feature) => !candidateFeatures.has(feature));
|
||||
const hasFeatureUpgrade = Array.from(candidateFeatures).some((feature) => !featureSatisfied(feature, activeFeatures));
|
||||
const hasFeatureDowngrade = Array.from(activeFeatures).some((feature) => !featureSatisfied(feature, candidateFeatures));
|
||||
|
||||
const limitKeys: Array<keyof Package> = ['max_photos', 'max_guests', 'gallery_days'];
|
||||
let hasLimitUpgrade = false;
|
||||
|
||||
Reference in New Issue
Block a user