Fixing PLans page
This commit is contained in:
@@ -20,7 +20,6 @@ export default function ProtectedRoute({ children }: ProtectedRouteProps) {
|
||||
const [errorMessage, setErrorMessage] = useState<string>('');
|
||||
const PLAN_ALLOWED_PATHS = [
|
||||
'/account/plans',
|
||||
'/account/billing',
|
||||
'/account/purchase-credits',
|
||||
'/account/settings',
|
||||
'/account/team',
|
||||
@@ -126,7 +125,7 @@ export default function ProtectedRoute({ children }: ProtectedRouteProps) {
|
||||
|
||||
if (!isPrivileged) {
|
||||
if (pendingPayment && !isPlanAllowedPath) {
|
||||
return <Navigate to="/account/billing" state={{ from: location }} replace />;
|
||||
return <Navigate to="/account/plans" state={{ from: location }} replace />;
|
||||
}
|
||||
if (accountInactive && !isPlanAllowedPath) {
|
||||
return <Navigate to="/account/plans" state={{ from: location }} replace />;
|
||||
|
||||
@@ -100,7 +100,7 @@ export default function SignUpForm({ planDetails: planDetailsProp, planLoading:
|
||||
|
||||
const status = user?.account?.status;
|
||||
if (status === "pending_payment") {
|
||||
navigate("/account/billing", { replace: true });
|
||||
navigate("/account/plans", { replace: true });
|
||||
} else {
|
||||
navigate("/sites", { replace: true });
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ export interface PricingPlan {
|
||||
name: string;
|
||||
price: string | number; // Current displayed price (will be calculated based on period)
|
||||
monthlyPrice?: string | number; // Base monthly price (used for annual discount calculation)
|
||||
annualDiscountPercent?: number; // Annual discount percentage from backend (default 15%)
|
||||
originalPrice?: string | number;
|
||||
period?: string; // "/month", "/year", "/Lifetime"
|
||||
description?: string;
|
||||
@@ -63,7 +64,7 @@ export default function PricingTable({
|
||||
return price;
|
||||
};
|
||||
|
||||
// Calculate price based on billing period with 20% annual discount
|
||||
// Calculate price based on billing period with discount from backend
|
||||
const getDisplayPrice = (plan: PricingPlan): { price: number; originalPrice?: number } => {
|
||||
const monthlyPrice = typeof plan.monthlyPrice === 'number'
|
||||
? plan.monthlyPrice
|
||||
@@ -72,8 +73,12 @@ export default function PricingTable({
|
||||
: parseFloat(String(plan.price || 0));
|
||||
|
||||
if (billingPeriod === 'annually' && showToggle) {
|
||||
// Annual price: monthly * 12 * 0.8 (20% discount)
|
||||
const annualPrice = monthlyPrice * 12 * 0.8;
|
||||
// Get discount percentage from plan (default 15%)
|
||||
const discountPercent = plan.annualDiscountPercent || 15;
|
||||
const discountMultiplier = (100 - discountPercent) / 100;
|
||||
|
||||
// Annual price: monthly * 12 * discount multiplier
|
||||
const annualPrice = monthlyPrice * 12 * discountMultiplier;
|
||||
const originalAnnualPrice = monthlyPrice * 12;
|
||||
return { price: annualPrice, originalPrice: originalAnnualPrice };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user