import React, { useState, useEffect } from 'react'; import { Head, Link, router } from '@inertiajs/react'; import axios from 'axios'; import { toast } from 'sonner'; import { Eye, EyeOff, Lock, Loader2, Check, X, Users, TrendingUp, MessageSquare } from 'lucide-react'; export default function CreatePassword() { const [data, setData] = useState({ password: '', password_confirmation: '', }); const [showPassword, setShowPassword] = useState(false); const [loading, setLoading] = useState(false); const [errors, setErrors] = useState({}); // Live password strength validation const [strength, setStrength] = useState({ length: false, upper: false, lower: false, number: false, special: false }); useEffect(() => { const pass = data.password; setStrength({ length: pass.length >= 8, upper: /[A-Z]/.test(pass), lower: /[a-z]/.test(pass), number: /[0-9]/.test(pass), special: /[^A-Za-z0-9]/.test(pass) }); }, [data.password]); const handleInputChange = (field, value) => { setData(prev => ({ ...prev, [field]: value })); if (errors[field]) { setErrors(prev => ({ ...prev, [field]: null })); } }; const isAllCriteriaMet = Object.values(strength).every(Boolean); const validateForm = () => { const newErrors = {}; if (!data.password) { newErrors.password = 'Password is required.'; } else if (!isAllCriteriaMet) { newErrors.password = 'Password must meet all complexity requirements.'; } if (!data.password_confirmation) { newErrors.password_confirmation = 'Confirm password is required.'; } else if (data.password !== data.password_confirmation) { newErrors.password_confirmation = 'Passwords do not match.'; } setErrors(newErrors); return Object.keys(newErrors).length === 0; }; const handleSubmit = async (e) => { e.preventDefault(); setErrors({}); if (!validateForm()) { toast.error('Validation failed. Please correct the fields in red.'); return; } setLoading(true); try { await axios.post('/employer/create-password', data); toast.success('Registration finalized! Welcome to Migrant.'); router.visit('/employer/dashboard'); } catch (err) { if (err.response) { if (err.response.status === 422) { setErrors(err.response.data.errors || {}); toast.error('Validation failed. Please verify password requirements.'); } else { toast.error('Failed to complete enrollment. Please try again.'); } } else { toast.error('Network error. Please check your connection.'); } } finally { setLoading(false); } }; const renderStepIndicator = () => (
Unlock direct access to top domestic candidates with a Migrant premium subscription. Find, interview, and hire directly without middlemen.
Configure your portal access password