Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import { PlusCircleIcon } from '@heroicons/react/24/outline';
import '../styles/globals.css';
import { Colors } from '../styles/styles';
Expand All @@ -16,6 +16,7 @@ type ButtonProps = {
className?: string;
variant?: 'submit' | 'white' | 'light' | 'icon' | 'gray';
textColor?: string;
type?: 'submit' | 'reset' | 'button' | undefined;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aca si es opcional el :? toma como que puede recibirse o no, creo que no hay que pasarle en si que tomara un tipo undefined, ya que es opcional de tomar alguno ya recibe una de las variantes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aca si es opcional el :? toma como que puede recibirse o no, creo que no hay que pasarle en si que tomara un tipo undefined, ya que es opcional de tomar alguno ya recibe una de las variantes.

¿Te refieres a que debería estar así type?: 'submit' | 'reset' | 'button';?

};

const Button: React.FC<ButtonProps> = ({
Expand All @@ -31,7 +32,26 @@ const Button: React.FC<ButtonProps> = ({
className = '',
variant = 'submit',
textColor = 'white',
type = undefined,
}) => {
const [internalDisabled, setInternalDisabled] = useState(false);

const handleClick = () => {
if (disabled || internalDisabled) return;

setInternalDisabled(true);

const result = onClick?.();

if (result && typeof result === 'object' && 'then' in result) {
(result as Promise<void>).finally(() => setInternalDisabled(false));
} else {
setInternalDisabled(false);
}
};

const isDisabled = disabled || internalDisabled;

const baseStyles = `font-medium transition duration-200 rounded-md shadow-sm border-transparent px-${paddingX} py-${paddingY} text-${textSize}`;

const variantStyles =
Expand All @@ -47,10 +67,11 @@ const Button: React.FC<ButtonProps> = ({

return (
<button
onClick={onClick}
disabled={disabled}
type={type}
onClick={handleClick}
disabled={isDisabled}
style={{
backgroundColor: disabled
backgroundColor: isDisabled
? `${Colors.disabled}`
: variant === 'white'
? 'white'
Expand All @@ -59,7 +80,7 @@ const Button: React.FC<ButtonProps> = ({
: variant === 'gray'
? `${Colors.neuter}`
: color,
color: disabled
color: isDisabled
? `${Colors.textHighContrast}`
: variant === 'white'
? `${Colors.textMain}`
Expand All @@ -73,7 +94,7 @@ const Button: React.FC<ButtonProps> = ({
border: variant === 'white' ? `2px solid ${Colors.primary}` : 'none',
}}
className={`${baseStyles} ${variantStyles} ${
disabled
isDisabled
? 'cursor-not-allowed border-none bg-gray-300 text-black opacity-50'
: ''
} hover:opacity-50 ${className}`}
Expand Down
20 changes: 20 additions & 0 deletions src/lib/validations/checkoutShippingInfoSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { z } from 'zod';

export const checkoutShippingInfoSchema = z
.object({
shippingMethod: z.string().min(1, 'Debes seleccionar una opción de compra'),
branch: z.string().min(1, 'Debes seleccionar una sucursal/dirección'),
paymentMethod: z.string().min(1, 'Debes seleccionar un método de pago'),
})
.refine(
() => {
// Aquí puedes poner cualquier lógica adicional si es necesario.
// Ejemplo: Si se selecciona "Envío a Domicilio", la dirección debe ser válida, etc.
return true; // Aquí se puede agregar lógica como validación de combinación de opciones
},
{
message:
'Por favor, asegurate de que todas las opciones estén bien seleccionadas',
path: ['shippingMethod', 'branch', 'paymentMethod'], // Asegura que todas las opciones estén bien seleccionadas
},
);
Loading