'use client' import * as z from 'zod' import { useForm } from 'react-hook-form' import { zodResolver } from '@hookform/resolvers/zod' import { Input, Button, Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@hanzo/ui/primitives' import { Form, FormControl, FormField, FormItem, FormMessage, } from '@hanzo/ui/form' import { useCommerce } from '../../service/context' import countries from '../../util/countries' import { sendGAEvent } from '../../util/analytics' import type { CheckoutStepComponentProps } from '../../types' const shippingFormSchema = z.object({ addressLine1: z.string().min(2, 'Address must be at least 2 characters.'), addressLine2: z.string().optional(), zipCode: z.string().min(2, 'Zip code is invalid.'), city: z.string().min(2, 'City is invalid.'), state: z.string().optional(), country: z.string().min(2, 'Country is invalid.'), }) const ShippingStepForm: React.FC = ({ orderId, onDone }) => { const cmmc = useCommerce() const shippingForm = useForm>({ resolver: zodResolver(shippingFormSchema as any), defaultValues: { addressLine1: '', addressLine2: '', zipCode: '', city: '', state: '', country: '', }, }) const onSubmit = async (values: z.infer) => { if (orderId) { await cmmc.updateOrderShippingInfo(orderId, values) } sendGAEvent('add_shipping_info', { items: cmmc.cartItems.map((item) => ({ item_id: item.sku, item_name: item.title, item_category: item.familyId, price: item.price, quantity: item.quantity })), num_items: cmmc.cartItems.length, value: cmmc.cartTotal, currency: 'USD', }) onDone() } return (
( )} /> ( )} />
( )} /> ( )} />
( )} /> ( )} />
) } export default ShippingStepForm