🚑 (billing) Fix disabled upgrade buttons
This commit is contained in:
@ -81,9 +81,7 @@ export const getSubscription = authenticatedProcedure
|
||||
isYearly: currentSubscription.items.data.some((item) => {
|
||||
return (
|
||||
priceIds.STARTER.chats.yearly === item.price.id ||
|
||||
priceIds.STARTER.storage.yearly === item.price.id ||
|
||||
priceIds.PRO.chats.yearly === item.price.id ||
|
||||
priceIds.PRO.storage.yearly === item.price.id
|
||||
priceIds.PRO.chats.yearly === item.price.id
|
||||
)
|
||||
}),
|
||||
currency: currentSubscription.currency as 'usd' | 'eur',
|
||||
@ -98,8 +96,3 @@ export const chatPriceIds = [priceIds.STARTER.chats.monthly]
|
||||
.concat(priceIds.STARTER.chats.yearly)
|
||||
.concat(priceIds.PRO.chats.monthly)
|
||||
.concat(priceIds.PRO.chats.yearly)
|
||||
|
||||
export const storagePriceIds = [priceIds.STARTER.storage.monthly]
|
||||
.concat(priceIds.STARTER.storage.yearly)
|
||||
.concat(priceIds.PRO.storage.monthly)
|
||||
.concat(priceIds.PRO.storage.yearly)
|
||||
|
@ -67,18 +67,11 @@ export const ChangePlanForm = ({ workspace }: Props) => {
|
||||
const handlePayClick = async ({
|
||||
plan,
|
||||
selectedChatsLimitIndex,
|
||||
selectedStorageLimitIndex,
|
||||
}: {
|
||||
plan: 'STARTER' | 'PRO'
|
||||
selectedChatsLimitIndex: number
|
||||
selectedStorageLimitIndex: number
|
||||
}) => {
|
||||
if (
|
||||
!user ||
|
||||
selectedChatsLimitIndex === undefined ||
|
||||
selectedStorageLimitIndex === undefined
|
||||
)
|
||||
return
|
||||
if (!user || selectedChatsLimitIndex === undefined) return
|
||||
|
||||
const newSubscription = {
|
||||
plan,
|
||||
|
@ -44,10 +44,7 @@ type Props = {
|
||||
currency?: 'usd' | 'eur'
|
||||
isLoading: boolean
|
||||
isYearly: boolean
|
||||
onPayClick: (props: {
|
||||
selectedChatsLimitIndex: number
|
||||
selectedStorageLimitIndex: number
|
||||
}) => void
|
||||
onPayClick: (props: { selectedChatsLimitIndex: number }) => void
|
||||
}
|
||||
|
||||
export const ProPlanPricingCard = ({
|
||||
@ -62,27 +59,15 @@ export const ProPlanPricingCard = ({
|
||||
const scopedT = useScopedI18n('billing.pricingCard')
|
||||
const [selectedChatsLimitIndex, setSelectedChatsLimitIndex] =
|
||||
useState<number>()
|
||||
const [selectedStorageLimitIndex, setSelectedStorageLimitIndex] =
|
||||
useState<number>()
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
isDefined(selectedChatsLimitIndex) ||
|
||||
isDefined(selectedStorageLimitIndex)
|
||||
)
|
||||
return
|
||||
if (isDefined(selectedChatsLimitIndex)) return
|
||||
if (workspace.plan !== Plan.PRO) {
|
||||
setSelectedChatsLimitIndex(0)
|
||||
setSelectedStorageLimitIndex(0)
|
||||
return
|
||||
}
|
||||
setSelectedChatsLimitIndex(workspace.additionalChatsIndex ?? 0)
|
||||
}, [
|
||||
selectedChatsLimitIndex,
|
||||
selectedStorageLimitIndex,
|
||||
workspace.additionalChatsIndex,
|
||||
workspace?.plan,
|
||||
])
|
||||
}, [selectedChatsLimitIndex, workspace.additionalChatsIndex, workspace.plan])
|
||||
|
||||
const workspaceChatsLimit = workspace ? getChatsLimit(workspace) : undefined
|
||||
|
||||
@ -92,11 +77,7 @@ export const ProPlanPricingCard = ({
|
||||
isYearly === currentSubscription?.isYearly
|
||||
|
||||
const getButtonLabel = () => {
|
||||
if (
|
||||
selectedChatsLimitIndex === undefined ||
|
||||
selectedStorageLimitIndex === undefined
|
||||
)
|
||||
return ''
|
||||
if (selectedChatsLimitIndex === undefined) return ''
|
||||
if (workspace?.plan === Plan.PRO) {
|
||||
if (isCurrentPlan) return scopedT('upgradeButton.current')
|
||||
|
||||
@ -107,14 +88,9 @@ export const ProPlanPricingCard = ({
|
||||
}
|
||||
|
||||
const handlePayClick = async () => {
|
||||
if (
|
||||
selectedChatsLimitIndex === undefined ||
|
||||
selectedStorageLimitIndex === undefined
|
||||
)
|
||||
return
|
||||
if (selectedChatsLimitIndex === undefined) return
|
||||
onPayClick({
|
||||
selectedChatsLimitIndex,
|
||||
selectedStorageLimitIndex,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -40,10 +40,7 @@ type Props = {
|
||||
currency?: 'eur' | 'usd'
|
||||
isLoading?: boolean
|
||||
isYearly: boolean
|
||||
onPayClick: (props: {
|
||||
selectedChatsLimitIndex: number
|
||||
selectedStorageLimitIndex: number
|
||||
}) => void
|
||||
onPayClick: (props: { selectedChatsLimitIndex: number }) => void
|
||||
}
|
||||
|
||||
export const StarterPlanPricingCard = ({
|
||||
@ -58,27 +55,15 @@ export const StarterPlanPricingCard = ({
|
||||
const scopedT = useScopedI18n('billing.pricingCard')
|
||||
const [selectedChatsLimitIndex, setSelectedChatsLimitIndex] =
|
||||
useState<number>()
|
||||
const [selectedStorageLimitIndex, setSelectedStorageLimitIndex] =
|
||||
useState<number>()
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
isDefined(selectedChatsLimitIndex) ||
|
||||
isDefined(selectedStorageLimitIndex)
|
||||
)
|
||||
return
|
||||
if (isDefined(selectedChatsLimitIndex)) return
|
||||
if (workspace.plan !== Plan.STARTER) {
|
||||
setSelectedChatsLimitIndex(0)
|
||||
setSelectedStorageLimitIndex(0)
|
||||
return
|
||||
}
|
||||
setSelectedChatsLimitIndex(workspace.additionalChatsIndex ?? 0)
|
||||
}, [
|
||||
selectedChatsLimitIndex,
|
||||
selectedStorageLimitIndex,
|
||||
workspace.additionalChatsIndex,
|
||||
workspace?.plan,
|
||||
])
|
||||
}, [selectedChatsLimitIndex, workspace.additionalChatsIndex, workspace.plan])
|
||||
|
||||
const workspaceChatsLimit = workspace ? getChatsLimit(workspace) : undefined
|
||||
|
||||
@ -88,11 +73,7 @@ export const StarterPlanPricingCard = ({
|
||||
isYearly === currentSubscription?.isYearly
|
||||
|
||||
const getButtonLabel = () => {
|
||||
if (
|
||||
selectedChatsLimitIndex === undefined ||
|
||||
selectedStorageLimitIndex === undefined
|
||||
)
|
||||
return ''
|
||||
if (selectedChatsLimitIndex === undefined) return ''
|
||||
if (workspace?.plan === Plan.PRO) return t('downgrade')
|
||||
if (workspace?.plan === Plan.STARTER) {
|
||||
if (isCurrentPlan) return scopedT('upgradeButton.current')
|
||||
@ -107,14 +88,9 @@ export const StarterPlanPricingCard = ({
|
||||
}
|
||||
|
||||
const handlePayClick = async () => {
|
||||
if (
|
||||
selectedChatsLimitIndex === undefined ||
|
||||
selectedStorageLimitIndex === undefined
|
||||
)
|
||||
return
|
||||
if (selectedChatsLimitIndex === undefined) return
|
||||
onPayClick({
|
||||
selectedChatsLimitIndex,
|
||||
selectedStorageLimitIndex,
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user