import React, { useState } from 'react'; import { Box, Typography, Stack, Button, useTheme, TextField } from '@mui/material'; const ContactInformation = ({ formData, updateFormData, onNext, onBack }) => { const theme = useTheme(); const [errors, setErrors] = useState({}); const handleChange = (field, value) => { updateFormData({ [field]: value }); setErrors(prev => ({ ...prev, [field]: '' })); // إزالة الخطأ عند التعديل }; const validateFields = () => { const newErrors = {}; if (!formData.Phone || formData.Phone.trim() === '') { newErrors.Phone = 'Phone number is required'; } else if (!/^\+?\d{7,15}$/.test(formData.Phone.trim())) { newErrors.Phone = 'Invalid phone number'; } if (!formData.Email || formData.Email.trim() === '') { newErrors.Email = 'Email is required'; } else if (!/^[\w-.]+@([\w-]+\.)+[\w-]{2,4}$/.test(formData.Email.trim())) { newErrors.Email = 'Invalid Email address'; } setErrors(newErrors); return Object.keys(newErrors).length === 0; }; const handleNextClick = () => { if (validateFields()) { onNext(); } }; return ( Contact Information Enter your contact information to proceed to registration of your own restaurant on this platform {/* Phone Number Input */} Phone Number handleChange('Phone', e.target.value)} error={!!errors.Phone} helperText={errors.Phone || ' '} sx={{ '& input': { fontWeight: 500, fontSize: '15px' }, '& input::placeholder': { color: '#969BA7' }, '& .MuiOutlinedInput-root': { borderRadius: '10px', transition: '0.3s', '&.Mui-focused fieldset': { borderColor: theme.palette.primary.main, boxShadow: '0 0 0 2px rgba(255, 145, 77, 0.2)' } }, '& .MuiOutlinedInput-root.Mui-focused': { borderColor: '#3f51b5', boxShadow: '0 0 0 2px rgba(63,81,181,0.1)' } }} /> {/* Email Input */} Email handleChange('Email', e.target.value)} error={!!errors.Email} helperText={errors.Email || ' '} sx={{ '& input': { fontWeight: 500, fontSize: '15px' }, '& input::placeholder': { color: '#969BA7' }, '& .MuiOutlinedInput-root': { borderRadius: '10px', transition: '0.3s', '&.Mui-focused fieldset': { borderColor: theme.palette.primary.main, boxShadow: '0 0 0 2px rgba(255, 145, 77, 0.2)' } }, '& .MuiOutlinedInput-root.Mui-focused': { borderColor: '#3f51b5', boxShadow: '0 0 0 2px rgba(63,81,181,0.1)' } }} /> {/* Next & Back Buttons */} ); }; export default ContactInformation;