From 40f0e687f22e044153c22c39201fd7c7247fa319 Mon Sep 17 00:00:00 2001 From: myrmidex Date: Sat, 2 May 2026 20:32:53 +0200 Subject: [PATCH] 41 - Unify InlineForm callbacks to onSuccess(type) --- .../js/components/Display/InlineForm.tsx | 32 ++++++++----------- resources/js/pages/dashboard.tsx | 8 +++-- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/resources/js/components/Display/InlineForm.tsx b/resources/js/components/Display/InlineForm.tsx index 1254e81..1536d83 100644 --- a/resources/js/components/Display/InlineForm.tsx +++ b/resources/js/components/Display/InlineForm.tsx @@ -3,14 +3,14 @@ import AddMilestoneForm from '@/components/Milestones/AddMilestoneForm'; import UpdatePriceForm from '@/components/Pricing/UpdatePriceForm'; import { cn } from '@/lib/utils'; +type FormType = 'purchase' | 'milestone' | 'price'; + interface InlineFormProps { - type: 'purchase' | 'milestone' | 'price' | null; + type: FormType | null; unit?: string; priceTrackingEnabled?: boolean; onClose: () => void; - onPurchaseSuccess?: () => void; - onMilestoneSuccess?: () => void; - onPriceSuccess?: () => void; + onSuccess?: (type: FormType) => void; className?: string; } @@ -19,13 +19,16 @@ export default function InlineForm({ unit = 'units', priceTrackingEnabled = false, onClose, - onPurchaseSuccess, - onMilestoneSuccess, - onPriceSuccess, + onSuccess, className, }: InlineFormProps) { if (!type) return null; + const handleSuccess = () => { + if (onSuccess) onSuccess(type); + onClose(); + }; + return (
{ - if (onPurchaseSuccess) onPurchaseSuccess(); - onClose(); - }} + onSuccess={handleSuccess} onCancel={onClose} /> ) : type === 'milestone' ? ( { - if (onMilestoneSuccess) onMilestoneSuccess(); - onClose(); - }} + onSuccess={handleSuccess} onCancel={onClose} /> ) : ( { - if (onPriceSuccess) onPriceSuccess(); - onClose(); - }} + onSuccess={handleSuccess} onCancel={onClose} /> )} diff --git a/resources/js/pages/dashboard.tsx b/resources/js/pages/dashboard.tsx index 3eb8e32..beac959 100644 --- a/resources/js/pages/dashboard.tsx +++ b/resources/js/pages/dashboard.tsx @@ -292,9 +292,11 @@ export default function Dashboard() { unit={tracker?.unit} priceTrackingEnabled={priceTrackingEnabled} onClose={() => setActiveForm(null)} - onPurchaseSuccess={handlePurchaseSuccess} - onMilestoneSuccess={handleMilestoneSuccess} - onPriceSuccess={handlePriceSuccess} + onSuccess={(type) => { + if (type === 'purchase') handlePurchaseSuccess(); + else if (type === 'milestone') handleMilestoneSuccess(); + else if (type === 'price') handlePriceSuccess(); + }} />