Skip to content

Commit

Permalink
clients/web: attempt to fix broken steps
Browse files Browse the repository at this point in the history
  • Loading branch information
emilwidlund committed Aug 6, 2024
1 parent 8f9acc0 commit 272e245
Showing 1 changed file with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
useListAccounts,
useListArticles,
useOrganizationAccount,
useProducts,
Expand All @@ -9,7 +8,7 @@ import {
import { useOrders } from '@/hooks/queries/orders'
import { MaintainerOrganizationContext } from '@/providers/maintainerOrganization'
import {
ListResourceAccount,
Account,
ListResourceArticle,
ListResourceDonation,
ListResourceOrder,
Expand Down Expand Up @@ -43,7 +42,7 @@ const shouldUpsellFirstOrder = (
) => {
if (!org.feature_settings?.subscriptions_enabled) return false

return orders?.pagination.total_count === 0
return orders?.pagination.total_count === 0 ?? true
}

const shouldUpsellFirstPost = (
Expand All @@ -52,15 +51,15 @@ const shouldUpsellFirstPost = (
) => {
if (!org.feature_settings?.articles_enabled) return false

return articles?.pages[0].pagination.total_count === 0
return articles?.pages[0].pagination.total_count === 0 ?? true
}

const shouldUpsellPayoutConnection = (accounts?: ListResourceAccount) => {
return accounts?.pagination.total_count === 0
const shouldUpsellPayoutConnection = (account?: Account) => {
return !account
}

const shouldUpsellPayout = (payouts?: ListResourceTransaction) => {
return payouts?.pagination.total_count === 0
return payouts?.pagination.total_count === 0 ?? true
}

const shouldUpsellDonation = (
Expand All @@ -69,7 +68,7 @@ const shouldUpsellDonation = (
) => {
if (!org.donations_enabled) return false

return donations?.pagination.total_count === 0
return donations?.pagination.total_count === 0 ?? true
}

export const useUpsellSteps = () => {
Expand All @@ -84,7 +83,6 @@ export const useUpsellSteps = () => {
isPublished: true,
limit: 1,
})
const { data: accounts, isLoading: accountsLoading } = useListAccounts()
const { data: payouts, isLoading: payoutsLoading } = useSearchTransactions({
accountId: account?.id,
type: 'payout',
Expand All @@ -99,7 +97,6 @@ export const useUpsellSteps = () => {
ordersLoading ||
tiersLoading ||
articlesLoading ||
accountsLoading ||
payoutsLoading ||
donationsLoading ||
orgAccountLoading
Expand Down Expand Up @@ -142,15 +139,15 @@ export const useUpsellSteps = () => {
description:
'Let us know which Stripe or Open Collective account we should make payouts to',
href: `/dashboard/${currentOrg.slug}/finance/account`,
done: !shouldUpsellPayoutConnection(accounts),
done: !shouldUpsellPayoutConnection(account),
})

steps.push({
title: 'Withdraw funds to your Payout Account',
description: 'Time to get paid!',
href: `/dashboard/${currentOrg.slug}/finance`,
done:
!shouldUpsellPayoutConnection(accounts) && !shouldUpsellPayout(payouts),
!shouldUpsellPayoutConnection(account) && !shouldUpsellPayout(payouts),
})

steps.push({
Expand All @@ -169,7 +166,7 @@ export const useUpsellSteps = () => {
})

return steps
}, [currentOrg, posts, orders, products, accounts, payouts, donations])
}, [currentOrg, posts, orders, products, account, payouts, donations])

if (isLoading) {
return []
Expand Down

0 comments on commit 272e245

Please sign in to comment.