Add hidden product option to billing components (#136)
- Introduced `hidden` field in product schema to control product visibility - Updated PlanPicker and PricingTable to filter out hidden products - Ensures hidden products are not displayed to users
This commit is contained in:
committed by
GitHub
parent
3553422e42
commit
b319ceb5bb
@@ -252,6 +252,11 @@ const ProductSchema = z
|
|||||||
description: 'Highlight this product. Displayed to the user.',
|
description: 'Highlight this product. Displayed to the user.',
|
||||||
})
|
})
|
||||||
.optional(),
|
.optional(),
|
||||||
|
hidden: z
|
||||||
|
.boolean({
|
||||||
|
description: 'Hide this product from being displayed to users.',
|
||||||
|
})
|
||||||
|
.optional(),
|
||||||
plans: z.array(PlanSchema),
|
plans: z.array(PlanSchema),
|
||||||
})
|
})
|
||||||
.refine((data) => data.plans.length > 0, {
|
.refine((data) => data.plans.length > 0, {
|
||||||
|
|||||||
@@ -108,6 +108,11 @@ export function PlanPicker(
|
|||||||
const isRecurringPlan =
|
const isRecurringPlan =
|
||||||
selectedPlan?.paymentType === 'recurring' || !selectedPlan;
|
selectedPlan?.paymentType === 'recurring' || !selectedPlan;
|
||||||
|
|
||||||
|
// Always filter out hidden products
|
||||||
|
const visibleProducts = props.config.products.filter(
|
||||||
|
(product) => !product.hidden,
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<div
|
<div
|
||||||
@@ -211,7 +216,7 @@ export function PlanPicker(
|
|||||||
|
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<RadioGroup value={field.value} name={field.name}>
|
<RadioGroup value={field.value} name={field.name}>
|
||||||
{props.config.products.map((product) => {
|
{visibleProducts.map((product) => {
|
||||||
const plan = product.plans.find((item) => {
|
const plan = product.plans.find((item) => {
|
||||||
if (item.paymentType === 'one-time') {
|
if (item.paymentType === 'one-time') {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -54,6 +54,9 @@ export function PricingTable({
|
|||||||
const intervals = getPlanIntervals(config).filter(Boolean) as Interval[];
|
const intervals = getPlanIntervals(config).filter(Boolean) as Interval[];
|
||||||
const [interval, setInterval] = useState(intervals[0]!);
|
const [interval, setInterval] = useState(intervals[0]!);
|
||||||
|
|
||||||
|
// Always filter out hidden products
|
||||||
|
const visibleProducts = config.products.filter((product) => !product.hidden);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={'flex flex-col space-y-8 xl:space-y-12'}>
|
<div className={'flex flex-col space-y-8 xl:space-y-12'}>
|
||||||
<div className={'flex justify-center'}>
|
<div className={'flex justify-center'}>
|
||||||
@@ -72,7 +75,7 @@ export function PricingTable({
|
|||||||
' justify-center lg:flex-row lg:space-x-4'
|
' justify-center lg:flex-row lg:space-x-4'
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{config.products.map((product) => {
|
{visibleProducts.map((product) => {
|
||||||
const plan = product.plans.find((plan) => {
|
const plan = product.plans.find((plan) => {
|
||||||
if (plan.paymentType === 'recurring') {
|
if (plan.paymentType === 'recurring') {
|
||||||
return plan.interval === interval;
|
return plan.interval === interval;
|
||||||
|
|||||||
Reference in New Issue
Block a user