import { useLocaleContext } from '@arcblock/ux/lib/Locale/context'; import { Fade, InputAdornment, Stack } from '@mui/material'; import type { SxProps } from '@mui/material'; import { Controller, useFormContext, useWatch } from 'react-hook-form'; import FormInput from '../../components/input'; import FormLabel from '../../components/label'; import CountrySelect from '../../components/country-select'; import { getFieldValidation, validatePostalCode } from '../../libs/validator'; type Props = { mode: string; sx?: SxProps; fieldValidation?: Record; errorPosition?: 'right' | 'bottom'; }; export default function AddressForm({ mode, sx = {}, fieldValidation = {}, errorPosition = 'right' }: Props) { const { t, locale } = useLocaleContext(); const { control } = useFormContext(); const country = useWatch({ control, name: 'billing_address.country' }); if (mode === 'required') { return ( {t('payment.checkout.billing.line1')} {t('payment.checkout.billing.city')} {t('payment.checkout.billing.state')} {t('payment.checkout.billing.postal_code')} { const isValid = validatePostalCode(x, country); return isValid ? true : t('payment.checkout.invalid'); }, ...getFieldValidation('billing_address.postal_code', fieldValidation, locale), }} errorPosition={errorPosition} variant="outlined" placeholder={t('payment.checkout.billing.postal_code')} InputProps={{ startAdornment: ( ( } sx={{ '&.Mui-focused .MuiOutlinedInput-notchedOutline': { borderColor: 'transparent', }, }} /> )} /> ), }} /> ); } return ( {t('payment.checkout.billing.state')} {t('payment.checkout.billing.postal_code')} { const isValid = validatePostalCode(x, country); return isValid ? true : t('payment.checkout.invalid'); }, ...getFieldValidation('billing_address.postal_code', fieldValidation, locale), }} errorPosition={errorPosition} variant="outlined" placeholder={t('payment.checkout.billing.postal_code')} InputProps={{ startAdornment: ( ( } sx={{ '.MuiOutlinedInput-notchedOutline': { borderColor: 'transparent !important', }, }} /> )} /> ), }} /> ); }