-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #159 from Frnn4268/Frnn
Adding new components for Contact.jsx page
- Loading branch information
Showing
4 changed files
with
168 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React, { useState } from 'react'; | ||
import { Form, Input, AutoComplete, Button, message } from 'antd'; | ||
const { TextArea } = Input; | ||
|
||
const ContactForm = ({ handleSubmit }) => { | ||
const [options, setOptions] = useState([]); | ||
|
||
const handleSearch = (value) => { | ||
setOptions(() => { | ||
if (!value || value.includes('@')) { | ||
return []; | ||
} | ||
return ['gmail.com', 'hotmail.com', 'outlook.com'].map((domain) => ({ | ||
label: `${value}@${domain}`, | ||
value: `${value}@${domain}`, | ||
})); | ||
}); | ||
}; | ||
|
||
return ( | ||
<Form layout="vertical" onFinish={handleSubmit}> | ||
<Form.Item | ||
label='Nombre completo' | ||
name='name' | ||
rules={[ | ||
{ | ||
required: true, | ||
message: 'Por favor ingresa tu nombre' | ||
} | ||
]} | ||
> | ||
<Input size='large' placeholder='Ingresa tu nombre completo'/> | ||
</Form.Item> | ||
<Form.Item | ||
label='Email' | ||
name='email' | ||
rules={[ | ||
{ | ||
required: true, | ||
message: 'Por favor ingresa tu email', | ||
}, | ||
{ | ||
type: 'email', | ||
message: 'Este no es un email válido', | ||
}, | ||
]} | ||
> | ||
<AutoComplete | ||
size='large' | ||
style={{ width: '100%' }} | ||
onSearch={handleSearch} | ||
placeholder="Email" | ||
options={options} | ||
/> | ||
</Form.Item> | ||
<Form.Item | ||
label="Mensaje" | ||
name="message" | ||
rules={[ | ||
{ | ||
required: true, | ||
message: 'Por favor ingresa tu mensaje.' | ||
} | ||
]} | ||
> | ||
<TextArea placeholder="Tu mensaje" rows={5} /> | ||
</Form.Item> | ||
<Form.Item> | ||
<Button type='primary' size='large' className='btn' htmlType="submit"> | ||
Enviar | ||
</Button> | ||
</Form.Item> | ||
</Form> | ||
); | ||
}; | ||
|
||
export default ContactForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import { Typography } from 'antd'; | ||
|
||
const ContactHeader = () => { | ||
return ( | ||
<> | ||
<Typography.Title level={3} strong className='title' style={{textAlign: 'center'}}> | ||
Contacto | ||
</Typography.Title> | ||
<Typography.Title level={5} strong className='title' style={{textAlign: 'center'}}> | ||
Contáctanos para obtener más información. | ||
</Typography.Title> | ||
</> | ||
); | ||
}; | ||
|
||
export default ContactHeader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react'; | ||
import { Layout, Card, Row, Col } from 'antd'; | ||
import MainMenu from '../../components/home/MainMenu.jsx'; | ||
import ContactHeader from './ContactHeader.jsx'; | ||
import ContactForm from './ContactForm.jsx'; | ||
|
||
const { Header, Content } = Layout; | ||
|
||
const backgroundStyle = { | ||
backgroundImage: `linear-gradient(to bottom, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1.5)), url('https://i.postimg.cc/3wBGn5Jc/form-card1.png')`, | ||
backgroundSize: 'cover', | ||
backgroundPosition: 'center', | ||
position: 'relative', | ||
borderRadius: '0 100% 25% 15%' | ||
}; | ||
|
||
const ContactLayout = ({ handleSubmit, contextHolder }) => { | ||
return ( | ||
<Layout className="layout" style={backgroundStyle}> | ||
<Header className='home-header'> | ||
<MainMenu /> | ||
</Header> | ||
<Content style={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}> | ||
<Card className="home-block-section-contact"> | ||
<ContactHeader /> | ||
<Row justify="space-around"> | ||
<Col xs={22} sm={18} md={16} lg={8}> | ||
<ContactForm handleSubmit={handleSubmit} /> | ||
</Col> | ||
</Row> | ||
</Card> | ||
</Content> | ||
{contextHolder} | ||
</Layout> | ||
); | ||
}; | ||
|
||
export default ContactLayout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,141 +1,40 @@ | ||
import React, { useState } from 'react'; | ||
import { Row, Col, Button, Form, Input, AutoComplete, Layout, Card, Typography, message } from 'antd'; | ||
const { TextArea } = Input; | ||
|
||
import MainMenu from '../../../components/home/MainMenu.jsx'; | ||
|
||
import '../../css/Home.css'; | ||
|
||
const { Header, Content } = Layout; | ||
|
||
const backgroundStyle = { | ||
backgroundImage: `linear-gradient(to bottom, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1.5)), url('https://i.postimg.cc/3wBGn5Jc/form-card1.png')`, | ||
backgroundSize: 'cover', | ||
backgroundPosition: 'center', | ||
position: 'relative', | ||
borderRadius: '0 100% 25% 15%' | ||
}; | ||
import { message } from 'antd'; | ||
import ContactLayout from '../../../components/contact/ContactLayout.jsx'; | ||
|
||
const Contact = () => { | ||
const [options, setOptions] = useState([]); | ||
const [messageApi, contextHolder] = message.useMessage(); | ||
|
||
const handleSearch = (value) => { | ||
setOptions(() => { | ||
if (!value || value.includes('@')) { | ||
return []; | ||
} | ||
return ['gmail.com', 'hotmail.com', 'outlook.com'].map((domain) => ({ | ||
label: `${value}@${domain}`, | ||
value: `${value}@${domain}`, | ||
})); | ||
}); | ||
}; | ||
|
||
const success = () => { | ||
messageApi | ||
.loading('Enviando mensaje...', 2.5) | ||
.then(() => message.success('Mensaje enviado correctamente', 2.5)) | ||
.catch(() => message.error('Error al enviar el mensaje', 2.5)); | ||
}; | ||
|
||
const handleSubmit = async (values) => { | ||
try { | ||
const response = await fetch(`${import.meta.env.VITE_APP_API_URL}/contact`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(values), | ||
}); | ||
|
||
if (response.ok) { | ||
success(); | ||
} else { | ||
throw new Error('Error al enviar el mensaje'); | ||
} | ||
} catch (error) { | ||
message.error(error.message); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<Layout className="layout" style={backgroundStyle}> | ||
<Header className='home-header'> | ||
<MainMenu /> | ||
</Header> | ||
<Content style={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}> | ||
<Card className="home-block-section-contact"> | ||
<Typography.Title level={3} strong className='title' style={{textAlign: 'center'}}> | ||
Contacto | ||
</Typography.Title> | ||
<Typography.Title level={5} strong className='title' style={{textAlign: 'center'}}> | ||
Contáctanos para obtener más información. | ||
</Typography.Title> | ||
<Row justify="space-around"> | ||
<Col xs={22} sm={18} md={16} lg={8}> | ||
<Form layout="vertical" onFinish={handleSubmit}> | ||
<Form.Item | ||
label='Nombre completo' | ||
name='name' | ||
rules={[ | ||
{ | ||
required: true, | ||
message: 'Por favor ingresa tu nombre' | ||
} | ||
]} | ||
> | ||
<Input size='large' placeholder='Ingresa tu nombre completo'/> | ||
</Form.Item> | ||
<Form.Item | ||
label='Email' | ||
name='email' | ||
rules={[ | ||
{ | ||
required: true, | ||
message: 'Por favor ingresa tu email', | ||
}, | ||
{ | ||
type: 'email', | ||
message: 'Este no es un email válido', | ||
}, | ||
]} | ||
> | ||
<AutoComplete | ||
size='large' | ||
style={{ width: '100%' }} | ||
onSearch={handleSearch} | ||
placeholder="Email" | ||
options={options} | ||
/> | ||
</Form.Item> | ||
<Form.Item | ||
label="Mensaje" | ||
name="message" | ||
rules={[ | ||
{ | ||
required: true, | ||
message: 'Por favor ingresa tu mensaje.' | ||
} | ||
]} | ||
> | ||
<TextArea placeholder="Tu mensaje" rows={5} /> | ||
</Form.Item> | ||
<Form.Item> | ||
<Button type='primary' size='large' className='btn' htmlType="submit"> | ||
Enviar | ||
</Button> | ||
</Form.Item> | ||
</Form> | ||
</Col> | ||
</Row> | ||
</Card> | ||
</Content> | ||
{contextHolder} | ||
</Layout> | ||
</> | ||
); | ||
} | ||
const [messageApi, contextHolder] = message.useMessage(); | ||
|
||
const success = () => { | ||
messageApi | ||
.loading('Enviando mensaje...', 2.5) | ||
.then(() => message.success('Mensaje enviado correctamente', 2.5)) | ||
.catch(() => message.error('Error al enviar el mensaje', 2.5)); | ||
}; | ||
|
||
const handleSubmit = async (values) => { | ||
try { | ||
const response = await fetch(`${import.meta.env.VITE_APP_API_URL}/contact`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(values), | ||
}); | ||
|
||
if (response.ok) { | ||
success(); | ||
} else { | ||
throw new Error('Error al enviar el mensaje'); | ||
} | ||
} catch (error) { | ||
message.error(error.message); | ||
} | ||
}; | ||
|
||
return ( | ||
<ContactLayout handleSubmit={handleSubmit} contextHolder={contextHolder} /> | ||
); | ||
}; | ||
|
||
export default Contact; | ||
export default Contact; |