- Bildschirm "Freunde einladen" (/invite, aus den Einstellungen erreichbar): eigener Code mit nativem Teilen-Dialog, Rangleiter mit Fortschritt, eingeladene Tiere, nachträgliche Code-Eingabe im Einlösefenster - Onboarding-Schritt "Wie hast du von PawFeed erfahren?" mit Code-Eingabe, einmal pro Owner (referrals.onboardingState) - Rang-Abzeichen in PetIdentityBadges (Feed und Profil), Profilring in Rangfarbe, "Eingeladen von …" im Tierprofil - Benachrichtigungen REFERRAL_JOINED / REFERRAL_RANK_UP - Keine neuen nativen Module (React Native Share) — per OTA auslieferbar Typecheck grün; nicht auf einem Gerät getestet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
import { useTranslation } from "react-i18next";
|
|
import { useTRPC } from "../api/trpc";
|
|
|
|
const RANKS_STALE_MS = 30 * 60 * 1000; // Ränge ändern sich selten — einmal laden, lange halten
|
|
|
|
export type ReferralRankView = {
|
|
id: string;
|
|
threshold: number;
|
|
name: string;
|
|
description: string;
|
|
icon: string;
|
|
color: string;
|
|
perks: string[];
|
|
isActive: boolean;
|
|
};
|
|
|
|
export type ReferralOwnerFields = {
|
|
referralRankId?: string | null;
|
|
referralPerks?: readonly string[] | null;
|
|
};
|
|
|
|
/** Port of web's src/hooks/useReferralRanks.ts — Rangliste in der aktuellen App-Sprache. */
|
|
export function useReferralRanks(): { ranks: ReferralRankView[]; byId: Map<string, ReferralRankView> } {
|
|
const trpc = useTRPC();
|
|
const { i18n } = useTranslation();
|
|
const isGerman = i18n.language.startsWith("de");
|
|
const { data = [] } = useQuery({ ...trpc.referrals.ranks.queryOptions(), staleTime: RANKS_STALE_MS });
|
|
|
|
const ranks = data.map((rank) => ({
|
|
id: rank.id,
|
|
threshold: rank.threshold,
|
|
name: isGerman ? rank.nameDe : rank.nameEn,
|
|
description: isGerman ? rank.descriptionDe : rank.descriptionEn,
|
|
icon: rank.icon,
|
|
color: rank.color,
|
|
perks: rank.perks,
|
|
isActive: rank.isActive,
|
|
}));
|
|
return { ranks, byId: new Map(ranks.map((rank) => [rank.id, rank])) };
|
|
}
|
|
|
|
/** Rang mit dem Vorteil `perk` für diesen Owner, sonst null (Vorteile sind kumulativ, siehe Owner.referralPerks). */
|
|
export function useOwnerRankWithPerk(owner: ReferralOwnerFields | null | undefined, perk: string): ReferralRankView | null {
|
|
const { byId } = useReferralRanks();
|
|
if (!owner?.referralRankId || !owner.referralPerks?.includes(perk)) return null;
|
|
return byId.get(owner.referralRankId) ?? null;
|
|
}
|