Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
suejung-sentry committed Jan 20, 2025
1 parent 0f3d8bb commit 27c7e37
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import { USBankAccountSchema } from 'services/account'

interface BankInformationProps {
usBankAccount: z.infer<typeof USBankAccountSchema>
nextBillingDisplayDate: string | null
}

function BankInformation({ usBankAccount }: BankInformationProps) {
function BankInformation({
usBankAccount,
nextBillingDisplayDate,
}: BankInformationProps) {
return (
<div className="flex flex-col gap-2">
<div className="flex gap-1">
<div className="flex flex-col gap-3">
<div className="flex gap-2">
<img src={bankLogo} alt="bank logo" />
<div className="ml-1 flex flex-col self-center">
<b>
Expand All @@ -20,6 +24,15 @@ function BankInformation({ usBankAccount }: BankInformationProps) {
</b>
</div>
</div>
{nextBillingDisplayDate && (
<p className="text-sm text-ds-gray-quinary">
Your next billing date is{' '}
<span className="text-ds-gray-octonary">
{nextBillingDisplayDate}
</span>
.
</p>
)}
</div>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ CardInformation.propTypes = {
expMonth: PropTypes.number.isRequired,
expYear: PropTypes.number.isRequired,
}).isRequired,
openForm: PropTypes.func.isRequired,
}

export default CardInformation
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import PropTypes from 'prop-types'
import { useState } from 'react'

import { subscriptionDetailType } from 'services/account'
import { formatTimestampToCalendarDate } from 'shared/utils/billing'
import A from 'ui/A'
import Button from 'ui/Button'
import Icon from 'ui/Icon'
Expand All @@ -14,8 +15,15 @@ function PaymentCard({ subscriptionDetail, provider, owner }) {
const card = subscriptionDetail?.defaultPaymentMethod?.card
const usBankAccount = subscriptionDetail?.defaultPaymentMethod?.usBankAccount

let nextBillingDisplayDate = null
if (!subscriptionDetail?.cancelAtPeriodEnd) {
nextBillingDisplayDate = formatTimestampToCalendarDate(
subscriptionDetail.currentPeriodEnd
)
}

Check failure on line 23 in src/pages/PlanPage/subRoutes/CurrentOrgPlan/BillingDetails/PaymentCard/PaymentCard.jsx

View workflow job for this annotation

GitHub Actions / Test Runner #2 - Vitest

src/pages/PlanPage/subRoutes/CurrentOrgPlan/BillingDetails/PaymentCard/PaymentCard.test.jsx > PaymentCard > when the user doesn't have any subscriptionDetail > renders the set payment method message

TypeError: Cannot read properties of null (reading 'currentPeriodEnd') ❯ PaymentCard src/pages/PlanPage/subRoutes/CurrentOrgPlan/BillingDetails/PaymentCard/PaymentCard.jsx:23:3 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7 ❯ recoverFromConcurrentError node_modules/react-dom/cjs/react-dom.development.js:25889:20 ❯ performConcurrentWorkOnRoot node_modules/react-dom/cjs/react-dom.development.js:25789:22

return (
<div className="flex flex-col gap-2 border-t p-4">
<div className="flex flex-col gap-3 border-t p-4">
<div className="flex justify-between">
<h4 className="font-semibold">Payment method</h4>
{!isFormOpen && (
Expand All @@ -38,7 +46,10 @@ function PaymentCard({ subscriptionDetail, provider, owner }) {
) : card ? (
<CardInformation card={card} subscriptionDetail={subscriptionDetail} />
) : usBankAccount ? (
<BankInformation usBankAccount={usBankAccount} />
<BankInformation
usBankAccount={usBankAccount}
nextBillingDisplayDate={nextBillingDisplayDate}
/>
) : (
<div className="flex flex-col gap-4 text-ds-gray-quinary">
<p className="mt-4">
Expand All @@ -61,7 +72,7 @@ function PaymentCard({ subscriptionDetail, provider, owner }) {
}

PaymentCard.propTypes = {
subscriptionDetail: PropTypes.oneOf([subscriptionDetailType, null]),
subscriptionDetail: subscriptionDetailType,
provider: PropTypes.string.isRequired,
owner: PropTypes.string.isRequired,
}
Expand Down
14 changes: 9 additions & 5 deletions src/services/account/propTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ export const subscriptionDetailType = PropType.shape({
latestInvoice: invoicePropType,
defaultPaymentMethod: PropType.shape({
card: PropType.shape({
brand: PropType.string.isRequired,
expMonth: PropType.number.isRequired,
expYear: PropType.number.isRequired,
last4: PropType.string.isRequired,
}).isRequired,
brand: PropType.string,
expMonth: PropType.number,
expYear: PropType.number,
last4: PropType.string,
}),
usBankAccount: PropType.shape({
bankName: PropType.string,
last4: PropType.string,
}),
}),
trialEnd: PropType.number,
})
Expand Down

0 comments on commit 27c7e37

Please sign in to comment.