import { BaseAddress, MeasurementUnitEnum } from '@bit-ui-libs/common'; import { yupResolver } from '@hookform/resolvers/yup'; import { useState } from 'react'; import { FormProvider, useForm } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; import { ScrollView, View } from 'react-native'; import { boolean, number, object, string } from 'yup'; import { Button, FormTextField, RadioButton, RadioButtonGroup, Text } from '../../../components'; import { tw } from '../../../core'; import { BottomModal } from '../../../layouts'; import { SellTokenShippingForm } from '../schemas'; import CheckBox from '@react-native-community/checkbox'; const FreeShipingChoice = [ { label: 'Yes', value: true, }, { label: 'No', value: false, }, ]; const schema = object().shape({ isFreeShipping: boolean().required(), // @ts-ignore TODO: fix types shippingDetail: object().when('isFreeShipping', { is: false, then: () => object().shape({ weight: number().required('Weight is required').nullable(), length: number().required('Length is required').nullable(), width: number().required('Width is required').nullable(), height: number().required('Height is required').nullable(), handlingFee: number().required('Handling Fee is required').nullable(), unitOfMeasurement: string().required(), packagingType: string().required(), }), }), }); interface TokenDetailsProps { shipFrom?: BaseAddress; onSubmit?: (data: SellTokenShippingForm) => void; onDismiss?: () => void; visible?: boolean; } export function TokenDetailsModal({ onSubmit, visible, onDismiss, shipFrom }: TokenDetailsProps) { const { t } = useTranslation(); const [checked, setChecked] = useState(false); const form = useForm({ mode: 'all', // @ts-ignore TODO: fix types resolver: yupResolver(schema), defaultValues: { isFreeShipping: false, shippingDetail: { unitOfMeasurement: MeasurementUnitEnum.IN, packagingType: '00' }, }, }); const onToggleFreeShipping = (value: boolean) => { form.setValue('isFreeShipping', value); if (value) form.clearErrors(); }; const isFreeShipping = form.watch('isFreeShipping'); return ( {t`marketplace.deliveryOptions`} {t`marketplace.shipFrom`} Free Shipping* onToggleFreeShipping(Boolean(v))} > {FreeShipingChoice.map((shiping, index) => ( ))} {shipFrom && ( null}> Country: {shipFrom.country} State: {shipFrom.state} City: {shipFrom.city} Zip Code: {shipFrom.zip} )} setChecked((v) => !v)} /> {t`marketplace.deliveryConfirmation`} {t`marketplace.shippingHandlingFee`} ); }