From 7be5762297f05f778df514f0680649034a3f0dff Mon Sep 17 00:00:00 2001 From: Leander Furumo Date: Sat, 31 Oct 2026 01:44:07 +0100 Subject: [PATCH] Only offer goals that are reachable with the current number of paying members Co-Authored-By: Claude Opus 5.5 --- src/app/components/GoalSelector.tsx | 10 ++++------ src/app/components/HomeClient.tsx | 3 +++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/app/components/GoalSelector.tsx b/src/app/components/GoalSelector.tsx index 001b9e2..9ea96a7 100644 --- a/src/app/components/GoalSelector.tsx +++ b/src/app/components/GoalSelector.tsx @@ -4,6 +4,8 @@ import { useLanguage } from "@/LanguageContext"; import { translations } from "@/translations"; import React from "react"; +const DEFAULT_OPTIONS = [25, 50, 100]; + interface GoalSelectorProps { goalAmount: number; setGoalAmount: (amount: number) => void; @@ -15,12 +17,8 @@ const GoalSelector: React.FC = ({ goalAmount, setGoalAmount, const { language } = useLanguage(); const t = translations[language]; - const options = [25, 50, 100]; - if (totalMembers > 0 && !options.includes(totalMembers)) { - // Add totalMembers to options and sort - options.push(totalMembers); - options.sort((a, b) => a - b); - } + const options = + totalMembers > 0 ? [...DEFAULT_OPTIONS.filter((option) => option < totalMembers), totalMembers] : DEFAULT_OPTIONS; return (
diff --git a/src/app/components/HomeClient.tsx b/src/app/components/HomeClient.tsx index bf3dcb5..5a85953 100644 --- a/src/app/components/HomeClient.tsx +++ b/src/app/components/HomeClient.tsx @@ -42,6 +42,9 @@ export default function HomeClient({ session }: { session: Session }) { if (res.ok) { const data = await res.json(); setTotalMembers(data.count); + if (data.count > 0) { + setGoalAmount((goal) => Math.min(goal, data.count)); + } } } catch (error) { console.error("Failed to fetch total members", error);