Skip to content

Commit

Permalink
feat: Migrate isEnterprisePlan to GQL Field (#3576)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajay-sentry authored Dec 12, 2024
1 parent ad05f89 commit c05416a
Show file tree
Hide file tree
Showing 53 changed files with 237 additions and 228 deletions.
3 changes: 1 addition & 2 deletions src/pages/AccountSettings/AccountSettings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { SentryRoute } from 'sentry'
import SidebarLayout from 'layouts/SidebarLayout'
import { usePlanData } from 'services/account'
import { useIsCurrentUserAnAdmin, useUser } from 'services/user'
import { isEnterprisePlan } from 'shared/utils/billing'
import LoadingLogo from 'ui/LoadingLogo'

import AccountSettingsSideMenu from './AccountSettingsSideMenu'
Expand All @@ -34,7 +33,7 @@ function AccountSettings() {
const { data: currentUser } = useUser()

const { data } = usePlanData({ provider, owner })
const viewOktaAccess = isEnterprisePlan(data?.plan?.value)
const viewOktaAccess = data?.plan?.isEnterprisePlan

const isViewingPersonalSettings =
currentUser?.user?.username?.toLowerCase() === owner?.toLowerCase()
Expand Down
1 change: 1 addition & 0 deletions src/pages/AccountSettings/AccountSettings.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ describe('AccountSettings', () => {
plan: {
...mockPlanData,
value: planValue,
isEnterprisePlan: planValue === Plans.USERS_ENTERPRISEM,
},
},
},
Expand Down
3 changes: 1 addition & 2 deletions src/pages/AccountSettings/AccountSettingsSideMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import config from 'config'

import { usePlanData } from 'services/account'
import { useIsCurrentUserAnAdmin, useUser } from 'services/user'
import { isEnterprisePlan } from 'shared/utils/billing'
import Sidemenu from 'ui/Sidemenu'

function defaultLinks({ internalAccessTab, viewOktaAccess }) {
Expand Down Expand Up @@ -66,7 +65,7 @@ function AccountSettingsSideMenu() {
currentUser?.user?.username?.toLowerCase() === owner?.toLowerCase()

const { data } = usePlanData({ provider, owner })
const viewOktaAccess = isEnterprisePlan(data?.plan?.value)
const viewOktaAccess = data?.plan?.isEnterprisePlan

const links = generateLinks({
isAdmin,
Expand Down
1 change: 1 addition & 0 deletions src/pages/AccountSettings/AccountSettingsSideMenu.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ describe('AccountSettingsSideMenu', () => {
plan: {
...mockPlanData,
value: planValue,
isEnterprisePlan: planValue === Plans.USERS_ENTERPRISEM,
},
},
},
Expand Down
1 change: 1 addition & 0 deletions src/pages/DefaultOrgSelector/DefaultOrgSelector.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ describe('DefaultOrgSelector', () => {
hasPrivateRepos: privateRepos,
plan: {
...mockTrialData,
isEnterprisePlan: false,
trialStatus,
value,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ function Activation() {
activated members of{' '}
<span className="text-lg font-semibold">{planQuantity}</span> available
seats{' '}
{accountDetails && <ChangePlanLink accountDetails={accountDetails} />}
{accountDetails && (
<ChangePlanLink
accountDetails={accountDetails}
plan={planData?.plan}
/>
)}
</p>
{/* TODO: new feature https://www.figma.com/file/iNTJAiBYGem3A4LmI4gvKX/Plan-and-members?node-id=103%3A1696 */}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const mockedAccountDetails = {
}

const mockPlanData = {
isEnterprisePlan: false,
baseUnitPrice: 10,
benefits: [],
billingRate: 'monthly',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ import PropType from 'prop-types'

import config from 'config'

import { CollectionMethods, isEnterprisePlan } from 'shared/utils/billing'
import { CollectionMethods } from 'shared/utils/billing'
import A from 'ui/A'

function ChangePlanLink({ accountDetails }) {
function ChangePlanLink({ accountDetails, plan }) {
const isInvoicedCustomer =
accountDetails?.subscriptionDetail?.collectionMethod ===
CollectionMethods.INVOICED_CUSTOMER_METHOD
const plan = accountDetails?.plan?.value

if (config.IS_SELF_HOSTED || isInvoicedCustomer || isEnterprisePlan(plan)) {
if (config.IS_SELF_HOSTED || isInvoicedCustomer || plan?.isEnterprisePlan) {
return null
}

Expand All @@ -27,8 +26,8 @@ function ChangePlanLink({ accountDetails }) {
ChangePlanLink.propTypes = {
accountDetails: PropType.shape({
subscriptionDetail: PropType.shape({ collectionMethod: PropType.string }),
plan: PropType.shape({ value: PropType.string }),
}).isRequired,
plan: PropType.object,
}

export default ChangePlanLink
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const mockPlanData = {
pretrialUsersCount: 0,
planUserCount: 1,
hasSeatsLeft: true,
isEnterprisePlan: false,
}

const server = setupServer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const mockPlanDataResponse = {
pretrialUsersCount: 0,
planUserCount: 1,
hasSeatsLeft: true,
isEnterprisePlan: false,
}

beforeAll(() => {
Expand Down
1 change: 1 addition & 0 deletions src/pages/OwnerPage/HeaderBanners/HeaderBanners.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const mockPlanDataResponse = {
pretrialUsersCount: 0,
planUserCount: 1,
hasSeatsLeft: true,
isEnterprisePlan: false,
}

const mockPlanDataResponseNoUploadLimit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const mockPlanDataResponse = {
marketingName: 'Pro Team',
monthlyUploadLimit: 341,
value: Plans.USERS_PR_INAPPM,
isEnterprisePlan: false,
trialStatus: TrialStatuses.NOT_STARTED,
trialStartDate: '',
trialEndDate: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const mockResponse = {
pretrialUsersCount: 0,
planUserCount: 1,
hasSeatsLeft: true,
isEnterprisePlan: false,
}

const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const mockPlanData = {
pretrialUsersCount: 0,
planUserCount: 1,
hasSeatsLeft: true,
isEnterprisePlan: false,
}

const queryClient = new QueryClient({
Expand Down Expand Up @@ -151,6 +152,7 @@ describe('CancelPlanPage', () => {
...mockPlanData,
trialStatus,
value: planValue,
isEnterprisePlan: planValue === Plans.USERS_ENTERPRISEM,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
usePlanData,
} from 'services/account'
import {
isEnterprisePlan,
isMonthlyPlan,
isProPlan,
isTrialPlan,
Expand Down Expand Up @@ -46,7 +45,7 @@ function CancelPlanPage() {
planData?.plan?.trialStatus === TrialStatuses.ONGOING

// redirect right away if the user is on an enterprise plan
if (isEnterprisePlan(accountDetailsData?.plan?.value) || isOnTrial) {
if (planData?.plan?.isEnterprisePlan || isOnTrial) {
return <Redirect to={`/plan/${provider}/${owner}`} />
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { render, screen } from '@testing-library/react'
import { http, HttpResponse } from 'msw'
import { graphql, http, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'
import React from 'react'
import { MemoryRouter, Route } from 'react-router-dom'

import { TrialStatuses } from 'services/account'
import { PlanName, Plans } from 'shared/utils/billing'

import CurrentPlanCard from './CurrentPlanCard'
Expand All @@ -23,6 +24,7 @@ const proPlanDetails = {
quantity: 5,
value: Plans.USERS_PR_INAPPM,
billingRate: null,
isEnterprisePlan: false,
},
}

Expand All @@ -37,6 +39,7 @@ const freePlanDetails = {
'Unlimited public repositories',
'Unlimited private repositories',
],
isEnterprisePlan: false,
},
}

Expand All @@ -51,6 +54,7 @@ const enterprisePlan = {
'Unlimited public repositories',
'Unlimited private repositories',
],
isEnterprisePlan: true,
},
}

Expand All @@ -65,6 +69,7 @@ const usesInvoiceTeamPlan = {
'Unlimited public repositories',
'Unlimited private repositories',
],
isEnterprisePlan: false,
},
usesInvoice: true,
}
Expand All @@ -77,6 +82,7 @@ const trialPlanDetails = {
benefits: ['Configurable # of users', 'Unlimited repos'],
quantity: 5,
value: Plans.USERS_TRIAL,
isEnterprisePlan: false,
},
}

Expand Down Expand Up @@ -116,6 +122,27 @@ describe('CurrentPlanCard', () => {
server.use(
http.get('/internal/bb/critical-role/account-details/', () => {
return HttpResponse.json(planDetails)
}),
graphql.query('GetPlanData', () => {
const planChunk = {
trialStatus: TrialStatuses.NOT_STARTED,
trialStartDate: '',
trialEndDate: '',
trialTotalDays: 0,
pretrialUsersCount: 0,
planUserCount: 1,
hasSeatsLeft: true,
monthlyUploadLimit: 100,
}

return HttpResponse.json({
data: {
owner: {
hasPrivateRepos: true,
plan: { ...planDetails.plan, ...planChunk },
},
},
})
})
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { useParams } from 'react-router-dom'

import { useAccountDetails } from 'services/account'
import { useAccountDetails, usePlanData } from 'services/account'
import {
CollectionMethods,
isEnterprisePlan,
isFreePlan,
isTrialPlan,
} from 'shared/utils/billing'
Expand All @@ -20,20 +19,22 @@ interface URLParams {
function CurrentPlanCard() {
const { provider, owner } = useParams<URLParams>()
const { data: accountDetails } = useAccountDetails({ provider, owner })
const plan = accountDetails?.rootOrganization?.plan ?? accountDetails?.plan
const { data: planData } = usePlanData({ provider, owner })
const scheduledPhase = accountDetails?.scheduleDetail?.scheduledPhase
const collectionMethod = accountDetails?.subscriptionDetail?.collectionMethod

if (isFreePlan(plan?.value) || isTrialPlan(plan?.value)) {
return <FreePlanCard plan={plan} scheduledPhase={scheduledPhase} />
if (isFreePlan(planData?.plan?.value) || isTrialPlan(planData?.plan?.value)) {
return (
<FreePlanCard plan={planData?.plan} scheduledPhase={scheduledPhase} />
)
}

if (
isEnterprisePlan(plan?.value) ||
planData?.plan?.isEnterprisePlan ||
collectionMethod === CollectionMethods.INVOICED_CUSTOMER_METHOD ||
accountDetails?.usesInvoice
) {
return <EnterprisePlanCard plan={plan} />
return <EnterprisePlanCard plan={planData?.plan} />
}

return <PaidPlanCard />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ function FreePlanCard({ plan, scheduledPhase }) {
</div>
{shouldDisplayTeamCard({ plans }) && <PlanUpgradeTeam />}
<PlanUpgradePro
isSentryUpgrade={canApplySentryUpgrade({ plan, plans })}
isSentryUpgrade={canApplySentryUpgrade({
isEnterprisePlan: planData?.plan?.isEnterprisePlan,
plans,
})}
plans={plans}
/>
<div className="text-xs">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ const mockPlanData = {
pretrialUsersCount: 0,
planUserCount: 1,
hasSeatsLeft: true,
isEnterprisePlan: false,
}

const mockPreTrialPlanInfo = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import PlanUpgradeTeam from './PlanUpgradeTeam'
vi.mock('shared/plan/BenefitList', () => ({ default: () => 'BenefitsList' }))

const mockPlanBasic = {
isEnterprisePlan: false,
baseUnitPrice: 0,
benefits: ['Up to # user', 'Unlimited public repositories'],
billingRate: 'monthly',
Expand All @@ -29,6 +30,7 @@ const mockPlanBasic = {
}

const mockPlanPro = {
isEnterprisePlan: false,
baseUnitPrice: 10,
benefits: ['Up to # user', 'Unlimited public repositories'],
billingRate: 'monthly',
Expand All @@ -45,6 +47,7 @@ const mockPlanPro = {
}

const mockPlanTrialing = {
isEnterprisePlan: false,
baseUnitPrice: 10,
benefits: ['Up to # user', 'Unlimited public repositories'],
billingRate: 'monthly',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const mockResponse = {
pretrialUsersCount: 0,
planUserCount: 1,
hasSeatsLeft: true,
isEnterprisePlan: false,
}

const server = setupServer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ vi.mock('shared/plan/ScheduledPlanDetails', () => ({
}))

const mockProPlan = {
isEnterprisePlan: false,
marketingName: 'Pro',
value: Plans.USERS_PR_INAPPM,
billingRate: 'monthly',
Expand All @@ -44,6 +45,7 @@ const mockProPlan = {
}

const mockTeamPlan = {
isEnterprisePlan: false,
marketingName: 'Team',
value: Plans.USERS_TEAMM,
billingRate: 'monthly',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ function PaidPlanCard() {
<p className="mb-2 text-xs font-semibold">Pricing</p>
<div className="mb-4">
{value && baseUnitPrice ? (
<PlanPricing value={value} baseUnitPrice={baseUnitPrice} />
<PlanPricing
plan={plan}
value={value}
baseUnitPrice={baseUnitPrice}
/>
) : null}
{seats ? (
<p className="text-xs text-ds-gray-senary">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ function PlansActionsBilling({ plan }) {
)
}

if (canApplySentryUpgrade({ plan, plans })) {
if (
canApplySentryUpgrade({
isEnterprisePlan: planData?.plan?.isEnterprisePlan,
plans,
})
) {
return (
<div className="flex self-start">
<Button to={{ pageName: 'upgradeOrgPlan' }} variant="primary">
Expand Down
Loading

0 comments on commit c05416a

Please sign in to comment.