41 - Unify InlineForm callbacks to onSuccess(type)
This commit is contained in:
parent
941cd60680
commit
40f0e687f2
2 changed files with 18 additions and 22 deletions
|
|
@ -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 (
|
||||
<div
|
||||
className={cn(
|
||||
|
|
@ -40,26 +43,17 @@ export default function InlineForm({
|
|||
<AddEntryForm
|
||||
unit={unit}
|
||||
priceTrackingEnabled={priceTrackingEnabled}
|
||||
onSuccess={() => {
|
||||
if (onPurchaseSuccess) onPurchaseSuccess();
|
||||
onClose();
|
||||
}}
|
||||
onSuccess={handleSuccess}
|
||||
onCancel={onClose}
|
||||
/>
|
||||
) : type === 'milestone' ? (
|
||||
<AddMilestoneForm
|
||||
onSuccess={() => {
|
||||
if (onMilestoneSuccess) onMilestoneSuccess();
|
||||
onClose();
|
||||
}}
|
||||
onSuccess={handleSuccess}
|
||||
onCancel={onClose}
|
||||
/>
|
||||
) : (
|
||||
<UpdatePriceForm
|
||||
onSuccess={() => {
|
||||
if (onPriceSuccess) onPriceSuccess();
|
||||
onClose();
|
||||
}}
|
||||
onSuccess={handleSuccess}
|
||||
onCancel={onClose}
|
||||
/>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in a new issue