-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add banner for payment failure
- Loading branch information
Showing
7 changed files
with
171 additions
and
57 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
51 changes: 51 additions & 0 deletions
51
sdks/js/packages/core/react/components/organization/billing/payment-issue.tsx
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,51 @@ | ||
import { Flex, Image, Button, Text } from '@raystack/apsara'; | ||
import Skeleton from 'react-loading-skeleton'; | ||
import { INVOICE_STATES, SUBSCRIPTION_STATES } from '~/react/utils/constants'; | ||
import { V1Beta1Invoice, V1Beta1Subscription } from '~/src'; | ||
import billingStyles from './billing.module.css'; | ||
import exclamationTriangle from '~/react/assets/exclamation-triangle.svg'; | ||
import dayjs from 'dayjs'; | ||
import { useCallback } from 'react'; | ||
|
||
interface PaymentIssueProps { | ||
isLoading?: boolean; | ||
subscription?: V1Beta1Subscription; | ||
invoices: V1Beta1Invoice[]; | ||
} | ||
|
||
export function PaymentIssue({ | ||
isLoading, | ||
subscription, | ||
invoices | ||
}: PaymentIssueProps) { | ||
const isPastDue = subscription?.state === SUBSCRIPTION_STATES.PAST_DUE; | ||
const openInvoices = invoices | ||
.filter(inv => inv.state === INVOICE_STATES.OPEN) | ||
.sort((a, b) => (dayjs(a.due_date).isAfter(b.due_date) ? -1 : 1)); | ||
|
||
const onRetryPayment = useCallback(() => { | ||
window.location.href = openInvoices[0]?.hosted_url || ''; | ||
}, [openInvoices]); | ||
|
||
return isLoading ? ( | ||
<Skeleton /> | ||
) : isPastDue ? ( | ||
<Flex className={billingStyles.paymentIssueBox} justify={'between'}> | ||
<Flex gap="small" className={billingStyles.flex1}> | ||
{/* @ts-ignore */} | ||
<Image src={exclamationTriangle} alt="Exclamation Triangle" /> | ||
<Text className={billingStyles.paymentIssueText}> | ||
Your Payment is due. Please try again | ||
</Text> | ||
</Flex> | ||
<Flex className={billingStyles.flex1} justify={'end'}> | ||
<Button | ||
className={billingStyles.retryPaymentBtn} | ||
onClick={onRetryPayment} | ||
> | ||
Retry | ||
</Button> | ||
</Flex> | ||
</Flex> | ||
) : null; | ||
} |
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 |
---|---|---|
@@ -1 +1,12 @@ | ||
export const DEFAULT_DATE_FORMAT = 'DD MMM YYYY'; | ||
|
||
export const SUBSCRIPTION_STATES = { | ||
ACTIVE: 'active', | ||
PAST_DUE: 'past_due' | ||
} as const; | ||
|
||
export const INVOICE_STATES = { | ||
OPEN: 'open', | ||
PAID: 'paid', | ||
DRAFT: 'draft' | ||
} as const; |
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