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 plan of product.plans) {
|
||||
if (plan.lineItems.length > 1) {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
},
|
||||
{
|
||||
message: 'Lemon Squeezy only supports one line item per plan',
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
getPrimaryLineItem,
|
||||
getProductPlanPair,
|
||||
} from '@kit/billing';
|
||||
import config from '@kit/prettier-config/index.mjs';
|
||||
import { formatCurrency } from '@kit/shared/utils';
|
||||
import { Badge } from '@kit/ui/badge';
|
||||
import { Button } from '@kit/ui/button';
|
||||
@@ -153,13 +154,15 @@ export function PlanPicker(
|
||||
id={interval}
|
||||
value={interval}
|
||||
onClick={() => {
|
||||
form.setValue('planId', '', {
|
||||
shouldValidate: true,
|
||||
});
|
||||
if (selectedProduct) {
|
||||
const plan = selectedProduct.plans.find(
|
||||
(item) => item.interval === interval,
|
||||
);
|
||||
|
||||
form.setValue('productId', '', {
|
||||
form.setValue('planId', plan?.id ?? '', {
|
||||
shouldValidate: true,
|
||||
});
|
||||
}
|
||||
|
||||
form.setValue('interval', interval, {
|
||||
shouldValidate: true,
|
||||
|
||||
Reference in New Issue
Block a user