Skip to content

Commit

Permalink
handle no player limit
Browse files Browse the repository at this point in the history
  • Loading branch information
tudddorrr committed Jan 27, 2025
1 parent bc8c63b commit 15f91be
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/api/usePricingPlanUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import useSWR from 'swr'
import buildError from '../utils/buildError'
import makeValidatedGetRequest from './makeValidatedGetRequest'
import { z } from 'zod'
import { pricingPlanUsageSchema } from '../entities/pricingPlan'
import { PricingPlanUsage, pricingPlanUsageSchema } from '../entities/pricingPlan'

export default function usePricingPlanUsage() {
const fetcher = async ([url]: [string]) => {
Expand All @@ -18,8 +18,11 @@ export default function usePricingPlanUsage() {
fetcher
)

const limit = data?.usage.limit ?? (typeof data === 'undefined' ? 0 : Infinity)
const used = data?.usage.used ?? 0

return {
usage: data?.usage ?? { limit: 0, used: 0 },
usage: { limit, used } satisfies PricingPlanUsage,
loading: !data && !error,
error: error && buildError(error)
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/UsageWarningBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function UsageWarningBanner({ usage }: UsageWarningBannerProps) {
<AlertBanner
className='w-full lg:2/3 xl:w-1/2'
icon={IconInfoCircle}
text={<p>You&apos;ve used {Math.round(usage.used / usage.limit * 100)}% of your current plan&apos;s limit. <Link to='/billing' className='font-bold underline'>Upgrade your plan</Link> to avoid any disruption to your game.</p>}
text={<p>You&apos;ve used {Math.round(usage.used / usage.limit ?? Infinity * 100)}% of your current plan&apos;s limit. <Link to='/billing' className='font-bold underline'>Upgrade your plan</Link> to avoid any disruption to your game.</p>}
/>
)
}
2 changes: 1 addition & 1 deletion src/components/billing/PricingPlanTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default function PricingPlanTile({
<ul>
{!custom &&
<li>
Up to <span className='font-semibold'>{plan?.playerLimit.toLocaleString()}</span> players
Up to <span className='font-semibold'>{(plan?.playerLimit ?? Infinity).toLocaleString()}</span> players
</li>
}

Expand Down
2 changes: 1 addition & 1 deletion src/entities/pricingPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const pricingPlanSchema = z.object({
stripeId: z.string(),
hidden: z.boolean(),
default: z.boolean(),
playerLimit: z.number()
playerLimit: z.number().nullable()
})

export const pricingPlanUsageSchema = z.object({
Expand Down

0 comments on commit 15f91be

Please sign in to comment.