2
0

🐛 (billing) Fix currency possible mismatch on sub update

This commit is contained in:
Baptiste Arnaud
2022-11-29 13:17:46 +01:00
parent 43a85b5529
commit f9ffdbc4c5
7 changed files with 18 additions and 5 deletions

View File

@ -42,6 +42,7 @@ export const ChangePlanForm = () => {
workspaceId: workspace.id,
additionalChats: selectedChatsLimitIndex,
additionalStorage: selectedStorageLimitIndex,
currency: data?.currency,
})
if (typeof response === 'object' && response?.error) {
showToast({ description: response.error.message })
@ -75,6 +76,7 @@ export const ChangePlanForm = () => {
onPayClick={(props) =>
handlePayClick({ ...props, plan: Plan.STARTER })
}
currency={data?.currency}
/>
<ProPlanContent
@ -85,6 +87,7 @@ export const ChangePlanForm = () => {
workspace?.plan === Plan.PRO ? data?.additionalStorageIndex : 0
}
onPayClick={(props) => handlePayClick({ ...props, plan: Plan.PRO })}
currency={data?.currency}
/>
</HStack>
<Text color="gray.500">

View File

@ -32,6 +32,7 @@ import { MoreInfoTooltip } from '@/components/MoreInfoTooltip'
type ProPlanContentProps = {
initialChatsLimitIndex?: number
initialStorageLimitIndex?: number
currency?: 'usd' | 'eur'
onPayClick: (props: {
selectedChatsLimitIndex: number
selectedStorageLimitIndex: number
@ -41,6 +42,7 @@ type ProPlanContentProps = {
export const ProPlanContent = ({
initialChatsLimitIndex,
initialStorageLimitIndex,
currency,
onPayClick,
}: ProPlanContentProps) => {
const { workspace } = useWorkspace()
@ -153,7 +155,8 @@ export const ProPlanContent = ({
Plan.PRO,
selectedChatsLimitIndex ?? 0,
selectedStorageLimitIndex ?? 0
) ?? NaN
) ?? NaN,
currency
)}
<chakra.span fontSize="md">/ month</chakra.span>
</Heading>

View File

@ -29,6 +29,7 @@ import { MoreInfoTooltip } from '@/components/MoreInfoTooltip'
type StarterPlanContentProps = {
initialChatsLimitIndex?: number
initialStorageLimitIndex?: number
currency?: 'eur' | 'usd'
onPayClick: (props: {
selectedChatsLimitIndex: number
selectedStorageLimitIndex: number
@ -38,6 +39,7 @@ type StarterPlanContentProps = {
export const StarterPlanContent = ({
initialChatsLimitIndex,
initialStorageLimitIndex,
currency,
onPayClick,
}: StarterPlanContentProps) => {
const { workspace } = useWorkspace()
@ -126,7 +128,8 @@ export const StarterPlanContent = ({
Plan.STARTER,
selectedChatsLimitIndex ?? 0,
selectedStorageLimitIndex ?? 0
) ?? NaN
) ?? NaN,
currency
)}
<chakra.span fontSize="md">/ month</chakra.span>
</Heading>

View File

@ -13,6 +13,7 @@ export const useCurrentSubscriptionInfo = ({
{
additionalChatsIndex: number
additionalStorageIndex: number
currency?: 'eur' | 'usd'
},
Error
>(

View File

@ -15,6 +15,7 @@ type UpgradeProps = {
workspaceId: string
additionalChats: number
additionalStorage: number
currency?: 'eur' | 'usd'
}
export const upgradePlanQuery = async ({
@ -31,6 +32,7 @@ const updatePlan = async ({
workspaceId,
additionalChats,
additionalStorage,
currency,
}: Omit<UpgradeProps, 'user'>): Promise<{ newPlan?: Plan; error?: Error }> => {
const { data, error } = await sendRequest<{ message: string }>({
method: 'PUT',
@ -41,7 +43,7 @@ const updatePlan = async ({
stripeId,
additionalChats,
additionalStorage,
currency: guessIfUserIsEuropean() ? 'eur' : 'usd',
currency: currency ?? (guessIfUserIsEuropean() ? 'eur' : 'usd'),
},
})
if (error || !data) return { error }