Skip to content

Commit

Permalink
switched to useAccount() query
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh-akamai committed Nov 15, 2024
1 parent da1c100 commit 6670b95
Showing 1 changed file with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,22 @@ import { useHistory } from 'react-router-dom';

import { Button } from 'src/components/Button/Button';
import { DismissibleBanner } from 'src/components/DismissibleBanner/DismissibleBanner';
import { useAllPaymentMethodsQuery } from 'src/queries/account/payment';
import { useAccount } from 'src/queries/account/account';
import { isCreditCardExpired } from 'src/utilities/creditCard';

import type { PaymentMethod } from '@linode/api-v4/lib/account/types';

export const CreditCardExpiredBanner = () => {
const history = useHistory();

const { data: paymentMethods } = useAllPaymentMethodsQuery();
const { data: account } = useAccount();

if (!paymentMethods || paymentMethods?.length == 0) {
return;
if (!account) {
return null;
}

const isExpired = paymentMethods.some((paymentMethod: PaymentMethod) => {
const ccExpiry =
paymentMethod.type === 'credit_card' ? paymentMethod.data.expiry : null;
return ccExpiry && isCreditCardExpired(ccExpiry);
});
const isExpired = Boolean(
account?.credit_card?.expiry &&
isCreditCardExpired(account?.credit_card.expiry)
);

if (!isExpired) {
return;
Expand All @@ -39,7 +36,7 @@ export const CreditCardExpiredBanner = () => {
</Button>
}
important
preferenceKey={'credit card expired'}
preferenceKey={'credit-card-expired'}
variant="error"
>
<Typography variant="body1">
Expand Down

0 comments on commit 6670b95

Please sign in to comment.