Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/account-ui/src/billing/tab/BillingAutoTopUpCard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,33 @@ describe('BillingAutoTopUpCard', () => {
)
})

it('opens the host link in a new tab and reports the action', async () => {
const onAction = vi.fn()
render(BillingAutoTopUpCard, {
props: {
state: loaded({ status: 'failed' }),
offView: 'off',
setup: null,
copy: autoTopUpCardCopy,
locale: 'en',
actionHref: 'https://billing.test/profile/billing',
onAction
}
})

const link = screen.getByRole('link', { name: 'Update payment' })
link.addEventListener('click', (event) => event.preventDefault())
await userEvent.click(link)

expect(link.getAttribute('href')).toBe(
'https://billing.test/profile/billing'
)
expect(link.getAttribute('target')).toBe('_blank')
expect(link.dataset.variant).toBe('inverted')
expect(screen.queryByRole('button', { name: 'Update payment' })).toBeNull()
expect(onAction).toHaveBeenCalledWith('update_payment')
})

it('lets the host replace the retry control', () => {
render(BillingAutoTopUpCard, {
props: {
Expand Down
30 changes: 21 additions & 9 deletions packages/account-ui/src/billing/tab/BillingAutoTopUpCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,16 @@
:variant="actionVariant"
:icon="OPEN"
>
<CheckoutButton
<BillingBannerActionButton
:href="actionHref"
:label="copy.actions[view.actionLabel]"
:variant="actionVariant"
size="md"
:class="cn('shrink-0 no-underline', classes?.action)"
:class="classes?.action"
@click="emit('action', view.action)"
>
{{ copy.actions[view.actionLabel] }}
<i :class="OPEN" aria-hidden="true" />
</CheckoutButton>
</BillingBannerActionButton>
</slot>
</div>
</section>
Expand All @@ -118,6 +119,7 @@ import Skeleton from '@comfyorg/design-system/skeleton/Skeleton'
import { cn } from '@comfyorg/tailwind-utils'

import CheckoutButton from '#/billing/checkout/CheckoutButton.vue'
import BillingBannerActionButton from './BillingBannerActionButton.vue'
import BillingInfoTip from './BillingInfoTip.vue'
import { autoTopUpCardView } from './autoTopUpCardView'
import type { AutoTopUpCardCopy, AutoTopUpViewKey } from './autoTopUpCardView'
Expand All @@ -131,14 +133,14 @@ const DANGER = { border: 'border-destructive', text: 'text-destructive' }

const DOT: Record<AutoTopUpViewKey, string> = {
failed: 'bg-destructive',
turnedOff: 'bg-destructive-background',
turnedOff: 'bg-destructive',
off: 'bg-muted-foreground',
on_hold: 'bg-warning-background',
paused_by_budget: 'bg-warning-background',
on_hold: 'bg-warning',
paused_by_budget: 'bg-warning',
maximumReached: 'bg-warning-background',
noPaymentMethod: 'bg-muted-foreground',
noDefaultPaymentMethod: 'bg-muted-foreground',
on: 'bg-success-background'
on: 'bg-success'
}

const DEFAULT_VARIANTS: Record<AutoTopUpViewKey, ActionVariant> = {
Expand All @@ -153,12 +155,22 @@ const DEFAULT_VARIANTS: Record<AutoTopUpViewKey, ActionVariant> = {
on: 'secondary'
}

const { state, offView, setup, copy, locale, variants, classes } = defineProps<{
const {
state,
offView,
setup,
copy,
locale,
actionHref = null,
variants,
classes
} = defineProps<{
state: AutoTopUpCardState
offView: AutoTopUpOffView
setup: AutoTopUpOffViewFacts['setup']
copy: AutoTopUpCardCopy
locale: string
actionHref?: string | null
variants?: Partial<Record<AutoTopUpViewKey, ActionVariant>>
classes?: Partial<
Record<
Expand Down
6 changes: 3 additions & 3 deletions packages/account-ui/src/billing/tab/BillingBanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('BillingBanner', () => {
},
controls: ['BUTTON:Dismiss', 'BUTTON:Add credits'],
icon: 'text-muted-foreground',
shell: ['rounded-2xl', 'p-4']
shell: ['rounded-xl', 'p-4']
},
{
case: 'a parked payment',
Expand All @@ -100,14 +100,14 @@ describe('BillingBanner', () => {
},
controls: ['A:Contact support'],
icon: 'text-warning',
shell: ['rounded-2xl', 'p-4']
shell: ['rounded-xl', 'p-4']
},
{
case: 'a plan status',
view: { kind: 'planStatus', ...text, action: null, href: null },
controls: [],
icon: 'text-muted-foreground',
shell: ['rounded-2xl', 'p-4']
shell: ['rounded-xl', 'p-4']
},
{
case: 'auto top-up failed',
Expand Down
4 changes: 2 additions & 2 deletions packages/account-ui/src/billing/tab/BillingBanner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
role="status"
:class="
cn(
'flex flex-col gap-3 border border-border/60 bg-background',
'flex flex-col gap-3 rounded-xl border border-border bg-background',
look.windowBreakpoint
? 'sm:flex-row sm:items-center sm:gap-2'
: '@2xl:flex-row @2xl:items-center @2xl:gap-2',
look.roomy ? 'rounded-2xl p-4' : 'rounded-xl p-3',
look.roomy ? 'p-4' : 'p-3',
classes?.panel
)
"
Expand Down
16 changes: 13 additions & 3 deletions packages/account-ui/src/billing/tab/BillingBannerActionButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
:href
target="_blank"
rel="noopener"
:data-variant="variant"
:class="cn(buttonVariants({ variant, size }), 'shrink-0 no-underline')"
@click="emit('click')"
>
{{ label }}
<slot />
</a>
<CheckoutButton
v-else
Expand All @@ -18,21 +20,29 @@
@click="emit('click')"
>
{{ label }}
<slot />
</CheckoutButton>
</template>

<script setup lang="ts">
import { buttonVariants } from '@comfyorg/design-system/button.variants'
import type { ButtonVariants } from '@comfyorg/design-system/button.variants'
import { cn } from '@comfyorg/tailwind-utils'

import CheckoutButton from '#/billing/checkout/CheckoutButton.vue'

const { href, label, variant, size, loading } = defineProps<{
const {
href,
label,
variant,
size,
loading = false
} = defineProps<{
href: string | null
label: string
variant: 'inverted' | 'secondary'
variant: ButtonVariants['variant']
size: 'md' | 'lg'
loading: boolean
loading?: boolean
}>()

const emit = defineEmits<{ click: [] }>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import '@testing-library/jest-dom/vitest'
import { render, screen } from '@testing-library/vue'
import userEvent from '@testing-library/user-event'
import { describe, expect, it, vi } from 'vitest'
import { defineComponent } from 'vue'

import TooltipProvider from '@comfyorg/design-system/tooltip/TooltipProvider'

import BillingInfoTip from '@/platform/billing/components/billingTab/BillingInfoTip.vue'
import BillingInfoTip from './BillingInfoTip.vue'

function renderTip(props: { text: string; label?: string }) {
return render(
Expand Down
Loading
Loading