feat: Gedenkmodus „In Erinnerung“ für verstorbene Tiere
- Pet.deceasedAt + NotificationType.PET_DECEASED (additiv) - pets.setDeceased: nur Besitzer, kein Datum in der Zukunft, rückgängig machbar; beim ersten Setzen einmalig stille Mitteilung (ohne Push) an Follower anderer Besitzer - Verstorbene Tiere bekommen keine Geburtstags-/Adoptionstag-Mitteilungen, Impf-Erinnerungen und Tier-Vorschläge mehr und werden nicht vorgeschlagen - Abzeichen „In Erinnerung“ (Ribbon) überall neben dem Namen, Gedenk-Banner im Profil, Bereich „Gedenkmodus“ in „Profil bearbeiten“ (Web + App) - Mitteilung führt zum Profil des Tiers (Liste + Push-Tap) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b244ef4c10
commit
9216f0c702
31 files changed
+537
-25
No files matched your search
@@ -261,6 +261,7 @@ interface MockNotificationClient {
|
||||
findUnique: MockFn;
|
||||
count: MockFn;
|
||||
updateMany: MockFn;
|
||||
createMany: MockFn;
|
||||
}
|
||||
|
||||
interface MockWeightLogClient {
|
||||
@@ -642,6 +643,7 @@ export function createMockPrisma(): MockPrismaClient {
|
||||
findUnique: vi.fn(),
|
||||
count: vi.fn(),
|
||||
updateMany: vi.fn(),
|
||||
createMany: vi.fn().mockResolvedValue({ count: 0 }),
|
||||
},
|
||||
weightLog: {
|
||||
findMany: vi.fn(),
|
||||
|
||||
@@ -296,3 +296,60 @@ describe("Ownership assertion — non-owner cannot update", () => {
|
||||
expect(mockPrisma.pet.update).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("setDeceased: Gedenkmodus „In Erinnerung“", () => {
|
||||
let mockPrisma: ReturnType<typeof createMockPrisma>;
|
||||
|
||||
beforeEach(() => {
|
||||
mockPrisma = createMockPrisma();
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("sets the date and quietly notifies follower pets of other owners once", async () => {
|
||||
mockPrisma.pet.findUnique.mockResolvedValue({ ...MOCK_PET, deceasedAt: null });
|
||||
mockPrisma.pet.update.mockResolvedValue({});
|
||||
mockPrisma.follow.findMany.mockResolvedValue([{ followerPetId: "f1" }, { followerPetId: "f2" }]);
|
||||
|
||||
const caller = createTestCaller(TEST_OWNER_ID, mockPrisma);
|
||||
await caller.setDeceased({ petId: PET_ID, deceasedAt: "2026-10-01" });
|
||||
|
||||
expect(mockPrisma.pet.update).toHaveBeenCalledWith({ where: { id: PET_ID }, data: { deceasedAt: new Date("2026-10-01") } });
|
||||
expect(mockPrisma.follow.findMany).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ where: { followeePetId: PET_ID, follower: { ownerId: { not: TEST_OWNER_ID } } } })
|
||||
);
|
||||
expect(mockPrisma.notification.createMany).toHaveBeenCalledWith({
|
||||
data: [
|
||||
{ recipientPetId: "f1", type: "PET_DECEASED", actorPetId: PET_ID },
|
||||
{ recipientPetId: "f2", type: "PET_DECEASED", actorPetId: PET_ID },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("does not notify again when only the date is corrected", async () => {
|
||||
mockPrisma.pet.findUnique.mockResolvedValue({ ...MOCK_PET, deceasedAt: new Date("2026-10-01") });
|
||||
mockPrisma.pet.update.mockResolvedValue({});
|
||||
|
||||
await createTestCaller(TEST_OWNER_ID, mockPrisma).setDeceased({ petId: PET_ID, deceasedAt: "2026-09-30" });
|
||||
|
||||
expect(mockPrisma.notification.createMany).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("can be undone without notifications", async () => {
|
||||
mockPrisma.pet.findUnique.mockResolvedValue({ ...MOCK_PET, deceasedAt: new Date("2026-10-01") });
|
||||
mockPrisma.pet.update.mockResolvedValue({});
|
||||
|
||||
await createTestCaller(TEST_OWNER_ID, mockPrisma).setDeceased({ petId: PET_ID, deceasedAt: null });
|
||||
|
||||
expect(mockPrisma.pet.update).toHaveBeenCalledWith({ where: { id: PET_ID }, data: { deceasedAt: null } });
|
||||
expect(mockPrisma.notification.createMany).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("rejects non-owners and future dates", async () => {
|
||||
mockPrisma.pet.findUnique.mockResolvedValue({ ...MOCK_PET, ownerId: OTHER_OWNER_ID, deceasedAt: null });
|
||||
await expect(createTestCaller(TEST_OWNER_ID, mockPrisma).setDeceased({ petId: PET_ID, deceasedAt: "2026-10-01" })).rejects.toThrow(TRPCError);
|
||||
|
||||
mockPrisma.pet.findUnique.mockResolvedValue({ ...MOCK_PET, deceasedAt: null });
|
||||
await expect(createTestCaller(TEST_OWNER_ID, mockPrisma).setDeceased({ petId: PET_ID, deceasedAt: "2999-01-01" })).rejects.toThrow(/Zukunft/);
|
||||
expect(mockPrisma.pet.update).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -3,7 +3,7 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Bell, UserPlus, Heart, MessageCircle, Cake, Home, AtSign, Repeat2, Sparkles, Gift, Award, Syringe, PawPrint } from "lucide-react";
|
||||
import { Bell, UserPlus, Heart, MessageCircle, Cake, Home, AtSign, Repeat2, Sparkles, Gift, Award, Syringe, PawPrint, Ribbon } from "lucide-react";
|
||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { useTRPC } from "@/trpc/client";
|
||||
import { useActivePet } from "@/context/ActivePetContext";
|
||||
@@ -18,9 +18,9 @@ import { formatRelativeCompact } from "@/lib/format-relative-time";
|
||||
import { RankRing } from "@/components/referrals/RankRing";
|
||||
import { StoryViewer } from "@/components/stories/StoryViewer";
|
||||
|
||||
type NotificationType = "FOLLOW" | "REACTION" | "COMMENT" | "MESSAGE" | "BIRTHDAY" | "ADOPTION_DAY" | "MENTION" | "PAW_BACK" | "PET_SUGGESTION" | "REFERRAL_JOINED" | "REFERRAL_RANK_UP" | "VACCINE_DUE" | "STORY_MENTION" | "STORY_COMMENT" | "STORY_REACTION";
|
||||
type NotificationType = "FOLLOW" | "REACTION" | "COMMENT" | "MESSAGE" | "BIRTHDAY" | "ADOPTION_DAY" | "MENTION" | "PAW_BACK" | "PET_SUGGESTION" | "REFERRAL_JOINED" | "REFERRAL_RANK_UP" | "VACCINE_DUE" | "STORY_MENTION" | "STORY_COMMENT" | "STORY_REACTION" | "PET_DECEASED";
|
||||
|
||||
const KNOWN_TYPES = new Set<string>(["FOLLOW", "REACTION", "COMMENT", "MESSAGE", "BIRTHDAY", "ADOPTION_DAY", "MENTION", "PAW_BACK", "PET_SUGGESTION", "REFERRAL_JOINED", "REFERRAL_RANK_UP", "VACCINE_DUE", "STORY_MENTION", "STORY_COMMENT", "STORY_REACTION"]);
|
||||
const KNOWN_TYPES = new Set<string>(["FOLLOW", "REACTION", "COMMENT", "MESSAGE", "BIRTHDAY", "ADOPTION_DAY", "MENTION", "PAW_BACK", "PET_SUGGESTION", "REFERRAL_JOINED", "REFERRAL_RANK_UP", "VACCINE_DUE", "STORY_MENTION", "STORY_COMMENT", "STORY_REACTION", "PET_DECEASED"]);
|
||||
|
||||
function notificationIcon(type: NotificationType) {
|
||||
switch (type) {
|
||||
@@ -39,6 +39,7 @@ function notificationIcon(type: NotificationType) {
|
||||
case "STORY_MENTION": return <AtSign className="h-4 w-4 text-orange-500" />;
|
||||
case "STORY_COMMENT": return <MessageCircle className="h-4 w-4 text-orange-500" />;
|
||||
case "STORY_REACTION": return <PawPrint className="h-4 w-4 text-orange-500" />;
|
||||
case "PET_DECEASED": return <Ribbon className="h-4 w-4 fill-foreground text-foreground" />;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +107,7 @@ export default function NotificationsPage() {
|
||||
case "FOLLOW":
|
||||
case "PET_SUGGESTION":
|
||||
case "REFERRAL_JOINED":
|
||||
case "PET_DECEASED":
|
||||
return notif.actorPet ? `/pets/${notif.actorPet.id}` : null;
|
||||
case "REFERRAL_RANK_UP":
|
||||
return "/einladen";
|
||||
@@ -280,6 +282,7 @@ export default function NotificationsPage() {
|
||||
{notif.type === "STORY_MENTION" && t("typeStoryMention")}
|
||||
{notif.type === "STORY_COMMENT" && t("typeStoryComment")}
|
||||
{notif.type === "STORY_REACTION" && t("typeStoryReaction")}
|
||||
{notif.type === "PET_DECEASED" && t("typePetDeceased")}
|
||||
{notif.type === "VACCINE_DUE" && notif.vaccine?.nextDueDate &&
|
||||
t("typeVaccineDue", {
|
||||
name: notif.vaccine.name,
|
||||
|
||||
@@ -9,6 +9,7 @@ import { useTranslations } from "next-intl";
|
||||
import { useTRPC } from "@/trpc/client";
|
||||
import { useActivePet } from "@/context/ActivePetContext";
|
||||
import { PetForm } from "@/components/pet/PetForm";
|
||||
import { MemorialSettings } from "@/components/pet/MemorialSettings";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
@@ -279,6 +280,10 @@ export default function EditPetPage() {
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Gedenkmodus „In Erinnerung“ */}
|
||||
<Separator className="my-8" />
|
||||
<MemorialSettings petId={pet.id} petName={pet.name} deceasedAt={pet.deceasedAt} />
|
||||
|
||||
{/* Destructive zone */}
|
||||
<Separator className="my-8" />
|
||||
<div className="flex flex-col gap-2">
|
||||
|
||||
@@ -2,7 +2,8 @@ import { notFound } from "next/navigation";
|
||||
import { formatPetName } from "@/lib/pet-display-name";
|
||||
import Link from "next/link";
|
||||
import { currentUser } from "@clerk/nextjs/server";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { getFormatter, getTranslations } from "next-intl/server";
|
||||
import { Ribbon } from "lucide-react";
|
||||
import { createTRPCCaller } from "@/trpc/server";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { buttonVariants } from "@/components/ui/button";
|
||||
@@ -34,6 +35,8 @@ export default async function PetProfilePage({ params }: PageProps) {
|
||||
|
||||
const t = await getTranslations("PetProfile");
|
||||
const tFounding = await getTranslations("FoundingMember");
|
||||
const tMemory = await getTranslations("InMemory");
|
||||
const format = await getFormatter();
|
||||
const trpc = await createTRPCCaller();
|
||||
|
||||
let pet;
|
||||
@@ -77,6 +80,7 @@ export default async function PetProfilePage({ params }: PageProps) {
|
||||
<h1 className="flex items-center gap-1.5 text-xl font-semibold text-center">
|
||||
{formatPetName(pet)}
|
||||
<PetIdentityBadges
|
||||
isDeceased={!!pet.deceasedAt}
|
||||
isVerified={pet.isVerified}
|
||||
isFoundingMember={pet.isFoundingMember}
|
||||
sponsor={pet.owner}
|
||||
@@ -85,6 +89,15 @@ export default async function PetProfilePage({ params }: PageProps) {
|
||||
verifiedLabel={t("verified")}
|
||||
/>
|
||||
</h1>
|
||||
{pet.deceasedAt && (
|
||||
<p className="flex items-center gap-1.5 rounded-full border border-border bg-muted px-3 py-1 text-xs text-muted-foreground">
|
||||
<Ribbon className="h-3.5 w-3.5 fill-foreground text-foreground" aria-hidden />
|
||||
{tMemory("banner", {
|
||||
name: pet.name,
|
||||
date: format.dateTime(new Date(pet.deceasedAt), { dateStyle: "long", timeZone: "UTC" }),
|
||||
})}
|
||||
</p>
|
||||
)}
|
||||
{pet.isFoundingMember && (
|
||||
<p className="text-xs text-emerald-700 dark:text-emerald-400">{tFounding("tooltip")}</p>
|
||||
)}
|
||||
|
||||
@@ -26,6 +26,7 @@ export async function GET(req: Request) {
|
||||
AND EXTRACT(MONTH FROM birthday) = ${month}
|
||||
AND EXTRACT(DAY FROM birthday) = ${day}
|
||||
AND birthday <= NOW() - INTERVAL '1 year'
|
||||
AND "deceasedAt" IS NULL
|
||||
`;
|
||||
|
||||
// Find all pets whose adoptedAt matches today and was at least 1 year ago
|
||||
@@ -35,6 +36,7 @@ export async function GET(req: Request) {
|
||||
AND EXTRACT(MONTH FROM "adoptedAt") = ${month}
|
||||
AND EXTRACT(DAY FROM "adoptedAt") = ${day}
|
||||
AND "adoptedAt" <= NOW() - INTERVAL '1 year'
|
||||
AND "deceasedAt" IS NULL
|
||||
`;
|
||||
|
||||
let created = 0;
|
||||
|
||||
@@ -48,7 +48,7 @@ export async function GET(req: Request) {
|
||||
const suggestionCooldownStart = new Date(Date.now() - SUGGESTION_COOLDOWN_MS);
|
||||
|
||||
const pets = await prisma.pet.findMany({
|
||||
where: { owner: { petSuggestionsEnabled: true } },
|
||||
where: { owner: { petSuggestionsEnabled: true }, deceasedAt: null },
|
||||
select: { id: true, speciesId: true, breedId: true, ownerId: true },
|
||||
});
|
||||
|
||||
@@ -89,6 +89,7 @@ export async function GET(req: Request) {
|
||||
id: { notIn: Array.from(excludedPetIds) },
|
||||
speciesId: targetSpeciesId,
|
||||
owner: { shadowban: null },
|
||||
deceasedAt: null, // verstorbene Tiere nicht vorschlagen
|
||||
...(spiderExclusionId ? { NOT: { speciesId: spiderExclusionId } } : {}),
|
||||
},
|
||||
select: { id: true, breedId: true, _count: { select: { followers: true } } },
|
||||
|
||||
@@ -81,6 +81,7 @@ type PostPet = {
|
||||
name: string;
|
||||
avatarKey: string | null;
|
||||
isVerified?: boolean;
|
||||
deceasedAt?: Date | string | null;
|
||||
isFoundingMember?: boolean;
|
||||
// Sponsor fields only come with petCardSelect (feed/explore); posts.byPetId
|
||||
// uses petIdentitySelect, whose owner carries just the referral rank.
|
||||
@@ -256,7 +257,7 @@ function PostCardImpl({ post, onDeleted, variant = "feed" }: PostCardProps) {
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="flex items-center gap-1 text-base font-semibold text-foreground leading-tight truncate">
|
||||
{formatPetName(pet)}
|
||||
<PetIdentityBadges isVerified={pet.isVerified} isFoundingMember={pet.isFoundingMember} sponsor={pet.owner} referral={pet.owner} />
|
||||
<PetIdentityBadges isDeceased={!!pet.deceasedAt} isVerified={pet.isVerified} isFoundingMember={pet.isFoundingMember} sponsor={pet.owner} referral={pet.owner} />
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{formatRelativeTime(createdAt)}
|
||||
|
||||
@@ -37,6 +37,7 @@ type Pet = {
|
||||
name: string;
|
||||
avatarKey: string | null;
|
||||
isVerified: boolean;
|
||||
deceasedAt?: Date | string | null;
|
||||
species: { name: string };
|
||||
};
|
||||
|
||||
@@ -110,7 +111,7 @@ export function MobileNav({ pets }: MobileNavProps) {
|
||||
/>
|
||||
<span className="font-medium text-foreground truncate max-w-[120px] flex items-center gap-1">
|
||||
{formatPetName(activePet)}
|
||||
<PetIdentityBadges isVerified={activePet.isVerified} size="sm" />
|
||||
<PetIdentityBadges isDeceased={!!activePet.deceasedAt} isVerified={activePet.isVerified} size="sm" />
|
||||
</span>
|
||||
<ChevronDown className="h-3 w-3 text-muted-foreground" />
|
||||
</DropdownMenuTrigger>
|
||||
@@ -128,7 +129,7 @@ export function MobileNav({ pets }: MobileNavProps) {
|
||||
/>
|
||||
<span className="flex-1 text-sm truncate flex items-center gap-1">
|
||||
{formatPetName(pet)}
|
||||
<PetIdentityBadges isVerified={pet.isVerified} size="sm" />
|
||||
<PetIdentityBadges isDeceased={!!pet.deceasedAt} isVerified={pet.isVerified} size="sm" />
|
||||
</span>
|
||||
<Badge variant="secondary" className="text-xs shrink-0">
|
||||
{pet.species.name}
|
||||
|
||||
@@ -42,6 +42,7 @@ type Pet = {
|
||||
name: string;
|
||||
avatarKey: string | null;
|
||||
isVerified: boolean;
|
||||
deceasedAt?: Date | string | null;
|
||||
species: { name: string };
|
||||
};
|
||||
|
||||
@@ -152,7 +153,7 @@ export function Sidebar({ pets }: SidebarProps) {
|
||||
<>
|
||||
<span className="text-sm font-medium text-foreground flex-1 truncate flex items-center gap-1">
|
||||
{formatPetName(activePet)}
|
||||
<PetIdentityBadges isVerified={activePet.isVerified} />
|
||||
<PetIdentityBadges isDeceased={!!activePet.deceasedAt} isVerified={activePet.isVerified} />
|
||||
</span>
|
||||
<ChevronDown className="h-4 w-4 text-muted-foreground shrink-0" />
|
||||
</>
|
||||
@@ -172,7 +173,7 @@ export function Sidebar({ pets }: SidebarProps) {
|
||||
/>
|
||||
<span className="flex-1 text-sm truncate flex items-center gap-1">
|
||||
{formatPetName(pet)}
|
||||
<PetIdentityBadges isVerified={pet.isVerified} size="sm" />
|
||||
<PetIdentityBadges isDeceased={!!pet.deceasedAt} isVerified={pet.isVerified} size="sm" />
|
||||
</span>
|
||||
<Badge variant="secondary" className="text-xs shrink-0">
|
||||
{pet.species.name}
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { toast } from "sonner";
|
||||
import { Ribbon } from "lucide-react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useTRPC } from "@/trpc/client";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogClose,
|
||||
} from "@/components/ui/dialog";
|
||||
|
||||
type Props = {
|
||||
petId: string;
|
||||
petName: string;
|
||||
deceasedAt: Date | string | null;
|
||||
};
|
||||
|
||||
/** YYYY-MM-DD eines @db.Date-Werts (kommt als UTC-Mitternacht). */
|
||||
function toDateInput(value: Date | string | null): string {
|
||||
return value ? new Date(value).toISOString().slice(0, 10) : "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gedenkmodus „In Erinnerung“ in „Profil bearbeiten“: Datum setzen (mit
|
||||
* Bestätigung, Follower werden einmalig still informiert), korrigieren oder
|
||||
* zurücknehmen. Server: pets.setDeceased.
|
||||
*/
|
||||
export function MemorialSettings({ petId, petName, deceasedAt }: Props) {
|
||||
const t = useTranslations("InMemory");
|
||||
const trpc = useTRPC();
|
||||
const queryClient = useQueryClient();
|
||||
const router = useRouter();
|
||||
const isDeceased = deceasedAt != null;
|
||||
const [today] = useState(() => new Date().toISOString().slice(0, 10));
|
||||
const [date, setDate] = useState(() => toDateInput(deceasedAt) || today);
|
||||
const [confirmOpen, setConfirmOpen] = useState(false);
|
||||
|
||||
const mutation = useMutation({
|
||||
...trpc.pets.setDeceased.mutationOptions(),
|
||||
onSuccess: async (_data, variables) => {
|
||||
setConfirmOpen(false);
|
||||
toast.success(variables.deceasedAt ? t("saved") : t("removed"));
|
||||
await queryClient.invalidateQueries();
|
||||
router.refresh();
|
||||
},
|
||||
onError: () => toast.error(t("saveFailed")),
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<h2 className="flex items-center gap-1.5 text-sm font-medium">
|
||||
<Ribbon className="h-4 w-4" aria-hidden />
|
||||
{t("settingsHeading")}
|
||||
</h2>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{isDeceased ? t("activeHint", { name: petName }) : t("settingsHint")}
|
||||
</p>
|
||||
<div className="flex flex-wrap items-end gap-2">
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="deceased-at" className="text-xs">
|
||||
{t("dateLabel")}
|
||||
</Label>
|
||||
<Input
|
||||
id="deceased-at"
|
||||
type="date"
|
||||
max={today}
|
||||
value={date}
|
||||
onChange={(e) => setDate(e.target.value)}
|
||||
className="w-44"
|
||||
/>
|
||||
</div>
|
||||
{isDeceased ? (
|
||||
<>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
disabled={mutation.isPending || !date || date === toDateInput(deceasedAt)}
|
||||
onClick={() => mutation.mutate({ petId, deceasedAt: date })}
|
||||
>
|
||||
{t("saveDate")}
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
disabled={mutation.isPending}
|
||||
onClick={() => mutation.mutate({ petId, deceasedAt: null })}
|
||||
>
|
||||
{t("remove")}
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<Button variant="outline" size="sm" disabled={!date} onClick={() => setConfirmOpen(true)}>
|
||||
{t("activate")}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Dialog open={confirmOpen} onOpenChange={setConfirmOpen}>
|
||||
<DialogContent showCloseButton={false}>
|
||||
<DialogHeader>
|
||||
<DialogTitle className="text-base font-semibold">{t("confirmTitle", { name: petName })}</DialogTitle>
|
||||
<DialogDescription>{t("confirmDescription")}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<DialogClose render={<Button variant="outline" onClick={() => setConfirmOpen(false)} />}>
|
||||
{t("cancel")}
|
||||
</DialogClose>
|
||||
<Button disabled={mutation.isPending} onClick={() => mutation.mutate({ petId, deceasedAt: date })}>
|
||||
{t("confirm")}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
"use client";
|
||||
|
||||
import { Ribbon } from "lucide-react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const ICON_SIZE = { sm: "h-3 w-3", md: "h-3.5 w-3.5", lg: "h-4 w-4" } as const;
|
||||
|
||||
/** Gedenkmodus „In Erinnerung“ — das Tier ist verstorben (Pet.deceasedAt). */
|
||||
export function InMemoryBadge({ size = "md" }: { size?: keyof typeof ICON_SIZE }) {
|
||||
const t = useTranslations("InMemory");
|
||||
return (
|
||||
<span title={t("tooltip")} className="inline-flex shrink-0">
|
||||
<Ribbon className={cn(ICON_SIZE[size], "fill-foreground text-foreground")} aria-label={t("label")} />
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { isActiveSponsor } from "@/lib/sponsor";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { ReferralRankBadge, type ReferralOwnerFields } from "@/components/referrals/ReferralRankBadge";
|
||||
import { FoundingMemberBadge } from "@/components/ui/founding-member-badge";
|
||||
import { InMemoryBadge } from "@/components/ui/in-memory-badge";
|
||||
|
||||
type SponsorWindow = {
|
||||
// Optional: a pet identity's owner (petIdentitySelect) carries only the referral rank.
|
||||
@@ -14,6 +15,8 @@ type Props = {
|
||||
isVerified?: boolean;
|
||||
/** Eines der ersten 250 Tiere (Pet.isFoundingMember). */
|
||||
isFoundingMember?: boolean;
|
||||
/** Gedenkmodus „In Erinnerung“ (Pet.deceasedAt gesetzt). */
|
||||
isDeceased?: boolean;
|
||||
/** Omit entirely (rather than passing null) when the caller has no owner/sponsor data to show. */
|
||||
sponsor?: SponsorWindow | null;
|
||||
/** Owner-Felder referralRankId/referralPerks (petCardSelect.owner) — Rang-Abzeichen des Empfehlungsprogramms. */
|
||||
@@ -44,6 +47,7 @@ function isSponsorActive(sponsor: SponsorWindow): boolean {
|
||||
export function PetIdentityBadges({
|
||||
isVerified,
|
||||
isFoundingMember,
|
||||
isDeceased,
|
||||
sponsor,
|
||||
referral,
|
||||
size = "md",
|
||||
@@ -53,10 +57,11 @@ export function PetIdentityBadges({
|
||||
const iconClass = ICON_SIZE[size];
|
||||
const showSponsor = sponsor != null && isSponsorActive(sponsor);
|
||||
|
||||
if (!isVerified && !isFoundingMember && !showSponsor && !referral?.referralRankId) return null;
|
||||
if (!isDeceased && !isVerified && !isFoundingMember && !showSponsor && !referral?.referralRankId) return null;
|
||||
|
||||
return (
|
||||
<>
|
||||
{isDeceased && <InMemoryBadge size={size} />}
|
||||
{isVerified && (
|
||||
<BadgeCheck
|
||||
className={cn(iconClass, "shrink-0 fill-blue-500 text-background")}
|
||||
|
||||
@@ -53,6 +53,7 @@ const PUSH_COPY: Record<
|
||||
VACCINE_DUE: { title: "Impfung bald fällig", genericBody: "Eine Impfung wird bald fällig.", actorBody: () => "Eine Impfung wird bald fällig." },
|
||||
STORY_MENTION: { title: "In einer Story markiert", genericBody: "Du wurdest in einer Story markiert.", actorBody: (a) => `${a} hat dich in einer Story markiert.` },
|
||||
STORY_COMMENT: { title: "Neuer Story-Kommentar", genericBody: "Jemand hat deine Story kommentiert.", actorBody: (a) => `${a} hat deine Story kommentiert.` },
|
||||
PET_DECEASED: { title: "In Erinnerung", genericBody: "Ein Tier, dem du folgst, ist verstorben.", actorBody: (a) => `${a} ist leider verstorben.` },
|
||||
STORY_REACTION: { title: "Neue Pfote", genericBody: "Jemand hat deiner Story eine Pfote gegeben.", actorBody: (a) => `${a} hat deiner Story eine Pfote gegeben.` },
|
||||
};
|
||||
|
||||
|
||||
@@ -42,7 +42,8 @@ export async function sendVaccineReminders(prisma: ReminderPrisma, now = new Dat
|
||||
const horizon = new Date(today.getTime() + VACCINE_REMINDER_LEAD_DAYS * DAY_MS);
|
||||
|
||||
const dueVaccines = await prisma.vaccine.findMany({
|
||||
where: { reminderSentAt: null, nextDueDate: { gte: today, lte: horizon } },
|
||||
// Verstorbene Tiere („In Erinnerung“) bekommen keine Impf-Erinnerungen mehr.
|
||||
where: { reminderSentAt: null, nextDueDate: { gte: today, lte: horizon }, pet: { deceasedAt: null } },
|
||||
select: { id: true, petId: true, name: true, nextDueDate: true, pet: { select: { name: true } } },
|
||||
orderBy: { nextDueDate: "asc" },
|
||||
take: MAX_REMINDERS_PER_RUN,
|
||||
|
||||
@@ -22,6 +22,8 @@ export const petIdentitySelect = {
|
||||
name: true,
|
||||
nickname: true,
|
||||
avatarKey: true,
|
||||
// „In Erinnerung“-Abzeichen überall neben dem Namen
|
||||
deceasedAt: true,
|
||||
owner: { select: referralOwnerSelect },
|
||||
} satisfies Prisma.PetSelect;
|
||||
|
||||
|
||||
@@ -153,6 +153,42 @@ export const petsRouter = router({
|
||||
* Asserts ownership before any DB write (T-3-01).
|
||||
* T-3-02: Zod enforces character limits server-side.
|
||||
*/
|
||||
/**
|
||||
* Gedenkmodus „In Erinnerung“: Besitzer markiert sein Tier als verstorben
|
||||
* (Datum) oder nimmt das zurück (null). Beim ersten Setzen bekommen die
|
||||
* Follower einmalig eine stille Mitteilung (PET_DECEASED, bewusst ohne Push),
|
||||
* eigene Tiere des Besitzers nicht.
|
||||
*/
|
||||
setDeceased: protectedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
petId: z.string().min(1),
|
||||
deceasedAt: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).nullable(),
|
||||
})
|
||||
)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const pet = await assertPetOwnership(ctx.prisma, input.petId, ctx.userId);
|
||||
const deceasedAt = input.deceasedAt ? new Date(input.deceasedAt) : null;
|
||||
if (deceasedAt && deceasedAt.getTime() > Date.now()) {
|
||||
throw new TRPCError({ code: "BAD_REQUEST", message: "Das Datum liegt in der Zukunft." });
|
||||
}
|
||||
|
||||
await ctx.prisma.pet.update({ where: { id: input.petId }, data: { deceasedAt } });
|
||||
|
||||
if (deceasedAt && !pet.deceasedAt) {
|
||||
const followers = await ctx.prisma.follow.findMany({
|
||||
where: { followeePetId: input.petId, follower: { ownerId: { not: pet.ownerId } } },
|
||||
select: { followerPetId: true },
|
||||
});
|
||||
if (followers.length > 0) {
|
||||
await ctx.prisma.notification.createMany({
|
||||
data: followers.map((f) => ({ recipientPetId: f.followerPetId, type: "PET_DECEASED" as const, actorPetId: input.petId })),
|
||||
});
|
||||
}
|
||||
}
|
||||
return { deceasedAt };
|
||||
}),
|
||||
|
||||
update: protectedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
|
||||
Reference in new issue
Block a user