Files
Epicure/apps/web/components/recipe/share-recipe-button.tsx
T
Arnaud 21c541e115 fix: unlisted-recipe share link wrongly warned it wouldn't work (v0.28.3)
The public /r/{id} route allows any visibility except "private", so
unlisted links always worked — the copy-link toast just checked for
visibility === "public" instead of !== "private", flagging unlisted
recipes as broken when they weren't.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-14 13:40:30 +02:00

40 lines
1.1 KiB
TypeScript

"use client";
import { useTranslations } from "next-intl";
import { Share2 } from "lucide-react";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
export function ShareRecipeButton({ recipeId, visibility }: { recipeId: string; visibility: string }) {
const t = useTranslations("recipe");
async function handleShare() {
const url = `${window.location.origin}/r/${recipeId}`;
try {
await navigator.clipboard.writeText(url);
} catch {
toast.error(t("shareCopyFailed"));
return;
}
if (visibility === "private") {
toast.info(t("shareNotPublicNotice"));
} else {
toast.success(t("shareLinkCopied"));
}
}
return (
<TooltipProvider>
<Tooltip>
<TooltipTrigger render={
<Button variant="ghost" size="icon" onClick={() => void handleShare()} aria-label={t("share")}>
<Share2 className="h-4 w-4" />
</Button>
} />
<TooltipContent>{t("share")}</TooltipContent>
</Tooltip>
</TooltipProvider>
);
}