-
+
Password Strength:
{getStrengthText()}
+
+
{requirements.map((req, index) => {
const isMet = req.test(password);
@@ -81,7 +91,7 @@ const PasswordStrengthIndicator = ({ password }) => {
) : (
)}
-
+
{req.label}
@@ -95,79 +105,128 @@ const PasswordStrengthIndicator = ({ password }) => {
const InputField = ({
icon: Icon,
name,
- type = "text",
+ type,
placeholder,
value,
error,
+ isFocused,
+ showPassword,
+ onToggleShowPassword,
onChange,
- endIcon: EndIcon,
- onEndIconClick,
- ...props
-}) => (
-
-
-
- {EndIcon && (
-
- )}
- {error &&
{error}
}
-
-);
+ onFocus,
+ onBlur,
+ showPasswordStrength = false,
+}) => {
+ return (
+
+
-const TextAreaField = ({
- icon: Icon,
- name,
+
+
+ {(name === "password" || name === "confirmPassword") && (
+
+ )}
+
+ {error && (
+
+
+ {error}
+
+ )}
+
+ {showPasswordStrength && name === "password" && (
+
+ )}
+
+ );
+};
+
+const RoleCard = ({
value,
- onChange,
- placeholder,
- error,
- ...props
+ icon: Icon,
+ title,
+ description,
+ isSelected,
+ onClick,
}) => (
-
-
-
- {error &&
{error}
}
+
+
+
+ {description}
+
+
+ {isSelected && (
+
+ )}
);
export default function Registration() {
- // Effect to load CSS dynamically
- useEffect(() => {
- const styleId = 'react-toastify-css';
- if (!document.getElementById(styleId)) {
- const link = document.createElement('link');
- link.id = styleId;
- link.rel = 'stylesheet';
- link.href = 'https://cdn.jsdelivr.net/npm/react-toastify@9.1.3/dist/ReactToastify.min.css';
- document.head.appendChild(link);
- }
- }, []);
-
const [formData, setFormData] = useState({
email: "",
password: "",
- confirmPassword: "", // New state for confirm password
+ confirmPassword: "",
role: "PARENTS",
kidName: "",
dob: "",
@@ -181,13 +240,13 @@ export default function Registration() {
const [errors, setErrors] = useState({});
const [isSubmitting, setIsSubmitting] = useState(false);
const [showPassword, setShowPassword] = useState(false);
- const [showConfirmPassword, setShowConfirmPassword] = useState(false); // State for confirm password visibility
+ const [showConfirmPassword, setShowConfirmPassword] = useState(false);
+ const [focusedField, setFocusedField] = useState(null);
const navigate = useNavigate();
const validateForm = () => {
const newErrors = {};
- // Required fields
if (!formData.email.trim()) {
newErrors.email = "Email is required";
} else if (
@@ -202,7 +261,6 @@ export default function Registration() {
newErrors.password = "Password must be at least 8 characters";
}
- // New validation for confirm password
if (!formData.confirmPassword.trim()) {
newErrors.confirmPassword = "Please confirm your password";
} else if (formData.password !== formData.confirmPassword) {
@@ -213,7 +271,6 @@ export default function Registration() {
newErrors.role = "Role is required";
}
- // Role-specific validations
if (formData.role === "PARENTS") {
if (!formData.kidName.trim())
newErrors.kidName = "Child's name is required";
@@ -230,231 +287,373 @@ export default function Registration() {
return Object.keys(newErrors).length === 0;
};
- const handleChange = (e) => {
- const { name, value } = e.target;
- setFormData((prev) => ({ ...prev, [name]: value }));
- if (errors[name]) {
- setErrors((prev) => ({ ...prev, [name]: "" }));
- }
- };
-
const handleSubmit = async (e) => {
e.preventDefault();
-
- if (!validateForm()) {
- return;
- }
+ if (!validateForm()) return;
setIsSubmitting(true);
try {
- const { confirmPassword, ...dataToSend } = formData; // Exclude confirmPassword from submission
- const response = await axios.post(
- "http://localhost:5000/api/signup",
- dataToSend
- );
+ const { confirmPassword, ...dataToSend } = formData;
+
+ const response = await fetch(commnApiEndpoint.signup.url, {
+ method: commnApiEndpoint.signup.method,
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(dataToSend),
+ });
- if (response.data.success) {
+ const data = await response.json();
+ console.log("Registration response:", data);
+
+ if (response.ok && data.success) {
toast.success("Registration successful! Redirecting to login...");
setTimeout(() => {
navigate("/signin");
}, 2000);
+ } else {
+ console.error("Registration failed:", data);
+ toast.error(data.message || "Registration failed. Please try again.");
}
} catch (error) {
console.error("Registration error:", error);
- toast.error(
- error.response?.data?.message ||
- "Registration failed. Please try again."
- );
+ toast.error("Network error. Please check your connection and try again.");
} finally {
setIsSubmitting(false);
}
};
+ const handleChange = (e) => {
+ const { name, value } = e.target;
+ setFormData((prev) => ({ ...prev, [name]: value }));
+ if (errors[name]) {
+ setErrors((prev) => ({ ...prev, [name]: "" }));
+ }
+ };
+
return (
-
-
-
-
-
-
-
- Create Your Account
-
-
- Join our community and start tracking your child's health journey
-
+ <>
+
+
+ {/* Left Section */}
+
+
-