-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add PaymentRequiredToast for 402 error handling
- Loading branch information
1 parent
7097812
commit b15abd5
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useState } from "react"; | ||
import { Dialog } from "@/components/Dialog"; | ||
import { ButtonLoadingIndicator } from "@/components/Indicators/ButtonLoadingIndicator"; | ||
import { stripeService } from "@/services/stripeService"; | ||
import type { ToastContentProps } from "react-toastify"; | ||
|
||
export const PaymentRequiredToast = ({ closeToast }: PaymentRequiredToastProps) => { | ||
const { isDialogVisible, closeDialog } = Dialog.use(true); | ||
const [showLoading, setShowLoading] = useState(false); | ||
|
||
const handleClose = () => { | ||
closeDialog(); | ||
closeToast(); | ||
}; | ||
|
||
const handleAccept = async () => { | ||
setShowLoading(true); | ||
await stripeService.getCustomerPortalLink(); | ||
setShowLoading(false); | ||
handleClose(); | ||
}; | ||
|
||
const handleCancel = () => { | ||
handleClose(); | ||
}; | ||
|
||
return ( | ||
<Dialog | ||
isVisible={isDialogVisible} | ||
title="Payment Required" | ||
message="Your account is inactive - please update your payment method to continue." | ||
acceptLabel={showLoading ? <ButtonLoadingIndicator /> : "OK"} | ||
handleAccept={handleAccept} | ||
handleCancel={handleCancel} | ||
showCancelButton={false} | ||
/> | ||
); | ||
}; | ||
|
||
export type PaymentRequiredToastProps = Pick<ToastContentProps, "closeToast">; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./ToastContainer"; | ||
export * from "./PaymentRequiredToast"; |