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