All files / src/lib/schemas checkout.ts

0% Statements 0/21
100% Branches 0/0
0% Functions 0/1
0% Lines 0/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22                                           
import { z } from "zod";

// Address schema (reusable for both shipping and billing)
const addressSchema = z.object({
  street: z.string().min(1, "Street address is required"),
  city: z.string().min(1, "City is required"),
  state: z.string().min(1, "State/Province is required"),
  zipCode: z
    .string()
    .min(1, "ZIP/Postal code is required")
    .regex(/^[0-9]{5}(-[0-9]{4})?$|^[A-Z][0-9][A-Z] [0-9][A-Z][0-9]$/, "Invalid ZIP/Postal code format"),
  country: z.string().min(1, "Country is required")});

// Checkout form schema
export const checkoutSchema = z.object({
  shippingAddress: addressSchema,
  billingAddress: addressSchema,
  paymentMethod: z.enum(["credit_card", "paypal", "bank_transfer"]),
  notes: z.string().optional()});

export type CheckoutFormData = z.infer<typeof checkoutSchema>;