Skip to content
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

feat(fe2): Billing - Add tooltips to disabled buttons #3615

Merged
merged 17 commits into from
Dec 5, 2024
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
v-model="isYearlyIntervalSelected"
:show-label="false"
name="domain-protection"
:disabled="!toggleEnabled"
@update:model-value="(newValue) => $emit('onYearlyIntervalSelected', newValue)"
/>
<span class="text-body-2xs">Billed annually</span>
Expand All @@ -34,13 +33,24 @@
</div>
<div v-if="workspaceId" class="w-full mt-4">
<FormButton
v-if="isMonthlyToAnnual || canUpgradeToPlan"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to do this hacky fix to the v-tippy reactivity bug

:color="buttonColor"
:disabled="!isSelectable"
full-width
@click="onCtaClick"
>
{{ buttonText }}
</FormButton>
<div v-else v-tippy="buttonTooltip">
<FormButton
:color="buttonColor"
:disabled="!isSelectable"
full-width
@click="onCtaClick"
>
{{ buttonText }}
</FormButton>
</div>
</div>
<ul class="flex flex-col gap-y-2 mt-4 pt-3 border-t border-outline-3">
<li
Expand Down Expand Up @@ -133,36 +143,57 @@ const canUpgradeToPlan = computed(() => {

return allowedUpgrades[props.currentPlan.name].includes(props.plan.name)
})

const statusIsTrial = computed(
() => props.currentPlan?.status === WorkspacePlanStatuses.Trial || !props.currentPlan
)
const buttonColor = computed(() => {
if (statusIsTrial.value) {
return props.plan.name === WorkspacePlans.Starter ? 'primary' : 'outline'
}
return 'outline'
})

const isMatchingInterval = computed(
() =>
props.activeBillingInterval ===
(props.yearlyIntervalSelected ? BillingInterval.Yearly : BillingInterval.Monthly)
)

const isDowngrade = computed(() => {
return !canUpgradeToPlan.value && props.currentPlan?.name !== props.plan.name
})

const isAnnualToMonthly = computed(() => {
return (
!isMatchingInterval.value &&
props.currentPlan?.name === props.plan.name &&
!props.yearlyIntervalSelected
)
})

const isMonthlyToAnnual = computed(() => {
return (
!isMatchingInterval.value &&
props.currentPlan?.name === props.plan.name &&
props.yearlyIntervalSelected
)
})

const isCurrentPlan = computed(
() => isMatchingInterval.value && props.currentPlan?.name === props.plan.name
)

const isSelectable = computed(() => {
// Always enable buttons during trial
if (statusIsTrial.value) return true

// Disable if user is already on this plan with same billing interval
if (isMatchingInterval.value && props.currentPlan?.name === props.plan.name)
return false
// Disable if current plan
if (isCurrentPlan.value) return false
andrewwallacespeckle marked this conversation as resolved.
Show resolved Hide resolved

// Never allow annual to monthly changes
if (isAnnualToMonthly.value) return false

// Handle billing interval changes
if (!isMatchingInterval.value) {
const isCurrentPlan = props.currentPlan?.name === props.plan.name
const isMonthlyToYearly =
props.yearlyIntervalSelected &&
props.activeBillingInterval === BillingInterval.Monthly
// Allow yearly upgrades from monthly plans
if (isMonthlyToYearly) return isCurrentPlan || canUpgradeToPlan.value
if (isMonthlyToAnnual.value) {
return props.currentPlan?.name === props.plan.name || canUpgradeToPlan.value
}
// Never allow switching to monthly if currently on yearly billing
if (props.activeBillingInterval === BillingInterval.Yearly) return false
// Allow monthly plan changes only for upgrades
Expand All @@ -172,36 +203,50 @@ const isSelectable = computed(() => {
// Allow upgrades to higher tier plans
return canUpgradeToPlan.value
})
const toggleEnabled = computed(() => {
Mikehrn marked this conversation as resolved.
Show resolved Hide resolved
return statusIsTrial.value
? true
: canUpgradeToPlan.value ||
(props.currentPlan?.name === props.plan.name &&
props.activeBillingInterval === BillingInterval.Monthly)

const buttonColor = computed(() => {
if (statusIsTrial.value) {
return props.plan.name === WorkspacePlans.Starter ? 'primary' : 'outline'
}
return 'outline'
})

const buttonText = computed(() => {
// Trial plan case
if (statusIsTrial.value) {
return `Subscribe to ${startCase(props.plan.name)}`
}
// Current plan case
if (isMatchingInterval.value && props.currentPlan?.name === props.plan.name) {
if (isCurrentPlan.value) {
return 'Current plan'
}
// Billing interval and lower plan case
if (!canUpgradeToPlan.value && props.currentPlan?.name !== props.plan.name) {
if (isDowngrade.value) {
return `Downgrade to ${props.plan.name}`
}
// Billing interval change and current plan
if (!isMatchingInterval.value && props.currentPlan?.name === props.plan.name) {
return props.yearlyIntervalSelected
? 'Change to annual plan'
: 'Change to monthly plan'
if (isAnnualToMonthly.value) {
return 'Change to monthly plan'
}
if (isMonthlyToAnnual.value) {
return 'Change to annual plan'
}
// Upgrade case
return canUpgradeToPlan.value ? `Upgrade to ${startCase(props.plan.name)}` : ''
})

const buttonTooltip = computed(() => {
if (isDowngrade.value) {
return 'Downgrading is not supported at the moment. Please contact billing@speckle.systems.'
}

if (isAnnualToMonthly.value) {
return 'Changing from an annual to a monthly plan is currently not supported. Please contact billing@speckle.systems.'
}

return undefined
})

const onCtaClick = () => {
emit('onPlanSelected', props.plan.name)
}
Expand Down