-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
635e306
commit cbbf5e2
Showing
7 changed files
with
351 additions
and
526 deletions.
There are no files selected for viewing
122 changes: 102 additions & 20 deletions
122
www/src/components/account/billing/BillingManagePlan.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,113 @@ | ||
import { Div } from 'honorable' | ||
import { useContext } from 'react' | ||
import { Button, Flex } from '@pluralsh/design-system' | ||
|
||
import SubscriptionContext from '../../../contexts/SubscriptionContext' | ||
import { useCallback, useContext, useState } from 'react' | ||
|
||
import BillingPreview from './BillingPreview' | ||
import BillingPricingCards from './BillingPricingCards' | ||
import { useSearchParams } from 'react-router-dom' | ||
|
||
import styled, { useTheme } from 'styled-components' | ||
|
||
import SubscriptionContext from 'contexts/SubscriptionContext' | ||
|
||
import BillingPricingCards, { ContactUs } from './BillingPricingCards' | ||
import BillingPricingTable from './BillingPricingTable' | ||
import ConfirmPayment from './ConfirmPayment' | ||
|
||
function BillingManagePlan() { | ||
const { isEnterprisePlan } = useContext(SubscriptionContext) | ||
import BillingDowngradeModal from './BillingDowngradeModal' | ||
import BillingUpgradeToProfessionalModal from './BillingUpgradeToProfessionalModal' | ||
|
||
export default function BillingManagePlan() { | ||
const theme = useTheme() | ||
const [searchParams, setSearchParams] = useSearchParams() | ||
|
||
const [downgradeModalOpen, setDowngradeModalOpen] = useState(false) | ||
|
||
const upgradeToProfessionalModalOpen = | ||
typeof searchParams.get('upgrade') === 'string' | ||
const setUpgradeToProfessionalModalOpen = useCallback( | ||
(isOpen) => { | ||
setSearchParams((sp) => { | ||
if (isOpen) { | ||
sp.set('upgrade', '1') | ||
} else { | ||
sp.delete('upgrade') | ||
} | ||
|
||
return sp | ||
}) | ||
}, | ||
[setSearchParams] | ||
) | ||
|
||
return ( | ||
<> | ||
<Flex | ||
direction="column" | ||
gap="large" | ||
paddingBottom={theme.spacing.xxlarge} | ||
> | ||
<ConfirmPayment /> | ||
{!isEnterprisePlan && <BillingPreview />} | ||
<Div marginTop="xxlarge"> | ||
<BillingPricingCards /> | ||
</Div> | ||
<Div | ||
marginTop="xxlarge" | ||
marginBottom="large" | ||
> | ||
<BillingPricingTable /> | ||
</Div> | ||
</> | ||
<BillingPricingCards | ||
onUpgrade={() => setUpgradeToProfessionalModalOpen(true)} | ||
onCancel={() => setDowngradeModalOpen(true)} | ||
/> | ||
<BillingPricingTable | ||
onUpgrade={() => setUpgradeToProfessionalModalOpen(true)} | ||
onCancel={() => setDowngradeModalOpen(true)} | ||
/> | ||
{/* Modals */} | ||
<BillingUpgradeToProfessionalModal | ||
open={upgradeToProfessionalModalOpen} | ||
onClose={() => setUpgradeToProfessionalModalOpen(false)} | ||
/> | ||
<BillingDowngradeModal | ||
open={downgradeModalOpen} | ||
onClose={() => setDowngradeModalOpen(false)} | ||
/> | ||
</Flex> | ||
) | ||
} | ||
|
||
export default BillingManagePlan | ||
export function ProPlanCTA({ | ||
onUpgrade, | ||
onCancel, | ||
}: { | ||
onUpgrade: () => void | ||
onCancel: () => void | ||
}) { | ||
const { isProPlan, isEnterprisePlan } = useContext(SubscriptionContext) | ||
|
||
return isProPlan ? ( | ||
<ActionBtnSC | ||
secondary | ||
width="100%" | ||
onClick={onCancel} | ||
> | ||
Cancel plan | ||
</ActionBtnSC> | ||
) : isEnterprisePlan ? ( | ||
<ActionBtnSC | ||
primary | ||
disabled | ||
width="100%" | ||
> | ||
You have an Enterprise plan | ||
</ActionBtnSC> | ||
) : ( | ||
<ActionBtnSC | ||
primary | ||
width="100%" | ||
onClick={onUpgrade} | ||
> | ||
Upgrade | ||
</ActionBtnSC> | ||
) | ||
} | ||
|
||
export function EnterprisePlanCTA() { | ||
const { isProPlan } = useContext(SubscriptionContext) | ||
|
||
return isProPlan ? <ContactUs /> : <ContactUs floating /> | ||
} | ||
|
||
const ActionBtnSC = styled(Button)({ | ||
width: '100%', | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.