refactor: simplify the capture picker without behavior change

Drop the no-op single-argument cn() wrapper on the chooser button
class (and its now-unused import), and replace the three-way nested
ternary that resolves the form-sheet title with an explicit
per-kind lookup map. The null-kind fallback keeps the prior
ternary's mood label, and the sheet stays closed in that state so
the title is never read.

(cherry picked from commit 856e620754753570e0d4ce8d6ce982778e929b75)
This commit is contained in:
Marc-André Bombeck committed 2026-06-05 01:17:57 +02:00
1 parent ac4d84f386
commit 34061236e7
1 file changed
+10 -10
+10 -10
View File
@@ -7,7 +7,6 @@ import { MeasurementForm } from "@/components/measurements/measurement-form";
import { MoodForm } from "@/components/mood/mood-form";
import { MedicationIntakeQuickAdd } from "@/components/dashboard/medication-intake-quick-add";
import { ResponsiveSheet } from "@/components/ui/responsive-sheet";
import { cn } from "@/lib/utils";
import { useTranslations } from "@/lib/i18n/context";
/**
@@ -80,12 +79,15 @@ export function CapturePicker({ open, onOpenChange }: CapturePickerProps) {
},
];
const formTitle =
kind === "measurement"
? t("measurements.addMeasurement")
: kind === "medication"
? t("nav.capture.medication")
: t("mood.addEntry");
const formTitleByKind: Record<CaptureKind, string> = {
measurement: t("measurements.addMeasurement"),
medication: t("nav.capture.medication"),
mood: t("mood.addEntry"),
};
// `kind === null` keeps the form sheet closed (the title is unread then);
// the mood label is the harmless default, matching the prior ternary's
// else branch.
const formTitle = kind ? formTitleByKind[kind] : t("mood.addEntry");
return (
<>
@@ -103,9 +105,7 @@ export function CapturePicker({ open, onOpenChange }: CapturePickerProps) {
type="button"
data-testid={`capture-picker-${opt.kind}`}
onClick={() => chooseKind(opt.kind)}
className={cn(
"border-border hover:bg-accent/40 focus-visible:ring-ring/50 flex min-h-14 items-center gap-3 rounded-lg border px-4 py-3 text-left transition-colors focus-visible:outline-none focus-visible:ring-2",
)}
className="border-border hover:bg-accent/40 focus-visible:ring-ring/50 flex min-h-14 items-center gap-3 rounded-lg border px-4 py-3 text-left transition-colors focus-visible:outline-none focus-visible:ring-2"
>
<span className="bg-primary/10 text-primary flex h-9 w-9 shrink-0 items-center justify-center rounded-full">
<opt.icon className="h-5 w-5" aria-hidden="true" />