Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
3.1 kB
1
Indexable
Never
import React, { useState } from 'react';
import axios from 'axios';
import './addressPage.css';

const AddressPage = () => {
    const [mobileNumber, setMobileNumber] = useState('');
    const [city, setCity] = useState('');
    const [state, setState] = useState('');
    const [pincode, setPincode] = useState('');
    const [description, setDescription] = useState('');

    const handleSubmit = async (e) => {
        e.preventDefault();
        try {
            const response = await axios.post('YOUR_API_ENDPOINT', {
                mobileNumber,
                city,
                state,
                pincode,
                description
            });
            console.log('Address submitted successfully:', response.data);
            // Add any further logic after successful submission
        } catch (error) {
            console.error('Error submitting address:', error);
        }
    };

    return (
        <div className="address-container">
            <h2>Enter Your Address</h2>
            <form onSubmit={handleSubmit}>
                <div className="form-group">
                    <label htmlFor="mobileNumber">Mobile Number:</label>
                    <input type="text" id="mobileNumber" value={mobileNumber} onChange={(e) => setMobileNumber(e.target.value)} required />
                </div>
                <div className="form-group">
                    <label htmlFor="city">City:</label>
                    <input type="text" id="city" value={city} onChange={(e) => setCity(e.target.value)} required />
                </div>
                <div className="form-group">
                    <label htmlFor="state">State:</label>
                    <input type="text" id="state" value={state} onChange={(e) => setState(e.target.value)} required />
                </div>
                <div className="form-group">
                    <label htmlFor="pincode">Pincode:</label>
                    <input type="text" id="pincode" value={pincode} onChange={(e) => setPincode(e.target.value)} required />
                </div>
                <div className="form-group">
                    <label htmlFor="description">Address Description:</label>
                    <textarea id="description" value={description} onChange={(e) => setDescription(e.target.value)} required />
                </div>
                <button type="submit">Submit</button>
            </form>
        </div>
    );
};

export default AddressPage;


.address-container {
    max-width: 400px;
    margin: 0 auto;
    padding: 20px;
    border: 1px solid #ccc;
    border-radius: 5px;
    background-color: #f9f9f9;
}

.form-group {
    margin-bottom: 15px;
}

label {
    font-weight: bold;
}

input[type="text"],
textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

button[type="submit"] {
    background-color: #4CAF50;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

button[type="submit"]:hover {
    background-color: #45a049;
}



Leave a Comment