Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #105 from igrowker/javi-branch
Browse files Browse the repository at this point in the history
Varias modificaciones
  • Loading branch information
Gavbriel015 authored Dec 6, 2024
2 parents 624bcbb + 52e55e5 commit 0c63bb9
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 64 deletions.
5 changes: 5 additions & 0 deletions src/components/ConfirmRegister/ConfirmRegister.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@
padding: 0; /* Sin relleno */
}

.resend-button:hover {
@apply bg-transparent text-tertiary;
}

.resend-button:disabled {
background-color: transparent;
cursor: not-allowed;
color: #d1d5db; /* Gris claro cuando está deshabilitado */
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ConfirmationView/ConfirmationView.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.logoClassName {
transform: scale(2.2); /* Escala la imagen al 220% */
transform: scale(1.5); /* Escala la imagen al 220% */
transition: transform 0.3s ease; /* Suaviza la animación de escala */
object-fit: contain; /* Asegura que la imagen no se recorte ni pierda proporción */
width: 100%; /* Ajusta el tamaño al 100% del contenedor */
Expand Down
20 changes: 12 additions & 8 deletions src/components/ConfirmationView/ConfirmationView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ import AuthLayout from "../../layout/AuthLayout"; // Importamos AuthLayout
import vacationImage from "../../assets/img/vacationImage.png"; // Asegúrate de tener la imagen en esta ruta
import { Link } from "react-router-dom";
import './ConfirmationView.css';
import { useContext } from "react";
import { ReservationContext } from "../../contexts/reservation.context";

const ConfirmationView = () => {

const { experience, reservation } = useContext(ReservationContext)

return (
<AuthLayout showText={false} logoClassName="logoClassName" showBackButton={false}> {/* Solo aquí se pasa la clase personalizada */}
<div className="w-full max-w-md"> {/* Ajustamos la altura para que no haya un exceso de margen blanco */}
<AuthLayout showText={false} logoClassName="logoClassName" showTextImage={false} showBackButton={false}> {/* Solo aquí se pasa la clase personalizada */}
<div className="w-full max-w-md p-2"> {/* Ajustamos la altura para que no haya un exceso de margen blanco */}
{/* Contenido principal */}
<div className="text-center mt-[100px] mb-0"> {/* Ajuste en el margin-top para centrar más el contenido, y eliminamos el margen inferior */}
<h2 className="text-lg font-bold text-gray-800 mb-6 text-left">¡Experiencia confirmada!</h2>

{/* Información de la reserva */}
<div className="flex items-center justify-start gap-4 mb-4">
<div className="flex justify-start gap-4 mb-4">
<div className="relative">
<img
src={vacationImage} // Aquí se usa la nueva imagen
Expand All @@ -23,24 +27,24 @@ const ConfirmationView = () => {
/>
</div>
<div>
<p className="text-lg font-semibold text-gray-800">Cocktail en la playa</p>
<p className="text-sm text-gray-600">Order number #837nx38</p>
<p className="text-lg font-semibold text-gray-800">{ experience?.title }</p>
<p className="text-sm text-gray-600"></p>
</div>
</div>

{/* Detalles adicionales con margen ajustado */}
<div className="text-left mb-12 mt-6 ml-1"> {/* Ajuste de márgenes */}
<p className="flex items-center text-dark mb-2">
<FaCalendarAlt className="text-brandYellow mr-2" />
<span>13 al 15 de noviembre</span>
<span>{ reservation?.bookingDate?.toLocaleDateString() }</span>
</p>
<p className="flex items-center text-dark mb-2">
<FaClock className="text-brandYellow mr-2" />
<span>18:00 hs</span>
<span>{ reservation?.bookingDate?.toLocaleTimeString() }</span>
</p>
<p className="flex items-center text-dark">
<FaMapMarkerAlt className="text-brandYellow mr-2" />
<span>Malibu Beach, California</span>
<span>{ experience?.location[1] }, { experience?.location[0] }</span>
</p>
</div>

Expand Down
59 changes: 29 additions & 30 deletions src/components/LoginForm/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { zodResolver } from "@hookform/resolvers/zod";
import { LoginSchema, loginSchema } from "../../schemas/login.schema";
import { useContext, useState } from "react";
import { AxiosError } from "axios";
import { useNavigate } from "react-router-dom"; // Para redirección
import AuthLayout from "../../layout/AuthLayout.tsx"; // Asegúrate de importar el AuthLayout
import "./LoginForm.css";
import { useNavigate } from "react-router-dom";
import AuthLayout from "../../layout/AuthLayout.tsx";
import authServices from "../../services/auth.services.ts";
import { AuthContext } from "../../contexts/auth.context.tsx";
import { User } from "../../types/user.ts";
// import "./LoginForm.css";

const Login: React.FC = () => {
const {
Expand All @@ -24,6 +24,7 @@ const Login: React.FC = () => {
// Manejo de notificaciones
const [reqError, setReqError] = useState<string | null>(null);
const [successNotification, setSuccessNotification] = useState<string | null>(null);

const { setUser } = useContext(AuthContext);
const navigate = useNavigate();

Expand All @@ -34,25 +35,28 @@ const Login: React.FC = () => {

// Si la respuesta es exitosa
if (response.status === 200) {
reset(); // Limpiar el formulario
setSuccessNotification("Inicio de sesión exitoso");

console.log(response.data);
// Guardar el token en localStorage o en un estado global (ejemplo)
localStorage.setItem("authToken", response.data.token);
// console.log(response.data);

const user: User = {
...response.data.user,
_id: response.data.userId,
};

console.log(user);
localStorage.setItem("authToken", response.data.token);
localStorage.setItem("user", JSON.stringify(user));
setUser(user);

// console.log(user);
// Redirigir después de un tiempo
setTimeout(() => navigate("/"), 2000);
setTimeout(() => {
reset(); // Limpiar el formulario
setUser(user)
navigate("/")
}, 2000);
}


} catch (error) {
// Manejo de errores
if (error instanceof AxiosError && error.response?.data) {
Expand All @@ -62,21 +66,15 @@ const Login: React.FC = () => {
setReqError(error.response.data.message);
}
} else {
setReqError("Error desconocido. Por favor intente de nuevo.");
console.log(error)
setReqError("Error en la comunicación con el servidor");
}
setTimeout(() => setReqError(null), 5000);
}
};

return (
<AuthLayout>
{/* Mostrar errores globales en la parte superior */}
{reqError && (
<div className="form__global-error-container">
<span className="form__error-message">{reqError}</span>
</div>
)}

{/* Formulario de inicio de sesión */}
<form
onSubmit={handleSubmit(onSubmit)}
Expand All @@ -90,6 +88,9 @@ const Login: React.FC = () => {
id="email"
placeholder="[email protected]"
/>
{errors.email && (
<span className="form__error-validation">{errors.email.message}</span>
)}
</div>
<div>
<label htmlFor="password">Contraseña</label>
Expand All @@ -99,6 +100,9 @@ const Login: React.FC = () => {
id="password"
placeholder="••••••••"
/>
{errors.password && (
<span className="form__error-validation">{errors.password.message}</span>
)}
</div>
<div className="text-right">
<a
Expand All @@ -124,22 +128,17 @@ const Login: React.FC = () => {
</p>
</form>

{/* Mostrar errores específicos de cada campo debajo del formulario */}
{errors.email && (
<div className="form__error-container">
<span className="form__error-message">{errors.email.message}</span>
</div>
)}
{errors.password && (
<div className="form__error-container">
<span className="form__error-message">{errors.password.message}</span>
{/* Mostrar errores globales en la parte superior */}
{reqError && (
<div className="form__notification form__notification--error">
<p>{reqError}</p>
</div>
)}

{/* Notificación de éxito */}
{successNotification && (
<div className="form__success-container">
<span className="form__success-message">{successNotification}</span>
<div className="form__notification form__notification--success">
<p>{successNotification}</p>
</div>
)}
</AuthLayout>
Expand Down
31 changes: 17 additions & 14 deletions src/components/Register/Register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { Controller, useForm } from "react-hook-form"
import { zodResolver } from "@hookform/resolvers/zod"
import { SignUpSchema, signUpSchema } from "../../schemas/signUp.schema"
import AuthLayout from "../../layout/AuthLayout";
import "./Register.css"
import authServices from "../../services/auth.services";
import { countriesPhoneList } from "../../mocks/countriesPhoneList.mock";
// import "./Register.css"

const Register: React.FC = () => {
const {
Expand Down Expand Up @@ -62,15 +62,17 @@ const Register: React.FC = () => {
}, 5000)

} catch (error) {

if (error instanceof AxiosError) {
if (error.response?.data) {

if (error.response.data.errors) {
setReqError(error.response.data.errors)
} else {
setReqError([error.response.data.details.message])
setReqError([error.response.data.message])
}
} else {

setReqError([error.message])
}
} else {
Expand All @@ -88,7 +90,7 @@ const Register: React.FC = () => {
className="w-full flex flex-col gap-3 [&>div]:flex [&>div]:flex-col [&>div]:gap-2 [&_label]:text-sm [&_input]:px-4 [&_input]:py-3 [&_input]:text-sm"
>
<div>
<label htmlFor="name">Nombre</label>
<label htmlFor="name">Nombre *</label>
<input
{...register("name")}
type="text"
Expand All @@ -99,7 +101,7 @@ const Register: React.FC = () => {
<span className="form__error-validation"> {errors.name.message} </span>}
</div>
<div>
<label htmlFor="email">Correo electrónico</label>
<label htmlFor="email">Correo electrónico *</label>
<input
{...register("email")}
type="email"
Expand All @@ -110,7 +112,7 @@ const Register: React.FC = () => {
<span className="form__error-validation">{errors.email.message}</span>}
</div>
<div>
<label htmlFor="password">Contraseña</label>
<label htmlFor="password">Contraseña *</label>
<input
{...register("password")}
type="password"
Expand All @@ -120,7 +122,7 @@ const Register: React.FC = () => {
<span className="form__error-validation">{errors.password.message}</span>}
</div>
<div>
<label htmlFor="confirmPassword">Repite tu contraseña</label>
<label htmlFor="confirmPassword">Repite tu contraseña *</label>
<input
{...register("confirmPassword")}
type="password"
Expand All @@ -130,7 +132,7 @@ const Register: React.FC = () => {
<span className="form__error-validation">{errors.confirmPassword.message}</span>}
</div>
<div>
<label htmlFor="location">País</label>
<label htmlFor="location">País *</label>
<input
{...register("location")}
type="text"
Expand All @@ -140,7 +142,7 @@ const Register: React.FC = () => {
<span className="form__error-validation">{errors.location.message}</span>}
</div>
<div>
<label htmlFor="phone">Teléfono</label>
<label htmlFor="phone">Teléfono *</label>
<div className="flex gap-2">
<Controller
name="phone.prefix"
Expand Down Expand Up @@ -173,7 +175,7 @@ const Register: React.FC = () => {
<span className="form__error-validation">{errors.phone.number.message}</span>}
</div>
<div className="relative">
<label htmlFor="role">Quiero registrarme como...</label>
<label htmlFor="role">Quiero registrarme como... *</label>
<select
{...register("role")}
id="role"
Expand All @@ -188,7 +190,7 @@ const Register: React.FC = () => {
<span className="form__error-validation">{errors.role.message}</span>}
</div>
<div className="mt-2">
<label className="!text-xs">Para registrarte en la plataforma debes ser mayor de edad. Al marcar la siguiente casilla confirmas tener al menos 18 años.</label>
<label className="!text-xs">Para registrarte en la plataforma debes ser mayor de edad. Al marcar la siguiente casilla confirmas tener al menos 18 años. *</label>
<div className="flex items-center gap-2">
<input
{...register("age")}
Expand Down Expand Up @@ -223,10 +225,11 @@ const Register: React.FC = () => {
{
reqError.map((e, i) => <p key={`${Date.now()}-${i}`}>{e}</p>)
}
</div>
}
</div>}
{successNotification &&
<p className="form__notification form__notification--success">{successNotification}</p>}
<div className="form__notification form__notification--success">
<p>{successNotification}</p>
</div>}
</AuthLayout >
)
}
Expand Down
Loading

0 comments on commit 0c63bb9

Please sign in to comment.