feat: add package comparison view
This commit is contained in:
@@ -5,6 +5,18 @@ type PackageChange = {
|
||||
isDowngrade: boolean;
|
||||
};
|
||||
|
||||
export type PackageComparisonRow =
|
||||
| {
|
||||
id: string;
|
||||
type: 'limit';
|
||||
limitKey: 'max_photos' | 'max_guests' | 'gallery_days';
|
||||
}
|
||||
| {
|
||||
id: string;
|
||||
type: 'feature';
|
||||
featureKey: string;
|
||||
};
|
||||
|
||||
function collectFeatures(pkg: Package | null): Set<string> {
|
||||
if (!pkg?.features) {
|
||||
return new Set();
|
||||
@@ -87,3 +99,30 @@ export function selectRecommendedPackageId(
|
||||
|
||||
return sorted[0]?.id ?? null;
|
||||
}
|
||||
|
||||
export function buildPackageComparisonRows(packages: Package[]): PackageComparisonRow[] {
|
||||
const limitRows: PackageComparisonRow[] = [
|
||||
{ id: 'limit.max_photos', type: 'limit', limitKey: 'max_photos' },
|
||||
{ id: 'limit.max_guests', type: 'limit', limitKey: 'max_guests' },
|
||||
{ id: 'limit.gallery_days', type: 'limit', limitKey: 'gallery_days' },
|
||||
];
|
||||
|
||||
const featureKeys = new Set<string>();
|
||||
packages.forEach((pkg) => {
|
||||
Object.entries(pkg.features ?? {}).forEach(([key, enabled]) => {
|
||||
if (enabled && key !== 'photos') {
|
||||
featureKeys.add(key);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const featureRows = Array.from(featureKeys)
|
||||
.sort((a, b) => a.localeCompare(b))
|
||||
.map((featureKey) => ({
|
||||
id: `feature.${featureKey}`,
|
||||
type: 'feature' as const,
|
||||
featureKey,
|
||||
}));
|
||||
|
||||
return [...limitRows, ...featureRows];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user