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,7 +2,7 @@
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Wine, Sparkles, Loader2, Coffee, Beer, GlassWater, Leaf } from "lucide-react";
|
||||
import { Wine, Sparkles, Loader2, Coffee, Beer, GlassWater, Leaf, Lock } from "lucide-react";
|
||||
import { FakeProgressBar } from "@/components/ui/fake-progress-bar";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
} from "@/components/ui/dialog";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { UpgradeDialog } from "@/components/premium/upgrade-dialog";
|
||||
|
||||
type Drink = {
|
||||
name: string;
|
||||
@@ -45,9 +46,10 @@ const TYPE_LABEL_KEY: Record<Drink["type"], string> = {
|
||||
hot: "drinksTypeHot",
|
||||
};
|
||||
|
||||
export function DrinkPairingButton({ recipeId }: { recipeId: string }) {
|
||||
export function DrinkPairingButton({ recipeId, locked = false }: { recipeId: string; locked?: boolean }) {
|
||||
const t = useTranslations("recipe");
|
||||
const [open, setOpen] = useState(false);
|
||||
const [upgradeOpen, setUpgradeOpen] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [drinks, setDrinks] = useState<Drink[]>([]);
|
||||
|
||||
@@ -72,6 +74,10 @@ export function DrinkPairingButton({ recipeId }: { recipeId: string }) {
|
||||
}
|
||||
|
||||
function handleOpen() {
|
||||
if (locked) {
|
||||
setUpgradeOpen(true);
|
||||
return;
|
||||
}
|
||||
setOpen(true);
|
||||
if (drinks.length === 0) suggest();
|
||||
}
|
||||
@@ -81,14 +87,22 @@ export function DrinkPairingButton({ recipeId }: { recipeId: string }) {
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger render={
|
||||
<Button variant="ghost" size="icon" onClick={handleOpen} aria-label={t("drinksTooltip")}>
|
||||
<Button variant="ghost" size="icon" onClick={handleOpen} aria-label={t("drinksTooltip")} className="relative">
|
||||
<Wine 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("drinksTooltip")}</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
|
||||
<UpgradeDialog
|
||||
open={upgradeOpen}
|
||||
onOpenChange={setUpgradeOpen}
|
||||
featureKey="drink_pairing"
|
||||
featureLabel="Drink pairing"
|
||||
/>
|
||||
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogContent className="max-w-2xl max-h-[80vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
|
||||
Reference in New Issue
Block a user