Skip to content

Commit

Permalink
fix: close form modal after adding payment method
Browse files Browse the repository at this point in the history
  • Loading branch information
rohan-chaturvedi committed Nov 29, 2024
1 parent 80fe804 commit 53caeef
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,9 @@ const AddPaymentMethodForm = ({ onSuccess }: { onSuccess: () => void }) => {
}}
/>
</div>
<div className="text-neutral-500 text-xs">Powered by Stripe</div>
{error && <div className="text-red-500 text-sm">{error}</div>}
{success && (
<div className="text-emerald-500 text-sm">Payment method added successfully!</div>
)}

<div className="flex justify-end">
<Button variant="primary" type="submit" disabled={!stripe} isLoading={loading}>
<FaPlus /> Add Payment Method
Expand All @@ -104,6 +103,12 @@ const AddPaymentMethodForm = ({ onSuccess }: { onSuccess: () => void }) => {

export const AddPaymentMethodDialog = ({ onSuccess }: { onSuccess: () => void }) => {
const dialogRef = useRef<{ closeModal: () => void }>(null)

const handleSuccess = () => {
dialogRef.current?.closeModal()
onSuccess()
}

return (
<GenericDialog
title="Add a payment method"
Expand All @@ -116,7 +121,7 @@ export const AddPaymentMethodDialog = ({ onSuccess }: { onSuccess: () => void })
ref={dialogRef}
>
<Elements stripe={stripePromise}>
<AddPaymentMethodForm onSuccess={onSuccess} />
<AddPaymentMethodForm onSuccess={handleSuccess} />
</Elements>
</GenericDialog>
)
Expand Down

0 comments on commit 53caeef

Please sign in to comment.