'use client'; import { TruckIcon } from '@heroicons/react/24/outline'; import Price from 'components/price'; import SideDialog from 'components/side-dialog'; import { DELIVERY_OPTION_KEY } from 'lib/constants'; import { cn, createUrl } from 'lib/utils'; import { usePathname, useRouter, useSearchParams } from 'next/navigation'; import { ReactNode, useState } from 'react'; const options = ['Commercial', 'Residential'] as const; type Option = (typeof options)[number]; export const deliveryOptions: Array<{ key: Option; template: ReactNode; price: number; }> = [ { template: Commercial, price: 299, key: 'Commercial' }, { template: Residential, price: 398, key: 'Residential' } ]; const Delivery = () => { const searchParams = useSearchParams(); const pathname = usePathname(); const router = useRouter(); const [openingDialog, setOpeningDialog] = useState<'information' | 'terms-conditions' | null>( null ); const newSearchParams = new URLSearchParams(searchParams.toString()); const selectedDeliveryOption = newSearchParams.get(DELIVERY_OPTION_KEY); const handleSelectDelivery = (option: Option) => { newSearchParams.set(DELIVERY_OPTION_KEY, option); const newUrl = createUrl(pathname, newSearchParams); router.replace(newUrl, { scroll: false }); }; if (!selectedDeliveryOption) { handleSelectDelivery(options[0]); } return (
Information
Terms & Conditions