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 UpdatePriceForm from '@/components/Pricing/UpdatePriceForm';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
type FormType = 'purchase' | 'milestone' | 'price';
|
||||||
|
|
||||||
interface InlineFormProps {
|
interface InlineFormProps {
|
||||||
type: 'purchase' | 'milestone' | 'price' | null;
|
type: FormType | null;
|
||||||
unit?: string;
|
unit?: string;
|
||||||
priceTrackingEnabled?: boolean;
|
priceTrackingEnabled?: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
onPurchaseSuccess?: () => void;
|
onSuccess?: (type: FormType) => void;
|
||||||
onMilestoneSuccess?: () => void;
|
|
||||||
onPriceSuccess?: () => void;
|
|
||||||
className?: string;
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -19,13 +19,16 @@ export default function InlineForm({
|
||||||
unit = 'units',
|
unit = 'units',
|
||||||
priceTrackingEnabled = false,
|
priceTrackingEnabled = false,
|
||||||
onClose,
|
onClose,
|
||||||
onPurchaseSuccess,
|
onSuccess,
|
||||||
onMilestoneSuccess,
|
|
||||||
onPriceSuccess,
|
|
||||||
className,
|
className,
|
||||||
}: InlineFormProps) {
|
}: InlineFormProps) {
|
||||||
if (!type) return null;
|
if (!type) return null;
|
||||||
|
|
||||||
|
const handleSuccess = () => {
|
||||||
|
if (onSuccess) onSuccess(type);
|
||||||
|
onClose();
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
|
|
@ -40,26 +43,17 @@ export default function InlineForm({
|
||||||
<AddEntryForm
|
<AddEntryForm
|
||||||
unit={unit}
|
unit={unit}
|
||||||
priceTrackingEnabled={priceTrackingEnabled}
|
priceTrackingEnabled={priceTrackingEnabled}
|
||||||
onSuccess={() => {
|
onSuccess={handleSuccess}
|
||||||
if (onPurchaseSuccess) onPurchaseSuccess();
|
|
||||||
onClose();
|
|
||||||
}}
|
|
||||||
onCancel={onClose}
|
onCancel={onClose}
|
||||||
/>
|
/>
|
||||||
) : type === 'milestone' ? (
|
) : type === 'milestone' ? (
|
||||||
<AddMilestoneForm
|
<AddMilestoneForm
|
||||||
onSuccess={() => {
|
onSuccess={handleSuccess}
|
||||||
if (onMilestoneSuccess) onMilestoneSuccess();
|
|
||||||
onClose();
|
|
||||||
}}
|
|
||||||
onCancel={onClose}
|
onCancel={onClose}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<UpdatePriceForm
|
<UpdatePriceForm
|
||||||
onSuccess={() => {
|
onSuccess={handleSuccess}
|
||||||
if (onPriceSuccess) onPriceSuccess();
|
|
||||||
onClose();
|
|
||||||
}}
|
|
||||||
onCancel={onClose}
|
onCancel={onClose}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -292,9 +292,11 @@ export default function Dashboard() {
|
||||||
unit={tracker?.unit}
|
unit={tracker?.unit}
|
||||||
priceTrackingEnabled={priceTrackingEnabled}
|
priceTrackingEnabled={priceTrackingEnabled}
|
||||||
onClose={() => setActiveForm(null)}
|
onClose={() => setActiveForm(null)}
|
||||||
onPurchaseSuccess={handlePurchaseSuccess}
|
onSuccess={(type) => {
|
||||||
onMilestoneSuccess={handleMilestoneSuccess}
|
if (type === 'purchase') handlePurchaseSuccess();
|
||||||
onPriceSuccess={handlePriceSuccess}
|
else if (type === 'milestone') handleMilestoneSuccess();
|
||||||
|
else if (type === 'price') handlePriceSuccess();
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue