/** * Conditional Logic Tab * * Top-level Pro tab that provides an overview of all conditional logic rules * configured across checkout fields. This is a dashboard/overview — individual * rules are configured per-field in the field edit dialog. */ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Switch } from "@/components/ui/switch" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table" import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip" import { Zap, ArrowRight, Pencil, Info, } from "lucide-react" import { CheckoutField, conditionalOperators, } from "../../config" interface ConditionalLogicTabProps { fields: CheckoutField[] onEditField: (field: CheckoutField) => void updateField: (id: string, updates: Partial) => void } export function ConditionalLogicTab({ fields, onEditField, updateField, }: ConditionalLogicTabProps) { // Fields that have conditional logic configured (regardless of enabled state) const fieldsWithCL = fields.filter( (f) => f.conditionalLogic && f.conditionalLogic.rules.length > 0 ) // Fields with active (enabled) conditional logic const activeFields = fieldsWithCL.filter((f) => f.conditionalLogic?.enabled) const toggleCLEnabled = (field: CheckoutField) => { if (!field.conditionalLogic) return updateField(field.id, { conditionalLogic: { ...field.conditionalLogic, enabled: !field.conditionalLogic.enabled, }, }) } const getOperatorLabel = (operator: string) => { return ( conditionalOperators.find((o) => o.value === operator)?.label || operator ) } const getFieldLabel = (fieldKey: string) => { const field = fields.find((f) => f.key === fieldKey) return field?.label || fieldKey } return (
{/* Overview Stats */}
Total Rules {fieldsWithCL.length}

Fields with conditional logic configured

Active {activeFields.length}

Fields with conditional logic enabled

Inactive {fieldsWithCL.length - activeFields.length}

Fields with logic configured but disabled

{/* Rules Table */} {fieldsWithCL.length > 0 ? ( Conditional Logic Rules Overview of all conditional logic rules. Click edit to configure individual rules per field. Field Action Rules Active Actions {fieldsWithCL.map((field) => { const cl = field.conditionalLogic! return (
{field.label} ({field.section})
{cl.action}
{cl.rules.slice(0, 2).map((rule, i) => (
{getFieldLabel(rule.field)} {getOperatorLabel(rule.operator)} {rule.value && ( {rule.value} )}
))} {cl.rules.length > 2 && ( +{cl.rules.length - 2} more rule {cl.rules.length - 2 > 1 ? 's' : ''} )} {cl.logic === 'all' ? 'ALL match' : 'ANY match'}
toggleCLEnabled(field)} /> Edit field & conditional logic
) })}
) : ( // Empty State

No Conditional Logic Configured

Conditional logic lets you show, hide, enable, or disable checkout fields based on other field values. To get started, edit a field and configure rules in the Conditional Logic tab.

Go to Field Editor → Edit a field → Conditional Logic tab
)}
) }