2f3ba14093
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>
73 lines
2.2 KiB
TypeScript
73 lines
2.2 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import { useTranslations } from "next-intl";
|
|
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,
|
|
baseServings,
|
|
difficulty,
|
|
prepMins,
|
|
cookMins,
|
|
ingredients,
|
|
steps,
|
|
locked = false,
|
|
}: {
|
|
recipeId: string;
|
|
baseServings: number;
|
|
difficulty?: string | null;
|
|
prepMins?: number | null;
|
|
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={() => (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>
|
|
</Tooltip>
|
|
</TooltipProvider>
|
|
<VariationsDialog
|
|
recipeId={recipeId}
|
|
baseServings={baseServings}
|
|
difficulty={difficulty}
|
|
prepMins={prepMins}
|
|
cookMins={cookMins}
|
|
ingredients={ingredients}
|
|
steps={steps}
|
|
open={open}
|
|
onOpenChange={setOpen}
|
|
/>
|
|
<UpgradeDialog
|
|
open={upgradeOpen}
|
|
onOpenChange={setUpgradeOpen}
|
|
featureKey="recipe_variations"
|
|
featureLabel="Recipe variations"
|
|
/>
|
|
</>
|
|
);
|
|
}
|