"use client" import { setAddresses } from "@lib/data/cart" import useToggleState from "@lib/hooks/use-toggle-state" import compareAddresses from "@lib/util/compare-addresses" import { CheckCircle2 as CheckCircleSolid } from "lucide-react" import { HttpTypes } from "@medusajs/types" import Divider from "@modules/common/components/divider" import { Heading, Text } from "@modules/common/components/ui" import Spinner from "@modules/common/icons/spinner" import { usePathname, useRouter, useSearchParams } from "next/navigation" import { useActionState } from "react" import BillingAddress from "../billing_address" import ErrorMessage from "../error-message" import ShippingAddress from "../shipping-address" import { SubmitButton } from "../submit-button" const Addresses = ({ cart, customer, }: { cart: HttpTypes.StoreCart | null customer: HttpTypes.StoreCustomer | null }) => { const searchParams = useSearchParams() const router = useRouter() const pathname = usePathname() const isOpen = searchParams.get("step") === "address" const { state: sameAsBilling, toggle: toggleSameAsBilling } = useToggleState( cart?.shipping_address && cart?.billing_address ? compareAddresses(cart?.shipping_address, cart?.billing_address) : true ) const handleEdit = () => { router.push(pathname + "?step=address") } const [message, formAction] = useActionState(setAddresses, null) return (
Adresa dostave {!isOpen && } {!isOpen && cart?.shipping_address && ( )}
{isOpen ? (
{!sameAsBilling && (
Adresa za račun
)} Nastavite na dostavu
) : (
{cart && cart.shipping_address ? (
Adresa dostave {cart.shipping_address.first_name}{" "} {cart.shipping_address.last_name} {cart.shipping_address.address_1}{" "} {cart.shipping_address.address_2} {cart.shipping_address.postal_code},{" "} {cart.shipping_address.city} {cart.shipping_address.country_code?.toUpperCase()}
Kontakt {cart.shipping_address.phone} {cart.email}
Adresa za račun {sameAsBilling ? ( Adresa za račun ista je kao adresa dostave. ) : ( <> {cart.billing_address?.first_name}{" "} {cart.billing_address?.last_name} {cart.billing_address?.address_1}{" "} {cart.billing_address?.address_2} {cart.billing_address?.postal_code},{" "} {cart.billing_address?.city} {cart.billing_address?.country_code?.toUpperCase()} )}
) : (
)}
)}
) } export default Addresses