mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: abstract the pricing plans for setup and billing page
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
// @ts-nocheck
|
||||
import * as R from 'ramda';
|
||||
import { PricingPlan } from '@/components/PricingPlan/PricingPlan';
|
||||
import { SubscriptionPlansPeriod } from '@/store/plans/plans.reducer';
|
||||
import {
|
||||
WithPlansProps,
|
||||
withPlans,
|
||||
} from '@/containers/Subscriptions/withPlans';
|
||||
import { ButtonProps } from '@blueprintjs/core';
|
||||
|
||||
interface SubscriptionPricingFeature {
|
||||
text: string;
|
||||
hint?: string;
|
||||
hintLabel?: string;
|
||||
style?: Record<string, string>;
|
||||
}
|
||||
|
||||
interface SubscriptionPricingProps {
|
||||
slug: string;
|
||||
label: string;
|
||||
description: string;
|
||||
features?: Array<SubscriptionPricingFeature>;
|
||||
featured?: boolean;
|
||||
monthlyPrice: string;
|
||||
monthlyPriceLabel: string;
|
||||
annuallyPrice: string;
|
||||
annuallyPriceLabel: string;
|
||||
onSubscribe?: (variantId: number) => void;
|
||||
subscribeButtonProps?: Optional<ButtonProps>;
|
||||
}
|
||||
|
||||
interface SubscriptionPricingCombinedProps
|
||||
extends SubscriptionPricingProps,
|
||||
WithPlansProps {}
|
||||
|
||||
function SubscriptionPlanRoot({
|
||||
label,
|
||||
description,
|
||||
featured,
|
||||
features,
|
||||
monthlyPrice,
|
||||
monthlyPriceLabel,
|
||||
annuallyPrice,
|
||||
annuallyPriceLabel,
|
||||
onSubscribe,
|
||||
subscribeButtonProps,
|
||||
|
||||
// #withPlans
|
||||
plansPeriod,
|
||||
}: SubscriptionPricingCombinedProps) {
|
||||
const handleClick = () => {
|
||||
onSubscribe && onSubscribe();
|
||||
};
|
||||
|
||||
return (
|
||||
<PricingPlan featured={featured}>
|
||||
{featured && <PricingPlan.Featured>Most Popular</PricingPlan.Featured>}
|
||||
<PricingPlan.Header label={label} description={description} />
|
||||
|
||||
{plansPeriod === SubscriptionPlansPeriod.Monthly ? (
|
||||
<PricingPlan.Price price={monthlyPrice} subPrice={monthlyPriceLabel} />
|
||||
) : (
|
||||
<PricingPlan.Price
|
||||
price={annuallyPrice}
|
||||
subPrice={annuallyPriceLabel}
|
||||
/>
|
||||
)}
|
||||
<PricingPlan.BuyButton onClick={handleClick} {...subscribeButtonProps}>
|
||||
Subscribe
|
||||
</PricingPlan.BuyButton>
|
||||
|
||||
<PricingPlan.Features>
|
||||
{features?.map((feature) => (
|
||||
<PricingPlan.FeatureLine
|
||||
hintLabel={feature.hintLabel}
|
||||
hintContent={feature.hint}
|
||||
>
|
||||
{feature.text}
|
||||
</PricingPlan.FeatureLine>
|
||||
))}
|
||||
</PricingPlan.Features>
|
||||
</PricingPlan>
|
||||
);
|
||||
}
|
||||
|
||||
export const SubscriptionPlan = R.compose(
|
||||
withPlans(({ plansPeriod }) => ({ plansPeriod })),
|
||||
)(SubscriptionPlanRoot);
|
||||
@@ -0,0 +1,52 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
|
||||
|
||||
interface WithSubscriptionPlanProps {
|
||||
plan: any;
|
||||
onSubscribe?: (variantId: number) => void;
|
||||
}
|
||||
|
||||
interface MappedSubscriptionPlanProps {
|
||||
slug: string;
|
||||
label: string;
|
||||
description: string;
|
||||
features: any[];
|
||||
featured: boolean;
|
||||
monthlyPrice: string;
|
||||
monthlyPriceLabel: string;
|
||||
annuallyPrice: string;
|
||||
annuallyPriceLabel: string;
|
||||
monthlyVariantId: number;
|
||||
annuallyVariantId: number;
|
||||
onSubscribe?: (variantId: number) => void;
|
||||
}
|
||||
|
||||
export const withSubscriptionPlanMapper = <
|
||||
P extends MappedSubscriptionPlanProps,
|
||||
>(
|
||||
WrappedComponent: React.ComponentType<P>,
|
||||
) => {
|
||||
return function WithSubscriptionPlanMapper(
|
||||
props: WithSubscriptionPlanProps &
|
||||
Omit<P, keyof MappedSubscriptionPlanProps>,
|
||||
) {
|
||||
const { plan, onSubscribe, ...restProps } = props;
|
||||
|
||||
const mappedProps: MappedSubscriptionPlanProps = {
|
||||
slug: plan.slug,
|
||||
label: plan.name,
|
||||
description: plan.description,
|
||||
features: plan.features,
|
||||
featured: plan.featured,
|
||||
monthlyPrice: plan.monthlyPrice,
|
||||
monthlyPriceLabel: plan.monthlyPriceLabel,
|
||||
annuallyPrice: plan.annuallyPrice,
|
||||
annuallyPriceLabel: plan.annuallyPriceLabel,
|
||||
monthlyVariantId: plan.monthlyVariantId,
|
||||
annuallyVariantId: plan.annuallyVariantId,
|
||||
onSubscribe,
|
||||
};
|
||||
return <WrappedComponent {...mappedProps} {...(restProps as P)} />;
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user