import { Heading, Input, Select, clx } from "@medusajs/ui" import { useTranslation } from "react-i18next" import { z } from "zod" import { HttpTypes } from "@medusajs/types" import { Control } from "react-hook-form" import { AddressSchema } from "../../../lib/schemas" import { Form } from "../../common/form" import { CountrySelect } from "../../inputs/country-select" import { useDocumentDirection } from "../../../hooks/use-document-direction" type AddressFieldValues = z.infer type AddressFormProps = { control: Control countries?: HttpTypes.AdminRegionCountry[] layout: "grid" | "stack" } export const AddressForm = ({ control, countries, layout, }: AddressFormProps) => { const { t } = useTranslation() const direction = useDocumentDirection() const style = clx("gap-4", { "flex flex-col": layout === "stack", "grid grid-cols-2": layout === "grid", }) return (
{t("addresses.contactHeading")}
{ return ( {t("fields.firstName")} ) }} /> { return ( {t("fields.lastName")} ) }} /> { return ( {t("fields.company")} ) }} /> { return ( {t("fields.phone")} ) }} />
{t("addresses.locationHeading")}
{ return ( {t("fields.address")} ) }} /> { return ( {t("fields.address2")} ) }} /> { return ( {t("fields.city")} ) }} /> { return ( {t("fields.postalCode")} ) }} /> { return ( {t("fields.province")} ) }} /> { return ( {t("fields.country")} {countries ? ( ) : ( // When no countries are provided, use the country select component that has a built-in list of all countries )} ) }} />
) }