fix: standardize locked-vs-hidden treatment across all 9 per-tier gated features (v0.79.0)
Rule, applied consistently everywhere via a new isFeatureAvailableAnyTier() helper: if a feature is enabled on at least one tier, it stays visible for locked-out viewers with a small "Pro" badge and opens an upgrade prompt on click; if a feature is disabled on every tier, it hides entirely, since there's no upgrade path to point at. Covers: recipe variations, meal/drink pairings, nutrition estimation, Markdown export (5 call sites), weekly nutrition, import from URL, import from photo, and the Instacart grocery-delivery menu item. Previously inconsistent — some hid outright, one showed a lock icon overlapping its own icon. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { UpgradeDialog } from "@/components/premium/upgrade-dialog";
|
||||
import { ProBadge } from "@/components/premium/pro-badge";
|
||||
|
||||
type NutritionTotals = {
|
||||
calories: number;
|
||||
@@ -34,6 +36,9 @@ type NutritionResponse = {
|
||||
|
||||
interface WeeklyNutritionBarProps {
|
||||
weekStart: string;
|
||||
/** Available on some tier but not the viewer's — shows a locked teaser
|
||||
* (with a "Pro" upsell) instead of hiding, and skips fetching totals. */
|
||||
locked?: boolean;
|
||||
}
|
||||
|
||||
type BarItem = {
|
||||
@@ -45,16 +50,39 @@ type BarItem = {
|
||||
colorClass: string;
|
||||
};
|
||||
|
||||
export function WeeklyNutritionBar({ weekStart }: WeeklyNutritionBarProps) {
|
||||
export function WeeklyNutritionBar({ weekStart, locked = false }: WeeklyNutritionBarProps) {
|
||||
const t = useTranslations("mealPlan.nutritionBar");
|
||||
const [data, setData] = useState<NutritionResponse | null>(null);
|
||||
const [upgradeOpen, setUpgradeOpen] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (locked) return;
|
||||
fetch(`/api/v1/meal-plans/${weekStart}/nutrition`)
|
||||
.then((res) => (res.ok ? res.json() : null))
|
||||
.then((json) => setData(json))
|
||||
.catch(() => setData(null));
|
||||
}, [weekStart]);
|
||||
}, [weekStart, locked]);
|
||||
|
||||
if (locked) {
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setUpgradeOpen(true)}
|
||||
className="flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
{t("dailyAverageVsGoals")}
|
||||
<ProBadge />
|
||||
</button>
|
||||
<UpgradeDialog
|
||||
open={upgradeOpen}
|
||||
onOpenChange={setUpgradeOpen}
|
||||
featureKey="weekly_nutrition"
|
||||
featureLabel="Weekly nutrition"
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
if (!data || !data.goals) return null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user