Update billing schema and plan picker logic
Modified the logic in create-billing-schema.ts so if a plan contains more than one line item, it no longer returns true but false. In plan-picker.tsx, added a condition to check if a product is selected before setting the 'planId'. Also, the 'planId' is now set based on the selected plan's id rather than an empty string.
This commit is contained in:
@@ -215,13 +215,13 @@ const BillingSchema = z
|
|||||||
for (const product of schema.products) {
|
for (const product of schema.products) {
|
||||||
for (const plan of product.plans) {
|
for (const plan of product.plans) {
|
||||||
if (plan.lineItems.length > 1) {
|
if (plan.lineItems.length > 1) {
|
||||||
return true;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
message: 'Lemon Squeezy only supports one line item per plan',
|
message: 'Lemon Squeezy only supports one line item per plan',
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
getPrimaryLineItem,
|
getPrimaryLineItem,
|
||||||
getProductPlanPair,
|
getProductPlanPair,
|
||||||
} from '@kit/billing';
|
} from '@kit/billing';
|
||||||
|
import config from '@kit/prettier-config/index.mjs';
|
||||||
import { formatCurrency } from '@kit/shared/utils';
|
import { formatCurrency } from '@kit/shared/utils';
|
||||||
import { Badge } from '@kit/ui/badge';
|
import { Badge } from '@kit/ui/badge';
|
||||||
import { Button } from '@kit/ui/button';
|
import { Button } from '@kit/ui/button';
|
||||||
@@ -153,13 +154,15 @@ export function PlanPicker(
|
|||||||
id={interval}
|
id={interval}
|
||||||
value={interval}
|
value={interval}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
form.setValue('planId', '', {
|
if (selectedProduct) {
|
||||||
shouldValidate: true,
|
const plan = selectedProduct.plans.find(
|
||||||
});
|
(item) => item.interval === interval,
|
||||||
|
);
|
||||||
|
|
||||||
form.setValue('productId', '', {
|
form.setValue('planId', plan?.id ?? '', {
|
||||||
shouldValidate: true,
|
shouldValidate: true,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
form.setValue('interval', interval, {
|
form.setValue('interval', interval, {
|
||||||
shouldValidate: true,
|
shouldValidate: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user