-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Contact Us links for non-tiered accounts #604
Conversation
This pull request is being automatically deployed with Vercel (learn more). egghead-io-nextjs – ./🔍 Inspect: https://vercel.com/eggheadio/egghead-io-nextjs/6MDjaFPjsppM6s8zv2z64zhH1igq egghead-next-storybook – ./🔍 Inspect: https://vercel.com/eggheadio/egghead-next-storybook/HmoJLz9EpKh74GGYiF8LcUs2cvuR |
const recur = (price: any) => { | ||
if (price === undefined) return '' | ||
|
||
const { | ||
recurring: {interval, interval_count}, | ||
} = price | ||
|
||
if (interval === 'month' && interval_count === 3) return 'quarter' | ||
if (interval === 'month' && interval_count === 6) return '6-months' | ||
if (interval === 'month' && interval_count === 1) return 'month' | ||
if (interval === 'year' && interval_count === 1) return 'year' | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pulled this function out of the subscription data hook and placed it here because it was only being used here.
stripeCustomerId, | ||
slug, | ||
subscriptionData, | ||
loading, | ||
}: { | ||
stripeCustomerId: string | ||
slug: string | ||
subscriptionData: any | ||
loading: boolean | ||
}) => { | ||
const {subscriptionData, recur, loading} = useSubscriptionDetails({ | ||
stripeCustomerId, | ||
slug, | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Subscription data is being passed down from the singular call site instead of being requested here.
type SubscriptionData = { | ||
portalUrl?: string | ||
billingScheme: 'tiered' | 'per_unit' | ||
subscription?: any | ||
price?: any | ||
product?: any | ||
latestInvoice?: any | ||
upcomingInvoice?: any | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some typing for the SubscriptionData to get some better type inference and warnings.
const [ | ||
subscriptionData, | ||
setSubscriptionData, | ||
] = React.useState<SubscriptionData>({billingScheme: 'per_unit'}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The billing scheme will always be either 'tiered' or 'per_unit'. I default it to this, but Stripe should always tell us one or the other.
@@ -30,6 +30,7 @@ const StripeCheckoutSession = async ( | |||
if (subscription) { | |||
const price = get(first(subscription.items.data), 'price') | |||
const latestInvoice = get(subscription, 'latest_invoice') | |||
const billingScheme = get(subscription, 'plan.billing_scheme') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract billing scheme as a top-level value for ease of access in a couple places for conditional rendering.
type SubscriptionData = { | ||
portalUrl: string | undefined | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused type
const {accountSlug, stripeCustomerId} = teamData | ||
const [ | ||
subscriptionData, | ||
setSubscriptionData, | ||
] = React.useState<SubscriptionData>({} as SubscriptionData) | ||
|
||
React.useEffect(() => { | ||
if (stripeCustomerId) { | ||
axios | ||
.get(`/api/stripe/billing/session`, { | ||
params: { | ||
customer_id: stripeCustomerId, | ||
account_slug: accountSlug, | ||
}, | ||
}) | ||
.then(({data}) => { | ||
if (data) { | ||
setSubscriptionData(data) | ||
} | ||
}) | ||
} | ||
}, [stripeCustomerId, accountSlug]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the duplicate Stripe API call that has been pulled up to a single call site.
</span> | ||
{subscriptionData?.portalUrl && ( | ||
<Link href={subscriptionData.portalUrl}> | ||
{billingScheme === 'tiered' && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This second adjusts the copy and CTA of the At Capacity Notice based on the billing scheme.
src/pages/team/index.tsx
Outdated
{!subscriptionDataLoading && | ||
subscriptionData.billingScheme === 'per_unit' && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section displays an additional note about adding seats to your account based IF this account is on legacy pricing.
There were multiple components in the Team page tree that was firing off the API call that requests subscription data from Stripe. This pulls the call up so that it is made a single time and then passes the needed data down.
212caac
to
7a770d8
Compare
export const recur = (price: any) => { | ||
if (price === undefined) return '' | ||
|
||
const { | ||
recurring: {interval, interval_count}, | ||
} = price | ||
|
||
if (interval === 'month' && interval_count === 3) return 'quarter' | ||
if (interval === 'month' && interval_count === 6) return '6-months' | ||
if (interval === 'month' && interval_count === 1) return 'month' | ||
if (interval === 'year' && interval_count === 1) return 'year' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exporting recur instead of passing it around as a prop since it is a static concept.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the "manage your account" needs to be removed for legacy accounts too because the portal is WEIRD for them.
This PR does a couple things (for #594):
Primarily, it adds 'Contact Us' messaging/links for the accounts that are still on the non-tiered legacy pricing. Because they won't be able to adjust the number of seats through the stripe billing portal, they should contact support to make those adjustments.
Secondarily, this PR:
slug
argument that was being passed around and into the Stripe API call because it is not used by that Next API endpoint.Screens
A persistent info block for customers on the legacy pricing
The adjusted CTA for legacy pricing customers when they reach their seat limit