feat: init
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import type { FC } from "react";
|
||||
// plane imports
|
||||
import { observer } from "mobx-react";
|
||||
import type { EProductSubscriptionEnum, TBillingFrequency } from "@plane/types";
|
||||
import { getSubscriptionBackgroundColor, getDiscountPillStyle } from "@plane/ui";
|
||||
import { calculateYearlyDiscount, cn } from "@plane/utils";
|
||||
|
||||
type TPlanFrequencyToggleProps = {
|
||||
subscriptionType: EProductSubscriptionEnum;
|
||||
monthlyPrice: number;
|
||||
yearlyPrice: number;
|
||||
selectedFrequency: TBillingFrequency;
|
||||
setSelectedFrequency: (frequency: TBillingFrequency) => void;
|
||||
};
|
||||
|
||||
export const PlanFrequencyToggle: FC<TPlanFrequencyToggleProps> = observer((props) => {
|
||||
const { subscriptionType, monthlyPrice, yearlyPrice, selectedFrequency, setSelectedFrequency } = props;
|
||||
// derived values
|
||||
const yearlyDiscount = calculateYearlyDiscount(monthlyPrice, yearlyPrice);
|
||||
|
||||
return (
|
||||
<div className="flex w-full items-center cursor-pointer py-1 animate-slide-up">
|
||||
<div
|
||||
className={cn(
|
||||
"flex space-x-1 rounded-md bg-custom-primary-200/10 p-0.5 w-full",
|
||||
getSubscriptionBackgroundColor(subscriptionType, "50")
|
||||
)}
|
||||
>
|
||||
<div
|
||||
key="month"
|
||||
onClick={() => setSelectedFrequency("month")}
|
||||
className={cn(
|
||||
"w-full rounded px-1 py-0.5 text-xs font-medium leading-5 text-center",
|
||||
selectedFrequency === "month"
|
||||
? "bg-custom-background-100 text-custom-text-100 shadow"
|
||||
: "text-custom-text-300 hover:text-custom-text-200"
|
||||
)}
|
||||
>
|
||||
Monthly
|
||||
</div>
|
||||
<div
|
||||
key="year"
|
||||
onClick={() => setSelectedFrequency("year")}
|
||||
className={cn(
|
||||
"w-full rounded px-1 py-0.5 text-xs font-medium leading-5 text-center",
|
||||
selectedFrequency === "year"
|
||||
? "bg-custom-background-100 text-custom-text-100 shadow"
|
||||
: "text-custom-text-300 hover:text-custom-text-200"
|
||||
)}
|
||||
>
|
||||
Yearly
|
||||
{yearlyDiscount > 0 && (
|
||||
<span className={cn(getDiscountPillStyle(subscriptionType), "rounded-full px-1 py-0.5 ml-1 text-[9px]")}>
|
||||
-{yearlyDiscount}%
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,127 @@
|
||||
import type { FC } from "react";
|
||||
import { observer } from "mobx-react";
|
||||
// plane imports
|
||||
import {
|
||||
SUBSCRIPTION_REDIRECTION_URLS,
|
||||
SUBSCRIPTION_WITH_BILLING_FREQUENCY,
|
||||
TALK_TO_SALES_URL,
|
||||
WORKSPACE_SETTINGS_TRACKER_ELEMENTS,
|
||||
WORKSPACE_SETTINGS_TRACKER_EVENTS,
|
||||
} from "@plane/constants";
|
||||
import { useTranslation } from "@plane/i18n";
|
||||
import { getButtonStyling } from "@plane/propel/button";
|
||||
import type { TBillingFrequency } from "@plane/types";
|
||||
import { EProductSubscriptionEnum } from "@plane/types";
|
||||
import { getUpgradeButtonStyle } from "@plane/ui";
|
||||
import { cn, getSubscriptionName } from "@plane/utils";
|
||||
// components
|
||||
import { DiscountInfo } from "@/components/license/modal/card/discount-info";
|
||||
import type { TPlanDetail } from "@/constants/plans";
|
||||
// local imports
|
||||
import { captureSuccess } from "@/helpers/event-tracker.helper";
|
||||
import { PlanFrequencyToggle } from "./frequency-toggle";
|
||||
|
||||
type TPlanDetailProps = {
|
||||
subscriptionType: EProductSubscriptionEnum;
|
||||
planDetail: TPlanDetail;
|
||||
billingFrequency: TBillingFrequency | undefined;
|
||||
setBillingFrequency: (frequency: TBillingFrequency) => void;
|
||||
};
|
||||
|
||||
const COMMON_BUTTON_STYLE =
|
||||
"relative inline-flex items-center justify-center w-full px-4 py-1.5 text-xs font-medium rounded-lg focus:outline-none transition-all duration-300 animate-slide-up";
|
||||
|
||||
export const PlanDetail: FC<TPlanDetailProps> = observer((props) => {
|
||||
const { subscriptionType, planDetail, billingFrequency, setBillingFrequency } = props;
|
||||
// plane hooks
|
||||
const { t } = useTranslation();
|
||||
// subscription details
|
||||
const subscriptionName = getSubscriptionName(subscriptionType);
|
||||
const isSubscriptionActive = planDetail.isActive;
|
||||
// pricing details
|
||||
const displayPrice = billingFrequency === "month" ? planDetail.monthlyPrice : planDetail.yearlyPrice;
|
||||
const pricingDescription = isSubscriptionActive ? "a user per month" : "Quote on request";
|
||||
const pricingSecondaryDescription =
|
||||
billingFrequency === "month"
|
||||
? planDetail.monthlyPriceSecondaryDescription
|
||||
: planDetail.yearlyPriceSecondaryDescription;
|
||||
// helper styles
|
||||
const upgradeButtonStyle = getUpgradeButtonStyle(subscriptionType, false) ?? getButtonStyling("primary", "lg");
|
||||
|
||||
const handleRedirection = () => {
|
||||
const frequency = billingFrequency ?? "year";
|
||||
// Get the redirection URL based on the subscription type and billing frequency
|
||||
const redirectUrl = SUBSCRIPTION_REDIRECTION_URLS[subscriptionType][frequency] ?? TALK_TO_SALES_URL;
|
||||
captureSuccess({
|
||||
eventName: WORKSPACE_SETTINGS_TRACKER_EVENTS.upgrade_plan_redirected,
|
||||
payload: {
|
||||
subscriptionType,
|
||||
},
|
||||
});
|
||||
// Open the URL in a new tab
|
||||
window.open(redirectUrl, "_blank");
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col justify-between col-span-1 p-3 space-y-0.5">
|
||||
{/* Plan name and pricing section */}
|
||||
<div className="flex flex-col items-start">
|
||||
<div className="flex w-full gap-2 items-center text-xl font-medium">
|
||||
<span className="transition-all duration-300">{subscriptionName}</span>
|
||||
{subscriptionType === EProductSubscriptionEnum.PRO && (
|
||||
<span className="px-2 rounded text-custom-primary-200 bg-custom-primary-100/20 text-xs">Popular</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex gap-x-2 items-start text-custom-text-300 pb-1 transition-all duration-300 animate-slide-up">
|
||||
{isSubscriptionActive && displayPrice !== undefined && (
|
||||
<div className="flex items-center gap-1 text-2xl text-custom-text-100 font-semibold transition-all duration-300">
|
||||
<DiscountInfo
|
||||
currency="$"
|
||||
frequency={billingFrequency ?? "month"}
|
||||
price={displayPrice}
|
||||
subscriptionType={subscriptionType}
|
||||
className="mr-1.5"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="pt-1">
|
||||
{pricingDescription && <div className="transition-all duration-300">{pricingDescription}</div>}
|
||||
{pricingSecondaryDescription && (
|
||||
<div className="text-xs text-custom-text-400 transition-all duration-300">
|
||||
{pricingSecondaryDescription}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Billing frequency toggle */}
|
||||
{SUBSCRIPTION_WITH_BILLING_FREQUENCY.includes(subscriptionType) && billingFrequency && (
|
||||
<div className="h-8 py-0.5">
|
||||
<PlanFrequencyToggle
|
||||
subscriptionType={subscriptionType}
|
||||
monthlyPrice={planDetail.monthlyPrice || 0}
|
||||
yearlyPrice={planDetail.yearlyPrice || 0}
|
||||
selectedFrequency={billingFrequency}
|
||||
setSelectedFrequency={setBillingFrequency}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Subscription button */}
|
||||
<div className={cn("flex flex-col gap-1 py-3 items-start transition-all duration-300")}>
|
||||
<button
|
||||
onClick={handleRedirection}
|
||||
className={cn(upgradeButtonStyle, COMMON_BUTTON_STYLE)}
|
||||
data-ph-element={
|
||||
isSubscriptionActive
|
||||
? WORKSPACE_SETTINGS_TRACKER_ELEMENTS.BILLING_UPGRADE_BUTTON(subscriptionType)
|
||||
: WORKSPACE_SETTINGS_TRACKER_ELEMENTS.BILLING_TALK_TO_SALES_BUTTON
|
||||
}
|
||||
>
|
||||
{isSubscriptionActive ? `Upgrade to ${subscriptionName}` : t("common.upgrade_cta.talk_to_sales")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
48
apps/web/ce/components/workspace/billing/comparison/root.tsx
Normal file
48
apps/web/ce/components/workspace/billing/comparison/root.tsx
Normal file
@@ -0,0 +1,48 @@
|
||||
import { observer } from "mobx-react";
|
||||
// plane imports
|
||||
import type { EProductSubscriptionEnum, TBillingFrequency } from "@plane/types";
|
||||
// components
|
||||
import { PlansComparisonBase, shouldRenderPlanDetail } from "@/components/workspace/billing/comparison/base";
|
||||
import type { TPlanePlans } from "@/constants/plans";
|
||||
import { PLANE_PLANS } from "@/constants/plans";
|
||||
// plane web imports
|
||||
import { PlanDetail } from "./plan-detail";
|
||||
|
||||
type TPlansComparisonProps = {
|
||||
isCompareAllFeaturesSectionOpen: boolean;
|
||||
getBillingFrequency: (subscriptionType: EProductSubscriptionEnum) => TBillingFrequency | undefined;
|
||||
setBillingFrequency: (subscriptionType: EProductSubscriptionEnum, frequency: TBillingFrequency) => void;
|
||||
setIsCompareAllFeaturesSectionOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
};
|
||||
|
||||
export const PlansComparison = observer((props: TPlansComparisonProps) => {
|
||||
const {
|
||||
isCompareAllFeaturesSectionOpen,
|
||||
getBillingFrequency,
|
||||
setBillingFrequency,
|
||||
setIsCompareAllFeaturesSectionOpen,
|
||||
} = props;
|
||||
// plan details
|
||||
const { planDetails } = PLANE_PLANS;
|
||||
|
||||
return (
|
||||
<PlansComparisonBase
|
||||
planeDetails={Object.entries(planDetails).map(([planKey, plan]) => {
|
||||
const currentPlanKey = planKey as TPlanePlans;
|
||||
if (!shouldRenderPlanDetail(currentPlanKey)) return null;
|
||||
return (
|
||||
<PlanDetail
|
||||
key={planKey}
|
||||
subscriptionType={plan.id}
|
||||
planDetail={plan}
|
||||
billingFrequency={getBillingFrequency(plan.id)}
|
||||
setBillingFrequency={(frequency) => setBillingFrequency(plan.id, frequency)}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
isSelfManaged
|
||||
isCompareAllFeaturesSectionOpen={isCompareAllFeaturesSectionOpen}
|
||||
setIsCompareAllFeaturesSectionOpen={setIsCompareAllFeaturesSectionOpen}
|
||||
/>
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user