Files
cfw-autumn/shared/utils/featureUtils/convertFeatureUtils.ts
John Yeo 32cbb1d690 fix: improve onboarding stability and product switching behavior
- Fix product changes being discarded when navigating back from playground step
- Fix base price billing interval visibility when unchecked
- Improve feature sync logic to prioritize non-boolean features
- Fix auto-skip to playground only triggering on initial load, not on back navigation
- Fix feature store sync when switching products in playground
- Prevent useOnboardingFeatureSync from interfering with new feature creation
- Rename useInitProductAndFeature to useOnboardingFeatureSync for clarity
- Remove useInitFeatureItem logic that was corrupting product items on product switch

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 17:40:40 +01:00

28 lines
963 B
TypeScript

import {
FeatureType,
FeatureUsageType,
} from "@models/featureModels/featureEnums.js";
import type { Feature } from "@models/featureModels/featureModels.js";
import { ProductItemFeatureType } from "@models/productV2Models/productItemModels/productItemModels.js";
export const featureToItemFeatureType = ({ feature }: { feature: Feature }) => {
let featureType: ProductItemFeatureType;
if (feature.type === FeatureType.Boolean) {
featureType = ProductItemFeatureType.Static;
} else if (feature.type === FeatureType.CreditSystem) {
featureType = ProductItemFeatureType.SingleUse;
} else if (feature.type === FeatureType.Metered) {
const usageType = feature.config?.usage_type;
if (usageType === FeatureUsageType.Continuous) {
featureType = ProductItemFeatureType.ContinuousUse;
} else {
featureType = ProductItemFeatureType.SingleUse;
}
} else {
// Fallback
featureType = ProductItemFeatureType.SingleUse;
}
return featureType;
};