Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: getlago/lago-front
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ca63148f4ff8572b367db7692c56f4b511162c15
Choose a base ref
...
head repository: getlago/lago-front
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 17a4eb679cc38ba30049db6f0da603f1ffe74385
Choose a head ref
  • 6 commits
  • 161 files changed
  • 3 contributors

Commits on Jan 30, 2025

  1. feat(CustomerRevamp): Refactor customer subscription list, customer c…

    …oupons and customer details (#1997)
    
    * feat(icons): add arrow-indent icon
    
    * chore(translations): add translations
    
    * chore(graphql): generate types
    
    * feat(TimezoneDate): add className prop
    
    * feat(Status): add support for downgrade and scheduled statuses
    
    * feat(icons): add arrow-indent icon
    
    * feat(layoutsSection): create reusable page title component
    
    * feat(CouponCaption): add className prop
    
    * refactor(CustomerPage): unify section heights
    
    * refactor(CustomerCoupons): list -> table
    
    * refactor(CustomerSubscriptionsList): list -> table
    
    * refactor(CustomerMainInfos): always show all the customer details
    
    * refactor(CustomerOverview): re-use PageSectionTitle
    
    * refactor(CustomerDetails): replace customer details drawer with tab
    
    * fix: linting
    
    * fix(translations): remove unused translations
    
    * feat(translations): add other languages
    
    * refactor(Chip): remove clsx dependency
    
    * refactor(CustomerSubscriptionsList): remove unused fragment
    
    * fix(Status): fix types
    
    * refactor(CustomerSubscriptionsList): add padding to rows
    
    * delete: remove SubscriptionLine
    
    * refactor(CustomerSubscriptionsList): update graphql
    
    * chore(graphql): generate types
    
    * refactor(CustomerSubscriptionsList): update fragment for next subscription
    
    * chore(translations): add translations
    
    * feat(CustomerDetails): update label
    
    * feat(TimezoneDate): add typographyClassName prop
    
    * refactor(CustomerSubscriptionsList): scheduled status. column order. date border
    
    * chore(graphql): generate types
    
    * fix(CustomerSubscriptionList): enable clicking on downgrade. fix downgrade status
    
    * fix: add table paddings
    
    * fix(CustomerSubscriptionList): pass subscription status to terminate dialog
    
    * feat: move customer overview to the invoices tab
    
    * chore(translations): add translations
    
    * feat(PageSectionTitle): add support for a custom action
    
    * refactor(CustomerWalletsList): unify title
    
    * refactor(CustomerUsage): unify title
    
    * refactor(CustomerOverview): add subtitle
    
    * refactor(CustomerInvoicesTab): improve logic clarity. unify design
    
    * refactor(Settings): update spacing
    
    * chore(translations): add translations
    
    * refactor(CustomerInvoicesTab): do not show overview for 0 invoices. improve typography for 0 invoices
    
    * feat(tailwind): add first-child helper
    
    * chore(translations): add translations
    
    * refactor(CustomerMainInfos): separate into sections
    
    * refactor(CustomerMainInfos): render metadata and connections conditionally
    
    * refactor(CustomerMainInfos): do not render border for last element
    
    * chore(translations): add translations
    
    * feat(CreditNotesTable): add filtersContainerClassName prop
    
    * fix(CustomerCreditNotesList): remove legacy ScrollContainer
    
    * refactor(CreditNotesTable): remove legacy onKeyDown
    
    * refactor(CustomerCreditNotesList): remove unused import
    
    * fix(e2e): add missing data-test attributes
    
    * fix(CustomerSettings): remove bottom padding
    
    * chore(translations): update translations
    
    * fix(CustomerMainInfos): render billing information conditionally
    
    * chore(translations): update translations
    
    * fix(navigation): navigate to information tab after save
    
    * refactor(overdueBalance): refresh from card
    
    * refactor(useCreateEditCustomer): redirect to overview
    
    * refactor(loadingState): improve loading state
    
    * refactor(CustomerInvoicesTab): loading state
    
    * fix(translations): remove unused translations
    stephenlago99 authored Jan 30, 2025
    Copy the full SHA
    bae94f8 View commit details
  2. Copy the full SHA
    a2c3b39 View commit details
  3. feat: allow to add a fee to an invoice

    ansmonjol committed Jan 30, 2025
    Copy the full SHA
    efaf411 View commit details

Commits on Jan 31, 2025

  1. Copy the full SHA
    bc000e2 View commit details
  2. bug: prevent side effect on slice chaining

    ansmonjol committed Jan 31, 2025
    Copy the full SHA
    dbe90dc View commit details
  3. chore: enforce vscode import preference in settings (#2008)

    keellyp authored Jan 31, 2025
    Copy the full SHA
    17a4eb6 View commit details
Showing with 6,496 additions and 2,645 deletions.
  1. +3 −1 .vscode/settings.json
  2. +1 −2 src/App.tsx
  3. +1 −3 src/components/GenericPlaceholder.tsx
  4. +19 −8 src/components/OverviewCard.tsx
  5. +5 −2 src/components/TimezoneDate.tsx
  6. +1 −2 src/components/__tests__/WarningDialog.test.tsx
  7. +1 −2 src/components/auth/GoogleAuthButton.tsx
  8. +103 −84 src/components/coupons/CouponCaption.tsx
  9. +1 −2 src/components/coupons/__tests__/CouponCaption.test.tsx
  10. +187 −224 src/components/creditNote/CreditNotesTable.tsx
  11. +3 −5 src/components/creditNote/__tests__/utils.test.ts
  12. +69 −61 src/components/customers/CustomerCreditNotesList.tsx
  13. +11 −9 src/components/customers/CustomerInvoicesList.tsx
  14. +92 −64 src/components/customers/CustomerInvoicesTab.tsx
  15. +490 −438 src/components/customers/CustomerMainInfos.tsx
  16. +40 −42 src/components/customers/CustomerSettings.tsx
  17. +1 −2 src/components/customers/DeleteCustomerVatRateDialog.tsx
  18. +1 −2 src/components/customers/EditCustomerDunningCampaignDialog.tsx
  19. +1 −2 src/components/customers/EditCustomerInvoiceCustomSectionsDialog.tsx
  20. +1 −2 src/components/customers/__tests__/EditCustomerVatRateDialog.test.tsx
  21. +61 −14 src/components/customers/createCustomer/ExternalAppsAccordion/PaymentProvidersAccordion.tsx
  22. +58 −76 src/components/customers/overview/CustomerCoupons.tsx
  23. +18 −31 src/components/customers/overview/CustomerOverview.tsx
  24. +333 −91 src/components/customers/overview/CustomerSubscriptionsList.tsx
  25. +0 −149 src/components/customers/subscriptions/SubscriptionItem.tsx
  26. +0 −241 src/components/customers/subscriptions/SubscriptionLine.tsx
  27. +4 −5 src/components/customers/subscriptions/__tests__/SubscriptionDatesOffsetHelperComponent.test.tsx
  28. +13 −11 src/components/customers/usage/CustomerUsage.tsx
  29. +3 −2 src/components/designSystem/Chip.tsx
  30. +2 −0 src/components/designSystem/Icon/mapping.tsx
  31. +1 −1 src/components/designSystem/NavigationTab.tsx
  32. +3 −1 src/components/designSystem/Status.tsx
  33. +1 −2 src/components/developers/RotateApiKeyDialog.tsx
  34. +1 −2 src/components/emails/DunningEmail.tsx
  35. +1 −2 src/components/exports/ExportDialog.tsx
  36. +6 −2 src/components/form/AmountInput/AmountInput.tsx
  37. +1 −3 src/components/form/ButtonSelector/TabButton.tsx
  38. +2 −2 src/components/form/ComboBox/types.ts
  39. +4 −5 src/components/graphs/Gross.tsx
  40. +6 −7 src/components/graphs/Invoices.tsx
  41. +2 −3 src/components/graphs/MonthSelectorDropdown.tsx
  42. +4 −5 src/components/graphs/Mrr.tsx
  43. +6 −7 src/components/graphs/Usage.tsx
  44. +3 −4 src/components/graphs/__tests__/Gross.test.ts
  45. +4 −5 src/components/graphs/__tests__/Invoices.test.ts
  46. +3 −4 src/components/graphs/__tests__/Mrr.test.ts
  47. +3 −4 src/components/graphs/__tests__/Usage.test.ts
  48. +3 −4 src/components/graphs/__tests__/utils.test.ts
  49. +1 −2 src/components/graphs/utils.ts
  50. +1 −2 src/components/invoices/InvoiceCustomerInfos.tsx
  51. +13 −14 src/components/invoices/InvoicesList.tsx
  52. +7 −1 src/components/invoices/details/DeleteAdjustedFeeDialog.tsx
  53. +429 −208 src/components/invoices/details/EditFeeDrawer.tsx
  54. +44 −19 src/components/invoices/details/InvoiceDetailsTable.tsx
  55. +3 −1 src/components/invoices/details/InvoiceDetailsTableBodyLine.tsx
  56. +10 −2 src/components/invoices/details/InvoiceDetailsTableHeader.tsx
  57. +52 −51 src/components/invoices/details/InvoiceFeeAdvanceDetailsTable.tsx
  58. +52 −51 src/components/invoices/details/InvoiceFeeArrearsDetailsTable.tsx
  59. +1 −2 src/components/invoices/details/__tests__/InvoiceDetailsTableBodyLine.test.ts
  60. +466 −0 src/components/invoices/details/__tests__/fixture.ts
  61. +170 −0 src/components/invoices/details/__tests__/utils.test.ts
  62. +108 −0 src/components/invoices/details/utils.ts
  63. +64 −0 src/components/layouts/Drawer.tsx
  64. +52 −0 src/components/layouts/Section.tsx
  65. +4 −5 src/components/layouts/Settings.tsx
  66. +4 −5 src/components/plans/ChargeAccordion.tsx
  67. +2 −3 src/components/plans/ChargeFilter.tsx
  68. +1 −2 src/components/plans/ChargePercentage.tsx
  69. +10 −8 src/components/plans/ChargeWrapperSwitch.tsx
  70. +2 −3 src/components/plans/ChargesSection.tsx
  71. +3 −4 src/components/plans/CommitmentsSection.tsx
  72. +7 −5 src/components/plans/DynamicCharge.tsx
  73. +1 −2 src/components/plans/FixedFeeSection.tsx
  74. +1 −3 src/components/plans/PackageCharge.tsx
  75. +2 −4 src/components/plans/StandardCharge.tsx
  76. +3 −4 src/components/plans/__tests__/ChargeAccordion.test.tsx
  77. +1 −2 src/components/plans/__tests__/utils.test.ts
  78. +1 −2 src/components/plans/details/PlanDetailsAdvancedSettingsSection.tsx
  79. +2 −3 src/components/plans/details/PlanDetailsChargeWrapperSwitch.tsx
  80. +2 −4 src/components/plans/details/PlanDetailsChargesSection.tsx
  81. +1 −2 src/components/plans/details/PlanDetailsFixedFeeAccordion.tsx
  82. +1 −2 src/components/settings/LanguageSettingsButton.tsx
  83. +1 −2 src/components/settings/PreviewEmailLayout.tsx
  84. +2 −3 src/components/settings/dunnings/PreviewCampaignEmailDrawer.tsx
  85. +1 −2 src/components/settings/invoices/DeleteCustomSectionDialog.tsx
  86. +1 −2 src/components/settings/invoices/DeleteOrganizationVatRateDialog.tsx
  87. +4 −5 src/components/subscriptions/SubscriptionCurrentUsageTable.tsx
  88. +2 −3 src/components/subscriptions/SubscriptionDetailsOverview.tsx
  89. +2 −3 src/components/subscriptions/SubscriptionInformations.tsx
  90. +5 −6 src/components/subscriptions/SubscriptionUsageLifetimeGraph.tsx
  91. +1 −2 src/components/subscriptions/__tests__/utils.test.ts
  92. +101 −104 src/components/wallets/CustomerWalletList.tsx
  93. +4 −6 src/components/wallets/WalletAccordion.tsx
  94. +4 −2 src/components/wallets/WalletTransactionListItem/__tests__/index.test.tsx
  95. +1 −1 src/core/apolloClient/__tests__/errorUtils.test.ts
  96. +1 −1 src/core/apolloClient/reactiveVars/authTokenVar.ts
  97. +1 −1 src/core/apolloClient/reactiveVars/customerPortalTokenVar.ts
  98. +1 −2 src/core/apolloClient/reactiveVars/duplicatePlanVar.ts
  99. +1 −2 src/core/apolloClient/reactiveVars/internationalizationVar.ts
  100. +1 −1 src/core/formats/__tests__/countryDataForCombobox.test.ts
  101. +2,666 −0 src/core/formats/__tests__/fixture.ts
  102. +1 −2 src/core/formats/__tests__/formatCreditNotesItems.test.ts
  103. +140 −45 src/core/formats/__tests__/formatInvoiceItemsMap.test.ts
  104. +3 −4 src/core/formats/__tests__/intlFormatNumber.test.ts
  105. +1 −1 src/core/formats/__tests__/obfuscate.test.ts
  106. +1 −2 src/core/formats/countryDataForCombobox.ts
  107. +13 −8 src/core/formats/formatInvoiceItemsMap.ts
  108. +5 −2 src/core/serializers/__tests__/serializeAmount.test.ts
  109. +1 −2 src/core/serializers/__tests__/serializeCreditNoteInput.test.ts
  110. +1 −2 src/core/serializers/__tests__/serializePlanInput.test.ts
  111. +1 −1 src/core/timezone/__tests__/config.test.ts
  112. +2 −4 src/core/timezone/utils.ts
  113. +1 −1 src/core/translations/__tests__/utils.test.ts
  114. +1 −1 src/core/utils/__tests__/copyToClipboard.test.ts
  115. +1 −1 src/core/utils/__tests__/responsiveProps.test.ts
  116. +1 −1 src/core/utils/__tests__/urlUtils.test.ts
  117. +1 −1 src/core/utils/downloadFiles.ts
  118. +1 −1 src/core/utils/featureFlags.ts
  119. +1 −2 src/formValidation/__tests__/chargeSchemaGraduated.test.ts
  120. +1 −2 src/formValidation/__tests__/chargeSchemaGraduatedPercentage.test.ts
  121. +1 −2 src/formValidation/__tests__/chargeSchemaPackage.test.ts
  122. +1 −2 src/formValidation/__tests__/chargeSchemaPercentage.test.ts
  123. +1 −2 src/formValidation/__tests__/chargeSchemaStandard.test.ts
  124. +1 −2 src/formValidation/__tests__/chargeSchemaVolume.test.ts
  125. +1 −2 src/formValidation/__tests__/feesSchema.test.ts
  126. +1 −1 src/formValidation/__tests__/metadataSchema.test.ts
  127. +137 −46 src/generated/graphql.tsx
  128. +2 −3 src/hooks/__tests__/useCreateCreditNote.test.ts
  129. +1 −2 src/hooks/__tests__/useDebouncedSearch.test.ts
  130. +1 −2 src/hooks/__tests__/usePermissions.test.ts
  131. +1 −2 src/hooks/core/__tests__/useInternationalization.test.tsx
  132. +1 −2 src/hooks/core/__tests__/useLocationHistory.test.ts
  133. +2 −3 src/hooks/core/useLocationHistory.ts
  134. +1 −2 src/hooks/customer/useAddSubscription.tsx
  135. +2 −3 src/hooks/plans/__tests__/useChargeForm.test.tsx
  136. +4 −2 src/hooks/plans/__tests__/useGraduatedChargeForm.test.tsx
  137. +1 −2 src/hooks/plans/__tests__/useGraduatedPercentageChargeForm.test.tsx
  138. +1 −2 src/hooks/plans/__tests__/useVolumeChargeForm.test.tsx
  139. +1 −2 src/hooks/plans/useChargeForm.tsx
  140. +2 −3 src/hooks/plans/usePlanForm.tsx
  141. +1 −1 src/hooks/ui/__tests__/useListKeyNavigation.test.tsx
  142. +1 −1 src/hooks/ui/__tests__/useShortcuts.test.tsx
  143. +22 −6 src/hooks/useCreateEditCustomer.ts
  144. +1 −2 src/hooks/useCreateEditDunningCampaign.ts
  145. +1 −2 src/pages/CreateAddOn.tsx
  146. +1 −2 src/pages/CreateCoupon.tsx
  147. +152 −208 src/pages/CustomerDetails.tsx
  148. +6 −8 src/pages/WalletForm/WalletForm.tsx
  149. +1 −2 src/pages/WalletForm/components/SettingsCard.tsx
  150. +1 −2 src/pages/WalletForm/components/TopUpCard.tsx
  151. +1 −2 src/pages/auth/PortalInit.tsx
  152. +8 −0 src/public/icons/arrow-indent.svg
  153. +4 −5 src/test-utils.tsx
  154. +1 −0 tailwind.config.ts
  155. +39 −18 translations/base.json
  156. +3 −2 translations/de.json
  157. +3 −2 translations/es.json
  158. +3 −2 translations/fr.json
  159. +3 −2 translations/it.json
  160. +3 −2 translations/nb.json
  161. +3 −2 translations/sv.json
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -7,5 +7,7 @@
["cx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"],
["tw\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]
],
"eslint.useFlatConfig": true
"eslint.useFlatConfig": true,
"javascript.preferences.importModuleSpecifier": "non-relative",
"typescript.preferences.importModuleSpecifier": "non-relative",
}
3 changes: 1 addition & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -9,11 +9,10 @@ import { ErrorBoundary } from '~/components/ErrorBoundary'
import { RouteWrapper } from '~/components/RouteWrapper'
import { UserIdentifier } from '~/components/UserIdentifier'
import { envGlobalVar, initializeApolloClient, initializeTranslations } from '~/core/apolloClient'
import { AppEnvEnum } from '~/core/constants/globalTypes'
import { initializeYup } from '~/formValidation/initializeYup'
import { theme } from '~/styles'

import { AppEnvEnum } from './core/constants/globalTypes'

const App = () => {
const [client, setClient] = useState<ApolloClient<NormalizedCacheObject> | null>(null)
const { appEnv } = envGlobalVar()
4 changes: 1 addition & 3 deletions src/components/GenericPlaceholder.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { ReactNode } from 'react'

import { Button, ButtonVariant, Typography } from '~/components/designSystem'
import { tw } from '~/styles/utils'

import { Button, ButtonVariant } from './designSystem/Button'
import { Typography } from './designSystem/Typography'

export interface GenericPlaceholderProps {
className?: string
title?: string
27 changes: 19 additions & 8 deletions src/components/OverviewCard.tsx
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ interface OverviewCardProps {
caption: string
isAccentContent?: boolean
isLoading?: boolean
refresh?: () => void
}

export const OverviewCard: FC<OverviewCardProps> = ({
@@ -18,26 +19,36 @@ export const OverviewCard: FC<OverviewCardProps> = ({
caption,
isAccentContent,
isLoading,
refresh,
}) => {
return (
<Card className="flex-1 gap-4 p-6">
{isLoading ? (
<div className="h-22">
<Skeleton className="mb-8 w-22" variant="text" />
<Skeleton className="w-22" variant="text" />
<div className="flex flex-col gap-4">
<Skeleton className="w-50" variant="text" />
<Skeleton className="w-12" variant="text" />
</div>
</div>
) : (
<>
<div className="flex items-center gap-2">
<Typography variant="captionHl">{title}</Typography>
{tooltipContent && (
<Tooltip className="flex h-5 items-end" placement="top-start" title={tooltipContent}>
<Icon name="info-circle" />
</Tooltip>
)}
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<Typography variant="captionHl">{title}</Typography>

{tooltipContent && (
<Tooltip
className="flex h-5 items-end"
placement="top-start"
title={tooltipContent}
>
<Icon name="info-circle" />
</Tooltip>
)}
</div>

{refresh && <Icon name="reload" onClick={refresh} />}
</div>

<div className="flex flex-col gap-1">
7 changes: 5 additions & 2 deletions src/components/TimezoneDate.tsx
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import { formatDateToTZ, getTimezoneConfig } from '~/core/timezone'
import { TimezoneEnum } from '~/generated/graphql'
import { useInternationalization } from '~/hooks/core/useInternationalization'
import { useOrganizationInfos } from '~/hooks/useOrganizationInfos'
import { tw } from '~/styles/utils'

enum MainTimezoneEnum {
utc0 = 'utc0',
@@ -15,8 +16,9 @@ interface TimezoneDateProps {
mainDateFormat?: string
mainTimezone?: keyof typeof MainTimezoneEnum
customerTimezone?: TimezoneEnum
mainTypographyProps?: Pick<TypographyProps, 'variant' | 'color'>
mainTypographyProps?: Pick<TypographyProps, 'variant' | 'color' | 'className'>
className?: string
typographyClassName?: string
}

export const TimezoneDate = ({
@@ -25,6 +27,7 @@ export const TimezoneDate = ({
mainTimezone = MainTimezoneEnum.organization,
customerTimezone,
mainTypographyProps,
typographyClassName,
className,
}: TimezoneDateProps) => {
const { translate } = useInternationalization()
@@ -69,7 +72,7 @@ export const TimezoneDate = ({
placement="top-end"
>
<Typography
className="w-max border-b-2 border-dotted border-grey-400"
className={tw('w-max border-b-2 border-dotted border-grey-400', typographyClassName)}
color="grey700"
{...mainTypographyProps}
noWrap
3 changes: 1 addition & 2 deletions src/components/__tests__/WarningDialog.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { act, cleanup, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'

import { WarningDialog } from '~/components/WarningDialog'
import { render } from '~/test-utils'

import { WarningDialog } from '../WarningDialog'

const onContinueMock = jest.fn()

async function prepare() {
3 changes: 1 addition & 2 deletions src/components/auth/GoogleAuthButton.tsx
Original file line number Diff line number Diff line change
@@ -3,14 +3,13 @@ import { Stack } from '@mui/material'
import { useEffect, useState } from 'react'
import { useSearchParams } from 'react-router-dom'

import { Alert, Button, Typography } from '~/components/designSystem'
import { hasDefinedGQLError } from '~/core/apolloClient'
import { DOCUMENTATION_ENV_VARS } from '~/core/constants/externalUrls'
import { addValuesToUrlState } from '~/core/utils/urlUtils'
import { LagoApiError, useGetGoogleAuthUrlLazyQuery } from '~/generated/graphql'
import { useInternationalization } from '~/hooks/core/useInternationalization'

import { Alert, Button, Typography } from '../designSystem'

export type GoogleAuthModeEnum = 'login' | 'signup' | 'invite'

const getErrorKey = (errorCode: string): string => {
187 changes: 103 additions & 84 deletions src/components/coupons/CouponCaption.tsx
Original file line number Diff line number Diff line change
@@ -44,104 +44,123 @@ export interface CouponMixedType extends CouponItemFragment {
interface CouponCaptionProps {
coupon: CouponMixedType
variant?: TypographyProps['variant']
className?: string
}

export const CouponCaption = memo(({ coupon, variant = 'caption' }: CouponCaptionProps) => {
const { translate } = useInternationalization()
export const CouponCaption = memo(
({ coupon, variant = 'caption', className }: CouponCaptionProps) => {
const { translate } = useInternationalization()

const getCaption = () => {
const {
amountCurrency,
amountCents,
amountCentsRemaining,
percentageRate,
frequency,
frequencyDuration,
frequencyDurationRemaining,
} = coupon
const couponType = amountCents ? CouponTypeEnum.FixedAmount : CouponTypeEnum.Percentage
const getCaption = () => {
const {
amountCurrency,
amountCents,
amountCentsRemaining,
percentageRate,
frequency,
frequencyDuration,
frequencyDurationRemaining,
} = coupon
const couponType = amountCents ? CouponTypeEnum.FixedAmount : CouponTypeEnum.Percentage

if (couponType === CouponTypeEnum.FixedAmount && frequency === CouponFrequency.Once) {
return translate(
amountCentsRemaining ? 'text_637b4da08cd0118cd0c4486f' : 'text_632d68358f1fedc68eed3e70',
{
amount: intlFormatNumber(
deserializeAmount(
Number(amountCentsRemaining) || Number(amountCents),
amountCurrency || CurrencyEnum.Usd,
) || 0,
{
currencyDisplay: 'symbol',
currency: amountCurrency || undefined,
},
),
},
)
} else if (couponType === CouponTypeEnum.Percentage && frequency === CouponFrequency.Once) {
return translate('text_632d68358f1fedc68eed3eb5', {
rate: intlFormatNumber(Number(percentageRate) / 100 || 0, {
style: 'percent',
}),
})
} else if (
couponType === CouponTypeEnum.FixedAmount &&
frequency === CouponFrequency.Recurring
) {
return translate(
'text_632d68358f1fedc68eed3ede',
{
if (couponType === CouponTypeEnum.FixedAmount && frequency === CouponFrequency.Once) {
return translate(
amountCentsRemaining ? 'text_637b4da08cd0118cd0c4486f' : 'text_632d68358f1fedc68eed3e70',
{
amount: intlFormatNumber(
deserializeAmount(
Number(amountCentsRemaining) || Number(amountCents),
amountCurrency || CurrencyEnum.Usd,
) || 0,
{
currencyDisplay: 'symbol',
currency: amountCurrency || undefined,
},
),
},
)
} else if (couponType === CouponTypeEnum.Percentage && frequency === CouponFrequency.Once) {
return translate('text_632d68358f1fedc68eed3eb5', {
rate: intlFormatNumber(Number(percentageRate) / 100 || 0, {
style: 'percent',
}),
})
} else if (
couponType === CouponTypeEnum.FixedAmount &&
frequency === CouponFrequency.Recurring
) {
return translate(
'text_632d68358f1fedc68eed3ede',
{
amount: intlFormatNumber(
deserializeAmount(
Number(amountCentsRemaining) || Number(amountCents),
amountCurrency || CurrencyEnum.Usd,
) || 0,
{
currencyDisplay: 'symbol',
currency: amountCurrency || undefined,
},
),
duration: frequencyDurationRemaining || frequencyDuration,
},
frequencyDurationRemaining || frequencyDuration || 1,
)
} else if (
couponType === CouponTypeEnum.Percentage &&
frequency === CouponFrequency.Recurring
) {
return translate(
'text_632d68358f1fedc68eed3ef9',
{
rate: intlFormatNumber(Number(percentageRate) / 100 || 0, {
style: 'percent',
}),
duration: frequencyDurationRemaining || frequencyDuration,
},
frequencyDurationRemaining || frequencyDuration || 1,
)
} else if (
couponType === CouponTypeEnum.FixedAmount &&
frequency === CouponFrequency.Forever
) {
return translate('text_63c946e8bef768ead2fee35c', {
amount: intlFormatNumber(
deserializeAmount(
Number(amountCentsRemaining) || Number(amountCents),
amountCurrency || CurrencyEnum.Usd,
) || 0,
deserializeAmount(Number(amountCents), amountCurrency || CurrencyEnum.Usd) || 0,
{
currencyDisplay: 'symbol',
currency: amountCurrency || undefined,
},
),
duration: frequencyDurationRemaining || frequencyDuration,
},
frequencyDurationRemaining || frequencyDuration || 1,
)
} else if (
couponType === CouponTypeEnum.Percentage &&
frequency === CouponFrequency.Recurring
) {
return translate(
'text_632d68358f1fedc68eed3ef9',
{
})
} else if (
couponType === CouponTypeEnum.Percentage &&
frequency === CouponFrequency.Forever
) {
return translate('text_63c96b18bfbf40e9ef600e99', {
rate: intlFormatNumber(Number(percentageRate) / 100 || 0, {
style: 'percent',
}),
duration: frequencyDurationRemaining || frequencyDuration,
},
frequencyDurationRemaining || frequencyDuration || 1,
)
} else if (couponType === CouponTypeEnum.FixedAmount && frequency === CouponFrequency.Forever) {
return translate('text_63c946e8bef768ead2fee35c', {
amount: intlFormatNumber(
deserializeAmount(Number(amountCents), amountCurrency || CurrencyEnum.Usd) || 0,
{
currencyDisplay: 'symbol',
currency: amountCurrency || undefined,
},
),
})
} else if (couponType === CouponTypeEnum.Percentage && frequency === CouponFrequency.Forever) {
return translate('text_63c96b18bfbf40e9ef600e99', {
rate: intlFormatNumber(Number(percentageRate) / 100 || 0, {
style: 'percent',
}),
})
})
}
}
}

return (
<Typography variant={variant} color="grey600" noWrap data-test="coupon-caption">
{getCaption()}
</Typography>
)
})
return (
<>
{!className && (
<Typography variant={variant} color="grey600" noWrap data-test="coupon-caption">
{getCaption()}
</Typography>
)}

{className && (
<Typography className={className} data-test="coupon-caption">
{getCaption()}
</Typography>
)}
</>
)
},
)

CouponCaption.displayName = 'CouponCaption'
3 changes: 1 addition & 2 deletions src/components/coupons/__tests__/CouponCaption.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { act, cleanup, screen } from '@testing-library/react'

import { CouponCaption, CouponMixedType } from '~/components/coupons/CouponCaption'
import { CouponFrequency, CurrencyEnum } from '~/generated/graphql'
import { render } from '~/test-utils'

import { CouponCaption, CouponMixedType } from '../CouponCaption'

const amountCurrency = CurrencyEnum.Usd

const couponsDataSet = [
Loading