Overview
The Contactanos component provides a comprehensive contact solution with a WhatsApp quick-access button and a detailed contact form. The form collects customer information and sends messages to your API endpoint, with success/error feedback using SweetAlert2 modal dialogs.Component code
Props
This component does not accept any props.Usage example
Form fields
The contact form includes the following fields:Customer’s first name (Nombre)
Customer’s last name (Apellidos)
Customer’s email address (Correo)
Customer’s phone number (Número de teléfono)
Customer’s message or inquiry (Mensaje). 4 rows of text input.
There’s a commented-out company field in the source code that you can uncomment if you need to collect business information.
Styling details
Container and layout
Container and layout
- Amber-50 background color for warm, inviting feel
- Centered flexbox layout with isolate stacking context
- Responsive padding: 1.5rem horizontal, 6rem vertical on mobile
- White form container: 100% width on mobile, 50% on large screens
- Rounded corners (rounded-lg) with 1.25rem padding
Form styling
Form styling
- Two-column grid on small screens and up (sm:grid-cols-2)
- Single column on mobile devices
- Gap spacing: 2rem horizontal (gap-x-8), 1.5rem vertical (gap-y-6)
- Email, phone, and message fields span both columns (sm:col-span-2)
- Maximum width: 36rem (max-w-xl) for readability
Input fields
Input fields
All input fields share consistent styling:
- Black/5 background (semi-transparent black)
- 0.875rem horizontal padding, 0.5rem vertical padding
- Base text size with black text color
- Rounded corners (rounded-md)
- Gray-500 placeholder text
- Indigo-500 focus outline with 2px width and -2px offset
Submit button
Submit button
Typography
Typography
- Heading: 4xl (2.25rem) on mobile, 5xl (3rem) on small screens, black color, semi-bold
- Subheading: lg text (1.125rem), gray-500 color, 0.5rem top margin
- Labels: sm text (0.875rem), semi-bold weight, black color
- Text is balanced for optimal line breaks (text-balance)
Form submission flow
Submission process
Submission process
- User fills out form and clicks “Enviar” button
- Form prevents default submission and captures data
- Submit button disables and changes text to “Enviando…”
- Form data converts to JSON and posts to
/api/contact - Success response shows SweetAlert success modal
- Form resets and button re-enables
- Error response shows SweetAlert error modal with WhatsApp fallback suggestion
Success feedback
Success feedback
- Form resets to empty state
- Button text returns to “Enviar”
- Button re-enables for new submissions
Error handling
Error handling
- Button re-enables for retry
- Suggests WhatsApp as alternative contact method
- Form data preserved for user convenience
The component imports and includes the Whatsapp component at the top, providing users with an alternative quick-contact method.
Integration details
Expected request body:
Dependencies
- Whatsapp.astro: Imported component for WhatsApp quick-contact button
- SweetAlert2: Modal dialog library for success/error feedback
- Tailwind CSS: Form styling, layout, and responsive design
- Fetch API: For API communication
- FormData API: For extracting form field values
