optumflex-subscription-ui
Version:
A comprehensive React UI component library for subscription management, pricing tables, shopping cart, and checkout systems with full customization support
220 lines (213 loc) • 6.64 kB
TypeScript
import React from 'react';
interface PricingPackage {
id: string;
title: string;
package_name?: string;
description: string;
prices: {
weekly: number;
monthly: number;
quarterly: number;
halfyearly: number;
yearly: number;
};
discounted: {
weekly: number;
monthly: number;
quarterly: number;
halfyearly: number;
yearly: number;
};
features: string[];
popular?: boolean;
}
type BillingCycle = keyof PricingPackage['prices'];
type PlanType = 'subscriptionPlans' | 'modelPortfolios';
interface CartItem {
plan: PricingPackage;
cycle: BillingCycle;
}
interface SubscriptionState {
subscriptionPlans: PricingPackage[];
modelPortfolios: PricingPackage[];
loading: boolean;
error: string | null;
selectedCycles: {
[planId: string]: BillingCycle;
};
sortBy: string;
planType: PlanType;
}
interface CheckoutPayload {
packageCode: string;
duration: BillingCycle;
}
interface DiscountInfo {
originalPrice: number;
discountedPrice: number;
savings: number;
savingsPercentage: number;
isDiscounted: boolean;
}
interface SubscriptionConfig {
initialPlanType?: PlanType;
initialSortBy?: string;
currencySymbol?: string;
showCart?: boolean;
enableSorting?: boolean;
enableFiltering?: boolean;
showSavingsAsPercentage?: boolean;
}
interface UseSubscriptionOptions {
initialPlanType?: PlanType;
initialSortBy?: string;
initialData?: {
subscriptionPlans: PricingPackage[];
modelPortfolios: PricingPackage[];
};
config?: Partial<SubscriptionConfig>;
onError?: (error: string) => void;
onSuccess?: (message: string) => void;
}
interface UseSubscriptionReturn extends SubscriptionState {
setPlanType: (type: PlanType) => void;
setSortBy: (sortBy: string) => void;
setSelectedCycle: (planId: string, cycle: BillingCycle) => void;
refreshData: () => Promise<void>;
getDisplayedPlans: () => PricingPackage[];
getSortedPlans: () => PricingPackage[];
getFilteredPlans: (searchQuery?: string) => PricingPackage[];
getDiscountInfo: (plan: PricingPackage, cycle: BillingCycle) => DiscountInfo;
getAvailableCycles: (plan: PricingPackage) => BillingCycle[];
}
/**
* Parse features from API response format
*/
declare const parseFeatures: (featuresArr: any[]) => string[];
/**
* Parse a single plan from API response
*/
declare const parsePlan: (pkg: any) => PricingPackage;
/**
* Find the minimum price cycle for a plan
*/
declare const getMinimumPriceCycle: (prices: PricingPackage["prices"]) => BillingCycle;
/**
* Get available billing cycles for a plan
*/
declare const getAvailableCycles: (prices: PricingPackage["prices"]) => BillingCycle[];
/**
* Calculate discount information for a plan and cycle
*/
declare const calculateDiscountInfo: (plan: PricingPackage, cycle: BillingCycle) => DiscountInfo;
/**
* Sort plans based on criteria
*/
declare const sortPlans: (plans: PricingPackage[], sortBy: string, selectedCycles: {
[planId: string]: BillingCycle;
}) => PricingPackage[];
/**
* Generate checkout URL with cart data
*/
declare const generateCheckoutUrl: (cart: CheckoutPayload[], baseUrl: string) => string;
/**
* Handle buy now functionality for a single plan
*/
declare const handleBuyNow: (plan: PricingPackage, cycle: BillingCycle, companyInfo?: {
application?: string;
}) => void;
/**
* Format price with currency symbol
*/
declare const formatPrice: (price: number) => string;
/**
* Calculate total cart value
*/
declare const calculateCartTotal: (cart: {
plan: PricingPackage;
cycle: BillingCycle;
}[]) => number;
/**
* Create checkout payload from cart items
*/
declare const createCheckoutPayload: (cart: CartItem[]) => CheckoutPayload[];
/**
* Check if a plan has any discounts
*/
declare const hasDiscounts: (plan: PricingPackage) => boolean;
/**
* Get the best discount percentage for a plan
*/
declare const getBestDiscountPercentage: (plan: PricingPackage) => number;
/**
* Validate plan data
*/
declare const validatePlan: (plan: any) => boolean;
/**
* Filter plans by search query
*/
declare const filterPlansBySearch: (plans: PricingPackage[], searchQuery: string) => PricingPackage[];
declare const useSubscription: (options?: UseSubscriptionOptions) => UseSubscriptionReturn;
interface CartProps {
className?: string;
cart: CartItem[];
isOpen: boolean;
onClose: () => void;
onRemoveItem: (planId: string) => void;
applicationUrl?: string;
colorScheme?: {
primary?: string;
secondary?: string;
accent?: string;
background?: string;
text?: string;
border?: string;
gradient?: {
from?: string;
to?: string;
};
};
}
declare const Cart: React.FC<CartProps>;
interface SubscriptionProps {
apiData: {
subscriptionPlans: PricingPackage[];
modelPortfolios: PricingPackage[];
};
config?: Partial<SubscriptionConfig>;
applicationUrl?: string;
className?: string;
colorScheme?: {
primary?: string;
secondary?: string;
accent?: string;
background?: string;
text?: string;
border?: string;
gradient?: {
from?: string;
to?: string;
};
};
renderPlanCard?: (props: {
plan: PricingPackage;
availableCycles: BillingCycle[];
selectedCycle: BillingCycle;
isSelected: boolean;
discountInfo: any;
onCycleSelect: (cycle: BillingCycle) => void;
onAddToCart: () => void;
isInCart: boolean;
onBuyNow: (plan: PricingPackage, cycle: BillingCycle) => void;
}) => React.ReactNode;
renderHeader?: (props: {
planType: PlanType;
setPlanType: (type: PlanType) => void;
sortBy: string;
setSortBy: (sort: string) => void;
}) => React.ReactNode;
renderCart?: (props: any) => React.ReactNode;
}
declare const Subscription: React.FC<SubscriptionProps>;
export { Cart, Subscription, calculateCartTotal, calculateDiscountInfo, createCheckoutPayload, filterPlansBySearch, formatPrice, generateCheckoutUrl, getAvailableCycles, getBestDiscountPercentage, getMinimumPriceCycle, handleBuyNow, hasDiscounts, parseFeatures, parsePlan, sortPlans, useSubscription, validatePlan };
export type { BillingCycle, CartItem, CheckoutPayload, DiscountInfo, PlanType, PricingPackage, SubscriptionConfig, SubscriptionState, UseSubscriptionOptions, UseSubscriptionReturn };