feat: per-tier feature toggles for recipe variations/pairings (v0.50.0)
Admins can now disable specific AI features per tier from Admin > Tier Limits — new feature_flags table (feature x tier -> enabled, defaulting to true so adding a new gated feature never needs a backfill). Covers recipe variations, drink pairing, and meal pairing to start. When disabled for a user's tier, the button stays visible (with a small lock badge) but opens an upgrade dialog instead of running; the API route rejects the call server-side either way (requireFeatureEnabled, re-reads tier from the DB rather than trusting the session's cache, same rationale as checkAndIncrementTierLimit). The upgrade dialog is informational only — no Stripe checkout exists yet (STRIPE_PLAN.md is still just a plan) — its CTA links to /support prefilled as an upgrade-interest suggestion. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,10 +2,11 @@
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { GitBranch } from "lucide-react";
|
||||
import { GitBranch, Lock } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import { VariationsDialog } from "./variations-dialog";
|
||||
import { UpgradeDialog } from "@/components/premium/upgrade-dialog";
|
||||
|
||||
export function VariationsButton({
|
||||
recipeId,
|
||||
@@ -15,6 +16,7 @@ export function VariationsButton({
|
||||
cookMins,
|
||||
ingredients,
|
||||
steps,
|
||||
locked = false,
|
||||
}: {
|
||||
recipeId: string;
|
||||
baseServings: number;
|
||||
@@ -23,17 +25,26 @@ export function VariationsButton({
|
||||
cookMins?: number | null;
|
||||
ingredients: Array<{ rawName: string; quantity?: string | number | null; unit?: string | null; note?: string | null; order: number }>;
|
||||
steps: Array<{ instruction: string; timerSeconds?: number | null; order: number }>;
|
||||
locked?: boolean;
|
||||
}) {
|
||||
const t = useTranslations("recipe");
|
||||
const [open, setOpen] = useState(false);
|
||||
const [upgradeOpen, setUpgradeOpen] = useState(false);
|
||||
|
||||
return (
|
||||
<>
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger render={
|
||||
<Button variant="ghost" size="icon" onClick={() => setOpen(true)} aria-label={t("variationsTooltip")}>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => (locked ? setUpgradeOpen(true) : setOpen(true))}
|
||||
aria-label={t("variationsTooltip")}
|
||||
className="relative"
|
||||
>
|
||||
<GitBranch className="h-4 w-4" />
|
||||
{locked && <Lock className="h-2.5 w-2.5 absolute bottom-1 right-1 text-muted-foreground" />}
|
||||
</Button>
|
||||
} />
|
||||
<TooltipContent>{t("variationsTooltip")}</TooltipContent>
|
||||
@@ -50,6 +61,12 @@ export function VariationsButton({
|
||||
open={open}
|
||||
onOpenChange={setOpen}
|
||||
/>
|
||||
<UpgradeDialog
|
||||
open={upgradeOpen}
|
||||
onOpenChange={setUpgradeOpen}
|
||||
featureKey="recipe_variations"
|
||||
featureLabel="Recipe variations"
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user