refactor: add useFormatters hook to reduce boilerplate across 14 components
Created useFormatters() combining useWeightUnit + useCurrency + formatWeight/formatPrice into a single hook returning weight(grams) and price(cents) bound functions plus raw unit and currency values. Updated all 14 consumer files to use the new hook, removing the repeated 4-import + 2-hook-call pattern from each. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import { Reorder, useDragControls } from "framer-motion";
|
||||
import { useCurrency } from "../hooks/useCurrency";
|
||||
import { useWeightUnit } from "../hooks/useWeightUnit";
|
||||
import { formatPrice, formatWeight } from "../lib/formatters";
|
||||
import { useFormatters } from "../hooks/useFormatters";
|
||||
import { LucideIcon } from "../lib/iconData";
|
||||
import { useUIStore } from "../stores/uiStore";
|
||||
import { StatusBadge } from "./StatusBadge";
|
||||
@@ -53,8 +51,7 @@ export function CandidateListItem({
|
||||
onStatusChange,
|
||||
}: CandidateListItemProps) {
|
||||
const controls = useDragControls();
|
||||
const unit = useWeightUnit();
|
||||
const currency = useCurrency();
|
||||
const { weight, price } = useFormatters();
|
||||
const openCandidateEditPanel = useUIStore((s) => s.openCandidateEditPanel);
|
||||
const openConfirmDeleteCandidate = useUIStore(
|
||||
(s) => s.openConfirmDeleteCandidate,
|
||||
@@ -113,12 +110,12 @@ export function CandidateListItem({
|
||||
<div className="flex flex-wrap gap-1.5 mt-1">
|
||||
{candidate.weightGrams != null && (
|
||||
<span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-blue-50 text-blue-400">
|
||||
{formatWeight(candidate.weightGrams, unit)}
|
||||
{weight(candidate.weightGrams)}
|
||||
</span>
|
||||
)}
|
||||
{candidate.priceCents != null && (
|
||||
<span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-green-50 text-green-500">
|
||||
{formatPrice(candidate.priceCents, currency)}
|
||||
{price(candidate.priceCents)}
|
||||
</span>
|
||||
)}
|
||||
<span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-gray-50 text-gray-600">
|
||||
|
||||
Reference in New Issue
Block a user