Skip to content

Commit

Permalink
feat: add PaymentRequiredToast for 402 error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-anderson committed Feb 20, 2024
1 parent 7097812 commit b15abd5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/components/Alerts/PaymentRequiredToast.tsx
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">;
2 changes: 2 additions & 0 deletions src/components/Alerts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./ToastContainer";
export * from "./PaymentRequiredToast";

0 comments on commit b15abd5

Please sign in to comment.