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 = () => (
{[ { step: 1, label: 'Register' }, { step: 2, label: 'Verify' }, { step: 3, label: 'Emirates ID' }, { step: 4, label: 'Payment' }, { step: 5, label: 'Password' } ].map((s) => (
{s.step}
{s.step === 5 && ( {s.label} )}
{s.step < 5 && (
)} ))}
); const rules = [ { key: 'length', text: 'At least 8 characters' }, { key: 'upper', text: 'One uppercase letter (A-Z)' }, { key: 'lower', text: 'One lowercase letter (a-z)' }, { key: 'number', text: 'One numerical digit (0-9)' }, { key: 'special', text: 'One special symbol (e.g. @, #, $, %)' } ]; return (
{/* Left Brand Panel (Desktop Only) */}
M
Migrant Portal
Sponsor Registration

Find verified domestic workers directly.

Unlock direct access to top domestic candidates with a Migrant premium subscription. Find, interview, and hire directly without middlemen.

{/* Stat Row */}
3000+
Worker Profiles
550+
Avg Monthly Hires
Direct
Messaging
© 2026 Migrant. All rights reserved.
{/* Right Set Password Form */}
{renderStepIndicator()}

Set Password

Configure your portal access password

{/* Password input */}
handleInputChange('password', e.target.value)} placeholder="••••••••" className={`w-full pl-10 pr-10 py-2.5 bg-slate-50 border rounded-xl text-sm focus:outline-none focus:ring-2 focus:ring-[#185FA5]/20 focus:border-[#185FA5] focus:bg-white transition-all ${ errors.password ? 'border-red-500 focus:ring-red-500/20' : 'border-slate-300' }`} />
{errors.password && (

{Array.isArray(errors.password) ? errors.password[0] : errors.password}

)}
{/* Confirm Password input */}
handleInputChange('password_confirmation', e.target.value)} placeholder="••••••••" className={`w-full pl-10 pr-4 py-2.5 bg-slate-50 border rounded-xl text-sm focus:outline-none focus:ring-2 focus:ring-[#185FA5]/20 focus:border-[#185FA5] focus:bg-white transition-all ${ errors.password_confirmation ? 'border-red-500 focus:ring-red-500/20' : 'border-slate-300' }`} />
{errors.password_confirmation && (

{Array.isArray(errors.password_confirmation) ? errors.password_confirmation[0] : errors.password_confirmation}

)}
{/* Password Rules Checklist */}

Complexity Checklist

{rules.map((rule) => { const isMet = strength[rule.key]; return (
{isMet ? : null}
{rule.text}
); })}
Cancel Registration
); }