-
Notifications
You must be signed in to change notification settings - Fork 192
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
Changes from 4 commits
e964b96
e65fbc8
7a770d8
2916b34
af0ceb5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,39 @@ | ||
import * as React from 'react' | ||
import axios from 'axios' | ||
|
||
type SubscriptionData = { | ||
portalUrl?: string | ||
billingScheme: 'tiered' | 'per_unit' | ||
subscription?: any | ||
price?: any | ||
product?: any | ||
latestInvoice?: any | ||
upcomingInvoice?: any | ||
} | ||
Comment on lines
+4
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
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' | ||
} | ||
Comment on lines
+14
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
const useSubscriptionDetails = ({ | ||
stripeCustomerId, | ||
slug, | ||
}: { | ||
stripeCustomerId: string | ||
slug: string | ||
}) => { | ||
stripeCustomerId?: string | ||
}): {subscriptionData: SubscriptionData; loading: boolean} => { | ||
const [loading, setLoading] = React.useState<boolean>(true) | ||
const [subscriptionData, setSubscriptionData] = React.useState<any>() | ||
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' | ||
} | ||
const [ | ||
subscriptionData, | ||
setSubscriptionData, | ||
] = React.useState<SubscriptionData>({billingScheme: 'per_unit'}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
React.useEffect(() => { | ||
if (stripeCustomerId) { | ||
|
@@ -31,7 +43,6 @@ const useSubscriptionDetails = ({ | |
.get(`/api/stripe/billing/session`, { | ||
params: { | ||
customer_id: stripeCustomerId, | ||
account_slug: slug, | ||
}, | ||
}) | ||
.then(({data}) => { | ||
|
@@ -43,9 +54,9 @@ const useSubscriptionDetails = ({ | |
setLoading(false) | ||
}) | ||
} | ||
}, [stripeCustomerId, slug]) | ||
}, [stripeCustomerId]) | ||
|
||
return {subscriptionData, recur, loading} | ||
return {subscriptionData, loading} | ||
} | ||
|
||
export default useSubscriptionDetails |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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. |
||
|
||
const {product: product_id} = price | ||
|
||
|
@@ -47,6 +48,7 @@ const StripeCheckoutSession = async ( | |
|
||
res.status(200).json({ | ||
portalUrl: session.url, | ||
billingScheme, | ||
subscription, | ||
price, | ||
product, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,14 @@ import Link from 'next/link' | |
import LoginRequired from '../../components/login-required' | ||
import {useRouter} from 'next/router' | ||
import CopyToClipboard from '../../components/team/copy-to-clipboard' | ||
import axios from 'axios' | ||
import {track} from 'utils/analytics' | ||
import {loadTeams} from 'lib/teams' | ||
import TeamName from '../../components/team/team-name' | ||
import {getTokenFromCookieHeaders} from 'utils/auth' | ||
import {isEmpty, find} from 'lodash' | ||
import BillingSection from 'components/team/billing-section' | ||
import MemberTable from 'components/team/member-table' | ||
import useSubscriptionDetails from 'hooks/use-subscription-data' | ||
|
||
export type TeamData = { | ||
accountId: number | ||
|
@@ -45,35 +45,16 @@ const TeamComposition = ({ | |
} | ||
} | ||
|
||
type SubscriptionData = { | ||
portalUrl: string | undefined | ||
} | ||
Comment on lines
-48
to
-50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused type |
||
|
||
const AtCapacityNotice = ({teamData}: {teamData: TeamData}) => { | ||
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]) | ||
Comment on lines
-53
to
-74
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
if (!teamData.isFull) { | ||
const AtCapacityNotice = ({ | ||
isFull, | ||
billingPortalUrl, | ||
billingScheme, | ||
}: { | ||
isFull: boolean | ||
billingPortalUrl: string | undefined | ||
billingScheme: 'tiered' | 'per_unit' | ||
}) => { | ||
if (!isFull) { | ||
return null | ||
} | ||
|
||
|
@@ -98,24 +79,44 @@ const AtCapacityNotice = ({teamData}: {teamData: TeamData}) => { | |
/> | ||
</svg> | ||
</span> | ||
<div className="ml-8 flex flex-col space-y-2 p-2"> | ||
<span> | ||
Your team account is full. You can add more seats to your account | ||
through the Stripe Billing Portal. | ||
</span> | ||
{subscriptionData?.portalUrl && ( | ||
<Link href={subscriptionData.portalUrl}> | ||
{billingScheme === 'tiered' && ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
<div className="ml-8 flex flex-col space-y-2 p-2"> | ||
<span> | ||
Your team account is full. You can add more seats to your account | ||
through the Stripe Billing Portal. | ||
</span> | ||
{billingPortalUrl && ( | ||
<Link href={billingPortalUrl}> | ||
<a | ||
onClick={() => { | ||
track(`clicked manage membership`) | ||
}} | ||
className="transition-all duration-150 ease-in-out font-semibold rounded-md dark:text-yellow-400 dark:hover:text-yellow-300" | ||
> | ||
Visit Stripe Billing Portal | ||
</a> | ||
</Link> | ||
)} | ||
</div> | ||
)} | ||
{billingScheme === 'per_unit' && ( | ||
<div className="ml-8 flex flex-col space-y-2 p-2"> | ||
<span> | ||
Your team account is full. Our support team can help you add more | ||
seats to your account. | ||
</span> | ||
<Link href="mailto:[email protected]"> | ||
<a | ||
onClick={() => { | ||
track(`clicked manage membership`) | ||
track(`clicked contact us for account at capacity`) | ||
}} | ||
className="transition-all duration-150 ease-in-out font-semibold rounded-md dark:text-yellow-400 dark:hover:text-yellow-300" | ||
> | ||
Visit Stripe Billing Portal | ||
Contact Us | ||
</a> | ||
</Link> | ||
)} | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
@@ -137,6 +138,13 @@ const Team = ({team: teamData}: TeamPageProps) => { | |
} | ||
}, [teamDataNotAvailable]) | ||
|
||
const { | ||
subscriptionData, | ||
loading: subscriptionDataLoading, | ||
} = useSubscriptionDetails({ | ||
stripeCustomerId: teamData?.stripeCustomerId, | ||
}) | ||
|
||
if (teamData === undefined) return null | ||
|
||
return ( | ||
|
@@ -165,7 +173,11 @@ const Team = ({team: teamData}: TeamPageProps) => { | |
label={true} | ||
/> | ||
</div> | ||
<AtCapacityNotice teamData={teamData} /> | ||
<AtCapacityNotice | ||
isFull={teamData.isFull} | ||
billingPortalUrl={subscriptionData.portalUrl} | ||
billingScheme={subscriptionData.billingScheme} | ||
/> | ||
<h2 className="font-semibold text-xl mt-16"> | ||
Current Team Members{' '} | ||
<TeamComposition | ||
|
@@ -179,9 +191,45 @@ const Team = ({team: teamData}: TeamPageProps) => { | |
setMembers={setMembers} | ||
/> | ||
<BillingSection | ||
stripeCustomerId={teamData.stripeCustomerId} | ||
slug={teamData.accountSlug} | ||
subscriptionData={subscriptionData} | ||
loading={subscriptionDataLoading} | ||
/> | ||
{!subscriptionDataLoading && | ||
subscriptionData.billingScheme === 'per_unit' && ( | ||
<div | ||
className="relative px-4 py-1 mt-4 mb-4 leading-normal text-blue-700 bg-blue-100 dark:text-blue-100 dark:bg-blue-800 rounded" | ||
role="alert" | ||
> | ||
<span className="absolute inset-y-0 left-0 flex items-center ml-4"> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
className="h-6 w-6" | ||
fill="none" | ||
viewBox="0 0 24 24" | ||
stroke="currentColor" | ||
> | ||
<path | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth={2} | ||
d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z" | ||
/> | ||
</svg> | ||
</span> | ||
<div className="ml-8 flex flex-col space-y-2 p-2"> | ||
<span> | ||
Is the size of your team changing?{' '} | ||
<a | ||
className="transition-all duration-150 ease-in-out underline font-semibold rounded-md" | ||
href="mailto:[email protected]" | ||
> | ||
Contact us | ||
</a>{' '} | ||
at anytime to adjust the number of seats for your account. | ||
</span> | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
</LoginRequired> | ||
) | ||
|
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.