-
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 #156 from Actualiza-Tu-Carro/134-formulariodecontacto
134 formulariodecontacto
- Loading branch information
Showing
12 changed files
with
240 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,22 @@ | ||
import React from 'react'; | ||
|
||
export default function Close() { | ||
return ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
className="icon icon-tabler icon-tabler-x" | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
strokeWidth="2" | ||
stroke="currentColor" | ||
fill="none" | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
> | ||
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path> | ||
<path d="M18 6l-12 12"></path> | ||
<path d="M6 6l12 12"></path> | ||
</svg> | ||
); | ||
} |
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
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
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,143 @@ | ||
'use client'; | ||
import React, { FC } from 'react'; | ||
import { useForm, SubmitHandler } from 'react-hook-form'; | ||
import { InputField } from '../inputs/InputField'; | ||
import { MainButton } from '../button/button'; | ||
import Icon from '~/assets/icons/icon'; | ||
import Swal from 'sweetalert2'; | ||
|
||
interface FormProp { | ||
updateState: (flagState: boolean) => void; // Corregido el tipo de isOpenContact | ||
} | ||
|
||
interface FormProps { | ||
name: string; | ||
phone: string; | ||
message: string; | ||
} | ||
|
||
const Form: FC<FormProp> = ({ updateState }) => { | ||
const { | ||
register, | ||
handleSubmit, | ||
reset, | ||
formState: { errors }, | ||
} = useForm<FormProps>(); | ||
|
||
const handleFormSubmit: SubmitHandler<FormProps> = (data, event) => { | ||
event?.preventDefault(); | ||
if (!errors.name || !errors.phone || !errors.message) { | ||
updateState(false); | ||
alertSuccess(); | ||
console.log(data); | ||
} | ||
}; | ||
|
||
const alertSuccess = () => { | ||
Swal.fire({ | ||
toast: true, | ||
position: 'top-end', | ||
title: 'Enviado!', | ||
text: 'El mensaje a sido enviado correctamente', | ||
icon: 'success', | ||
showConfirmButton: false, | ||
timer: 2000, | ||
}); | ||
}; | ||
|
||
return ( | ||
<form | ||
onSubmit={handleSubmit(handleFormSubmit)} | ||
className="fixed inset-0 flex items-center justify-center z-50 bg-[rgba(0,0,0,.5)]" | ||
> | ||
<div className="relative flex p-6 px-14 pt-10 flex-col bg-white xs:w-[440px] gap-4 rounded-xl shadow-xl w-full"> | ||
<h1 className="text-[40px] font-bold py-1 overflow-hidden text-ellipsis"> | ||
Contacto | ||
</h1> | ||
<p className="text-xs"> | ||
¿Tienes preguntas o necesitas ayuda para tu compra? ¡Contáctanos! | ||
Nuestro equipo está aquí para asistirte. | ||
</p> | ||
<input | ||
placeholder="Nombre" | ||
{...register('name', { | ||
required: 'Nombre requerido', | ||
minLength: { | ||
value: 3, | ||
message: 'Debe tener minimo 3 caracteres', | ||
}, | ||
pattern: { | ||
value: /^[A-Za-z]+$/, | ||
message: 'Ingresa solo letras', | ||
}, | ||
})} | ||
autoComplete="off" | ||
className="bg-input-bg `w-full px-3 outline-none rounded-md text-secondary-dm text-xs py-3" | ||
/> | ||
{errors.name && ( | ||
<p className="text-primary-lm">{errors.name.message}</p> | ||
)} | ||
|
||
<input | ||
placeholder={ | ||
errors.phone | ||
? 'Mobil empieza por 3, longitud minima 10 caracteres' | ||
: 'Mobil / Correo' | ||
} | ||
{...register('phone', { | ||
required: 'Telefono o Correo requerido', | ||
validate: (value) => | ||
/^3\d{9}$/.test(value) || | ||
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test( | ||
value | ||
) || | ||
'Mobil o Correo invalidos', | ||
})} | ||
autoComplete="off" | ||
className="bg-input-bg `w-full px-3 outline-none rounded-md text-secondary-dm text-xs py-3" | ||
/> | ||
{errors.phone && ( | ||
<p className="text-primary-lm">{errors.phone.message}</p> | ||
)} | ||
|
||
<textarea | ||
placeholder="Mensaje" | ||
{...register('message', { | ||
required: 'Mensaje requerido', | ||
maxLength: { | ||
value: 200, | ||
message: 'Mensaje debe tener maximo 400 caracteres', | ||
}, | ||
})} | ||
autoComplete="off" | ||
className="bg-input-bg px-3 py-3 rounded-md autocomplete=off outline-none min-h-[100px] text-xs" | ||
/> | ||
{errors.message && ( | ||
<p className="text-primary-lm">{errors.message.message}</p> | ||
)} | ||
|
||
<MainButton | ||
variant="tertiary" | ||
type="submit" | ||
className="bg-primary-lm text-white py-3 rounded-md" | ||
> | ||
ENVIAR | ||
</MainButton> | ||
|
||
<MainButton | ||
type="button" | ||
onClick={() => { | ||
updateState(false); | ||
}} | ||
className="absolute top-2 right-2" | ||
> | ||
<div className="h-6 w-6"> | ||
<Icon icon="Close" /> | ||
</div> | ||
</MainButton> | ||
</div> | ||
</form> | ||
); | ||
}; | ||
|
||
export default Form; |
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
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
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,11 @@ | ||
import { useState } from 'react'; | ||
|
||
export function useFlagState(initialValue: boolean) { | ||
const [flagState, setFlagState] = useState<boolean>(initialValue); // Tipa isOpenContact como boolean. | ||
|
||
const updateState = (newValue: boolean): void => { | ||
setFlagState(newValue); | ||
}; | ||
|
||
return [flagState, updateState] as const; // Tipa la tupla de retorno como constante. | ||
} |
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 +1 @@ | ||
export type IconTypes = | 'CardCredit' | 'CarShoping' | 'Cash' | 'Facebook' | 'HamburguerClose' | 'HamburguerOpen' | 'Heart' | 'icon' | 'Instagram' | 'Login' | 'MapLocation' | 'Moon' | 'quotationMarks' | 'SearchIcon' | 'Shield' | 'Sun' | 'Truck' | 'warranty' | 'Whatsapp' | ||
export type IconTypes = | 'CardCredit' | 'CarShoping' | 'Cash' | 'Close' | 'Facebook' | 'HamburguerClose' | 'HamburguerOpen' | 'Heart' | 'icon' | 'Instagram' | 'Login' | 'MapLocation' | 'Moon' | 'quotationMarks' | 'SearchIcon' | 'Shield' | 'Sun' | 'Truck' | 'warranty' | 'Whatsapp' |
Oops, something went wrong.