|
|
@ -1,9 +1,9 @@ |
|
|
import { Button, Form, Input, Select } from 'antd'; |
|
|
import { Button, Form, Input, Select } from 'antd'; |
|
|
import styles from '../pages/Cliente/Cliente.module.css'; |
|
|
import styles from '../pages/Cliente/Cliente.module.css'; |
|
|
import { useEffect } from 'react'; |
|
|
import { useEffect } from 'react'; |
|
|
import { |
|
|
|
|
|
|
|
|
import { |
|
|
getAllPaises |
|
|
getAllPaises |
|
|
} from '../slices/ClienteSlice'; |
|
|
|
|
|
|
|
|
} from '../slices/ClienteSlice'; |
|
|
import { useDispatch, useSelector } from 'react-redux'; |
|
|
import { useDispatch, useSelector } from 'react-redux'; |
|
|
import { Cliente } from '../interfaces/Cliente'; |
|
|
import { Cliente } from '../interfaces/Cliente'; |
|
|
|
|
|
|
|
|
@ -14,88 +14,95 @@ export interface FormClienteProps { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function ClienteForm(props: FormClienteProps) { |
|
|
function ClienteForm(props: FormClienteProps) { |
|
|
const {paises} = useSelector((state:any)=>state.cliente); |
|
|
|
|
|
|
|
|
const { paises, loading} = useSelector((state: any) => state.cliente); |
|
|
const dispatch = useDispatch<any>(); |
|
|
const dispatch = useDispatch<any>(); |
|
|
|
|
|
|
|
|
const onFinish = (values: any) => { |
|
|
const onFinish = (values: any) => { |
|
|
const cliente:Cliente = { |
|
|
|
|
|
nome:values.nome, |
|
|
|
|
|
email:values.email, |
|
|
|
|
|
telefone:values.telefone, |
|
|
|
|
|
pais:{ |
|
|
|
|
|
uid:values.pais, |
|
|
|
|
|
nome:'' |
|
|
|
|
|
|
|
|
const cliente: Cliente = { |
|
|
|
|
|
nome: values.nome, |
|
|
|
|
|
email: values.email, |
|
|
|
|
|
telefone: values.telefone, |
|
|
|
|
|
pais: { |
|
|
|
|
|
uid: values.pais, |
|
|
|
|
|
nome: '' |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
props.eventEmiter(cliente); |
|
|
props.eventEmiter(cliente); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const onFinishFailed = (errorInfo: any) => { |
|
|
const onFinishFailed = (errorInfo: any) => { |
|
|
console.log('Failed:', errorInfo); |
|
|
|
|
|
|
|
|
console.log('Failed:', errorInfo); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
useEffect(() => { |
|
|
dispatch(getAllPaises()) |
|
|
|
|
|
|
|
|
dispatch(getAllPaises()) |
|
|
}, []); |
|
|
}, []); |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<> |
|
|
<> |
|
|
<Form |
|
|
|
|
|
className={styles.form_cliente} |
|
|
|
|
|
name="basic" |
|
|
|
|
|
layout="vertical" |
|
|
|
|
|
initialValues={{ remember: true }} |
|
|
|
|
|
onFinish={onFinish} |
|
|
|
|
|
onFinishFailed={onFinishFailed} |
|
|
|
|
|
autoComplete="off" |
|
|
|
|
|
> |
|
|
|
|
|
<Form.Item |
|
|
|
|
|
label="Nome" |
|
|
|
|
|
name="nome" |
|
|
|
|
|
initialValue={props.values ? props.values.nome : ''} |
|
|
|
|
|
rules={[{ required: true, message: 'Nome é obrigatorio!' }]} |
|
|
|
|
|
|
|
|
<Form |
|
|
|
|
|
className={styles.form_cliente} |
|
|
|
|
|
name="basic" |
|
|
|
|
|
layout="vertical" |
|
|
|
|
|
initialValues={{ remember: true }} |
|
|
|
|
|
onFinish={onFinish} |
|
|
|
|
|
onFinishFailed={onFinishFailed} |
|
|
|
|
|
autoComplete="off" |
|
|
> |
|
|
> |
|
|
<Input /> |
|
|
|
|
|
</Form.Item> |
|
|
|
|
|
|
|
|
<Form.Item |
|
|
|
|
|
label="Nome" |
|
|
|
|
|
name="nome" |
|
|
|
|
|
initialValue={props.values ? props.values.nome : ''} |
|
|
|
|
|
rules={[{ required: true, message: 'Nome é obrigatorio!' }]} |
|
|
|
|
|
> |
|
|
|
|
|
<Input /> |
|
|
|
|
|
</Form.Item> |
|
|
|
|
|
|
|
|
<Form.Item |
|
|
|
|
|
label="E-mail" |
|
|
|
|
|
name="email" |
|
|
|
|
|
initialValue={props.values ? props.values.email : ''} |
|
|
|
|
|
rules={[{ required: true, message: 'E-mail é obrigatorio!' }]} |
|
|
|
|
|
> |
|
|
|
|
|
<Input type='email' /> |
|
|
|
|
|
</Form.Item> |
|
|
|
|
|
|
|
|
<Form.Item |
|
|
|
|
|
label="E-mail" |
|
|
|
|
|
name="email" |
|
|
|
|
|
initialValue={props.values ? props.values.email : ''} |
|
|
|
|
|
rules={[{ required: true, message: 'E-mail é obrigatorio!' }]} |
|
|
|
|
|
> |
|
|
|
|
|
<Input type='email' /> |
|
|
|
|
|
</Form.Item> |
|
|
|
|
|
|
|
|
<Form.Item |
|
|
|
|
|
label="Telefone" |
|
|
|
|
|
name="telefone" |
|
|
|
|
|
initialValue={props.values ? props.values.telefone : ''} |
|
|
|
|
|
rules={[{ required: true, message: 'Numero de telefone é obrigatorio!' }]} |
|
|
|
|
|
> |
|
|
|
|
|
<Input /> |
|
|
|
|
|
</Form.Item> |
|
|
|
|
|
|
|
|
<Form.Item |
|
|
|
|
|
label="Telefone" |
|
|
|
|
|
name="telefone" |
|
|
|
|
|
initialValue={props.values ? props.values.telefone : ''} |
|
|
|
|
|
rules={[{ required: true, message: 'Numero de telefone é obrigatorio!' }]} |
|
|
|
|
|
> |
|
|
|
|
|
<Input /> |
|
|
|
|
|
</Form.Item> |
|
|
|
|
|
|
|
|
<Form.Item |
|
|
|
|
|
label="Pais" |
|
|
|
|
|
name="pais" |
|
|
|
|
|
rules={[{ required: true, message: 'É obrigatorio informar o pais!' }]} |
|
|
|
|
|
> |
|
|
|
|
|
<Select |
|
|
|
|
|
options={ |
|
|
|
|
|
paises.map((cliente:any)=>( |
|
|
|
|
|
{value:cliente.uid,label:cliente.nome} |
|
|
|
|
|
)) |
|
|
|
|
|
} |
|
|
|
|
|
/> |
|
|
|
|
|
</Form.Item> |
|
|
|
|
|
|
|
|
<Form.Item |
|
|
|
|
|
label="Pais" |
|
|
|
|
|
name="pais" |
|
|
|
|
|
rules={[{ required: true, message: 'É obrigatorio informar o pais!' }]} |
|
|
|
|
|
> |
|
|
|
|
|
<Select |
|
|
|
|
|
options={ |
|
|
|
|
|
paises.map((cliente: any) => ( |
|
|
|
|
|
{ value: cliente.uid, label: cliente.nome } |
|
|
|
|
|
)) |
|
|
|
|
|
} |
|
|
|
|
|
/> |
|
|
|
|
|
</Form.Item> |
|
|
|
|
|
|
|
|
<Form.Item> |
|
|
|
|
|
<Button type="primary" htmlType="submit"> |
|
|
|
|
|
{props.btnTitle} |
|
|
|
|
|
</Button> |
|
|
|
|
|
</Form.Item> |
|
|
|
|
|
</Form> |
|
|
|
|
|
|
|
|
<Form.Item> |
|
|
|
|
|
{(loading === false) && ( |
|
|
|
|
|
<Button type="primary" htmlType="submit"> |
|
|
|
|
|
{props.btnTitle} |
|
|
|
|
|
</Button> |
|
|
|
|
|
)} |
|
|
|
|
|
{(loading === true) && ( |
|
|
|
|
|
<Button type="primary" loading> |
|
|
|
|
|
Aguarde... |
|
|
|
|
|
</Button> |
|
|
|
|
|
)} |
|
|
|
|
|
</Form.Item> |
|
|
|
|
|
</Form> |
|
|
</> |
|
|
</> |
|
|
) |
|
|
) |
|
|
} |
|
|
} |
|
|
|