Back to blocks

MercadoPago Payer Info with React Hooks

4.0
enWeb DevelopmentMercadoPagoReact HooksInput Validation

Prompt


generate mercadopago payer information capture with validations in input fields, without use form , with react hooks

Résultat Généré

import React, { useState } from 'react';

const App = () => {
  const [payerInfo, setPayerInfo] = useState({
    name: '',
    email: '',
    phone: '',
    address: ''
  });
  const [errors, setErrors] = useState({});

  const validateField = (field, value) => {
    let error = '';
    if (!value) {
      error = 'This field is required';
    } else if (field === 'email' && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) {
      error = 'Invalid email address';
    } else if (field === 'phone' && !/^\d{10}$/.test(value)) {
      error = 'Invalid phone number';
    }
    setErrors(prev => ({ ...prev, [field]: error }));
  };

  const handleChange = (e) => {
    const { name, value } = e.target;
    setPayerInfo(prev => ({ ...prev, [name]: value }));
    validateField(name, value);
  };

  return (
    <div className="min-h-screen bg-gray-100 py-8 px-4 sm:px-6 lg:px-8">
      <div className="max-w-md mx-auto bg-white rounded-lg shadow-xl p-6">
        <h2 className="text-2xl font-bold text-gray-900 mb-6">Payer Information</h2>
        <div className="space-y-5">
          <div>
            <label className="block text-sm font-medium text-gray-700">Name</label>
            <input
              type="text"
              name="name"
              value={payerInfo.name}
              onChange={handleChange}
              className={`mt-1 block w-full px-3 py-2 border ${errors.name ? 'border-red-500' : 'border-gray-300'} rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500`}
            />
            {errors.name && <p className="text-red-500 text-xs mt-1">{errors.name}</p>}
          </div>
          <div>
            <label className="block text-sm font-medium text-gray-700">Email</label>
            <input
              type="email"
              name="email"
              value={payerInfo.email}
              onChange={handleChange}
              className={`mt-1 block w-full px-3 py-2 border ${errors.email ? 'border-red-500' : 'border-gray-300'} rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500`}
            />
            {errors.email && <p className="text-red-500 text-xs mt-1">{errors.email}</p>}
          </div>
          <div>
            <label className="block text-sm font-medium text-gray-700">Phone</label>
            <input
              type="text"
              name="phone"
              value={payerInfo.phone}
              onChange={handleChange}
              className="mt-1 block w-full px-3 py-2 border ${errors.phone ? 'border-red-500' : 'border-gray-300'} rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500"
            />
            {errors.phone && <p className="text-red-500 text-xs mt-1">{errors.phone}</p>}
          </div>
          <div>
            <label className="block text-sm font-medium text-gray-700">Address</label>
            <input
              type="text"
              name="address"
              value={payerInfo.address}
              onChange={handleChange}
              className={`mt-1 block w-full px-3 py-2 border ${errors.address ? 'border-red-500' : 'border-gray-300'} rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500`}
            />
            {errors.address && <p className="text-red-500 text-xs mt-1">{errors.address}</p>}
          </div>
        </div>
      </div>
      <div className="mt-8 text-center text-sm text-gray-500">
        © 2025 Your Company. All rights reserved.
      </div>
    </div>
  );
};

export default App;

Plus de Recommandations

Voir Tout

Next.js Vape Website

Web Developmenten
4.0

I want to create a simpple webiste in nextjs for vape listing and deatil anc checkout page using striip there as well stunning landing page to attract and add to cart then user ca place order Manchester Vape website name

Next.jsVapeStripe19/06/2025

Create TikTok Page

Web Developmenten
4.0

Create a TikTok like landing page.

TikTokLanding PageWeb Design17/06/2025

React Backoffice Frontend Guide

Web Developmenten
4.0

A backoffice frontend built in React 18 + Vite with Tailwind CSS and DaisyUI, Zustand for global state, TanStack Query for API state, React Hook Form with Zod for validation, and Axios for HTTP. The UI consists of: A dashboard (placeholder for future analytics) Games module: manage game metadata and brand availability Brands module: create/edit brands, assign games, apply jurisdiction rules Regulation module: read-only view of jurisdiction rules Players module: read-only, filterable player list Game sessions: read-only session explorer by brand/player Bets: read-only history table with filters Errored bets: read-only view of failed transactions and error details Admin users: single-user management (MVP) Layout is responsive with dark/light mode. Design system follows Mixpanel-style dashboards with interactive tables, forms, and consistent UI primitives. All modules are isolated under /features, with shared components, services, and store logic modularized.

ReactTailwind CSSZustand16/06/2025

React Backoffice Frontend Guide

Web Developmenten
4.0

A backoffice frontend built in React 18 + Vite with Tailwind CSS and DaisyUI, Zustand for global state, TanStack Query for API state, React Hook Form with Zod for validation, and Axios for HTTP. The UI consists of: A dashboard (placeholder for future analytics) Games module: manage game metadata and brand availability Brands module: create/edit brands, assign games, apply jurisdiction rules Regulation module: read-only view of jurisdiction rules Players module: read-only, filterable player list Game sessions: read-only session explorer by brand/player Bets: read-only history table with filters Errored bets: read-only view of failed transactions and error details Admin users: single-user management (MVP) Layout is responsive with dark/light mode. Design system follows Mixpanel-style dashboards with interactive tables, forms, and consistent UI primitives. All modules are isolated under /features, with shared components, services, and store logic modularized.

ReactViteTailwind CSS16/06/2025

CRM Web App Development

Web Developmenten
4.0

Create a responsive web app which maintains the CRM data like customer name, phone number , whatsapp number, location, Remarks etc.. so that i can send the brochure automatically to the customer added, through whatsapp api the message should be auto generated based on the keywords in the remarks. make it more professional and beautiful

CRMWeb AppWhatsApp API13/06/2025

Create Video Translation Site

Web Developmenten
4.0

Create a video translation website by adding the "Add video file" and "Add video link" options. Upload the link and support all social media links. Add a language selection feature, then add all the languages ​​you want to translate the video into. Clicking the "Translate video" button will upload the translated video. pip install gradio_client

video translationsocial medialanguage selection12/06/2025