import React, { useEffect } from 'react' import { StyleSheet, Platform, Alert } from 'react-native'; import { useLanguage, SendGiftCard as SendGiftCardController } from 'ordering-components-external/native'; import { useTheme } from 'styled-components/native'; import { OText, OButton, OInput } from '../../shared'; import { useForm, Controller } from 'react-hook-form' import { Container, FormController } from './styles' const SendGiftCardUI = (props: any) => { const { actionState, handleSendGiftCard } = props const theme = useTheme() const [, t] = useLanguage() const { handleSubmit, control, errors } = useForm() const style = StyleSheet.create({ btnStyle: { borderRadius: 7.6, height: 44, marginTop: 20 }, inputStyle: { borderWidth: 1, borderColor: theme.colors.border, borderRadius: 7.6, }, }) const onSubmit = (values) => { handleSendGiftCard(values) } useEffect(() => { if (Object.keys(errors).length > 0) { const list = Object.values(errors) let stringError = '' list.map((item: any, i: number) => { stringError += (i + 1) === list.length ? `- ${item.message}` : `- ${item.message}\n` }) Alert.alert( t('ERROR', 'Error'), stringError, [ { text: t('OK', 'oK'), onPress: () => { } } ] ) } }, [errors]) return ( {t('GIFT_CARD_DETAILS', 'Gift Card details')} {t('TO', 'To')} ( onChange(val)} autoCompleteType='email' autoCapitalize='none' autoCorrect={false} type='email-address' blurOnSubmit={false} style={style.inputStyle} /> )} name='email' rules={{ required: t('VALIDATION_ERROR_REQUIRED', 'To email is required').replace('_attribute_', t('EMAIL', 'EMail')) }} defaultValue="" /> {t('NAME', 'Name')} ( onChange(val)} autoCapitalize='none' autoCorrect={false} blurOnSubmit={false} style={style.inputStyle} /> )} name='user_name' defaultValue="" /> {t('TITLE', 'Title')} ( onChange(val)} autoCapitalize='none' autoCorrect={false} blurOnSubmit={false} style={style.inputStyle} /> )} name='title' defaultValue="" /> {t('MESSAGES', 'Messages')} ( onChange(val)} autoCapitalize='none' autoCorrect={false} blurOnSubmit={false} style={{ ...style.inputStyle, height: 100, alignItems: 'flex-start', }} /> )} name='message' defaultValue="" /> ) } export const SendGiftCard = (props: any) => { const sendGiftCardProps = { ...props, showToastMsg: true, UIComponent: SendGiftCardUI } return }