-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add confirm upgrade modal for flat rate subscriptions (#22449)
* Add confirm upgrade modal * move to a new confirm upgrade logic * make the sub unit dynamic * remove old code * add prorated copy * Move more code into logic * Improve how teams plans features are displayed
- Loading branch information
1 parent
ab2fd5f
commit 82be493
Showing
7 changed files
with
230 additions
and
35 deletions.
There are no files selected for viewing
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
76 changes: 76 additions & 0 deletions
76
frontend/src/lib/components/ConfirmUpgradeModal/ConfirmUpgradeModal.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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { IconCheckCircle } from '@posthog/icons' | ||
import { LemonButton, LemonModal, Tooltip } from '@posthog/lemon-ui' | ||
import { useActions, useValues } from 'kea' | ||
import { useMemo } from 'react' | ||
import { billingLogic } from 'scenes/billing/billingLogic' | ||
|
||
import { confirmUpgradeModalLogic } from './confirmUpgradeModalLogic' | ||
|
||
export function ConfirmUpgradeModal(): JSX.Element { | ||
const { upgradePlan } = useValues(confirmUpgradeModalLogic) | ||
const { daysRemaining, daysTotal, billing } = useValues(billingLogic) | ||
const { hideConfirmUpgradeModal, confirm, cancel } = useActions(confirmUpgradeModalLogic) | ||
|
||
const prorationAmount = useMemo( | ||
() => | ||
upgradePlan?.unit_amount_usd | ||
? (parseInt(upgradePlan?.unit_amount_usd) * ((daysRemaining || 1) / (daysTotal || 1))).toFixed(2) | ||
: 0, | ||
[upgradePlan, daysRemaining, daysTotal] | ||
) | ||
|
||
const isProrated = useMemo( | ||
() => | ||
billing?.has_active_subscription && upgradePlan?.unit_amount_usd | ||
? prorationAmount !== parseInt(upgradePlan?.unit_amount_usd || '') | ||
: false, | ||
[billing?.has_active_subscription, prorationAmount] | ||
) | ||
|
||
return ( | ||
<LemonModal | ||
onClose={hideConfirmUpgradeModal} | ||
isOpen={!!upgradePlan} | ||
closable={false} | ||
title={`Ready to subscribe to the ${upgradePlan?.name}?`} | ||
footer={ | ||
<> | ||
<LemonButton type="secondary" onClick={() => cancel()}> | ||
Cancel | ||
</LemonButton> | ||
<LemonButton type="primary" onClick={() => confirm()}> | ||
Sign me up | ||
</LemonButton> | ||
</> | ||
} | ||
> | ||
<div className="max-w-140"> | ||
<p> | ||
Woo! You're gonna love the {upgradePlan?.name}. We're just confirming that this is a $ | ||
{Number(upgradePlan?.unit_amount_usd)} / {upgradePlan?.unit} subscription.{' '} | ||
{isProrated | ||
? `The first payment will be prorated to $${prorationAmount} and it will be charged immediately.` | ||
: 'The first payment will be charged immediately.'} | ||
</p> | ||
{upgradePlan && upgradePlan?.features?.length > 1 && ( | ||
<div> | ||
<p className="ml-0 mb-2 max-w-200">Here are the features included:</p> | ||
<div className="grid grid-cols-2 gap-x-4"> | ||
{upgradePlan?.features.map((feature, index) => ( | ||
<div className="flex gap-x-2 items-center mb-2" key={'addon-features-' + index}> | ||
<IconCheckCircle className="text-success" /> | ||
<Tooltip key={feature.key} title={feature.description}> | ||
<b> | ||
{feature.name} | ||
{feature.note ? ': ' + feature.note : ''} | ||
</b> | ||
</Tooltip> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
</LemonModal> | ||
) | ||
} |
62 changes: 62 additions & 0 deletions
62
frontend/src/lib/components/ConfirmUpgradeModal/confirmUpgradeModalLogic.ts
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { actions, kea, listeners, path, reducers } from 'kea' | ||
|
||
import { BillingV2PlanType } from '~/types' | ||
|
||
import type { confirmUpgradeModalLogicType } from './confirmUpgradeModalLogicType' | ||
|
||
export const confirmUpgradeModalLogic = kea<confirmUpgradeModalLogicType>([ | ||
path(['lib', 'components', 'ConfirmUpgradeModal', 'confirmUpgradeModalLogic']), | ||
actions({ | ||
showConfirmUpgradeModal: ( | ||
upgradePlan: BillingV2PlanType, | ||
confirmCallback: () => void, | ||
cancelCallback: () => void | ||
) => ({ | ||
upgradePlan, | ||
confirmCallback, | ||
cancelCallback, | ||
}), | ||
hideConfirmUpgradeModal: true, | ||
confirm: true, | ||
cancel: true, | ||
}), | ||
reducers({ | ||
upgradePlan: [ | ||
null as BillingV2PlanType | null, | ||
{ | ||
showConfirmUpgradeModal: (_, { upgradePlan }) => upgradePlan, | ||
hideConfirmUpgradeModal: () => null, | ||
}, | ||
], | ||
confirmCallback: [ | ||
null as (() => void) | null, | ||
{ | ||
showConfirmUpgradeModal: (_, { confirmCallback }) => confirmCallback, | ||
hideConfirmUpgradeModal: () => null, | ||
}, | ||
], | ||
cancelCallback: [ | ||
null as (() => void) | null, | ||
{ | ||
showConfirmUpgradeModal: (_, { cancelCallback }) => cancelCallback, | ||
hideConfirmUpgradeModal: () => null, | ||
}, | ||
], | ||
}), | ||
listeners(({ actions, values }) => ({ | ||
confirm: async (_, breakpoint) => { | ||
await breakpoint(100) | ||
if (values.confirmCallback) { | ||
values.confirmCallback() | ||
} | ||
actions.hideConfirmUpgradeModal() | ||
}, | ||
cancel: async (_, breakpoint) => { | ||
await breakpoint(100) | ||
if (values.cancelCallback) { | ||
values.cancelCallback() | ||
} | ||
actions.hideConfirmUpgradeModal() | ||
}, | ||
})), | ||
]) |
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
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
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
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