import React, { useState, useEffect } from 'react'; import { Head, Link, router } from '@inertiajs/react'; import axios from 'axios'; import { toast } from 'sonner'; import { ShieldCheck, CheckCircle, Eye, EyeOff, Lock, Loader2, Check, X } 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 handleSubmit = async (e) => { e.preventDefault(); if (!isAllCriteriaMet) { setErrors({ password: 'Password does not meet all security guidelines.' }); toast.error('Password does not meet all security guidelines.'); return; } if (data.password !== data.password_confirmation) { setErrors({ password_confirmation: 'Passwords do not match.' }); toast.error('Passwords do not match.'); return; } setLoading(true); setErrors({}); try { const response = await axios.post('/employer/create-password', data); toast.success('Registration finalized! Welcome to the Marketplace.'); 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 Code' }, { step: 3, label: 'Set Password' } ].map((s) => (
{s.step === 3 && isAllCriteriaMet ? : s.step}
{s.label}
))}
); 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 */}
M
Marketplace

Establish Secure Credentials.

Establish a robust password to ensure protection of your domestic hiring workspace.

Empowering Household Recruitment Since 2024
{/* Right Form Content */}

Security Configuration

Step 3 of 3: Configure Portal Access Key

{renderStepIndicator()}
{/* Password input */}
handleInputChange('password', e.target.value)} placeholder="••••••••" className={`w-full pl-12 pr-12 py-4 bg-slate-50 border rounded-2xl text-sm font-bold focus:ring-4 focus:ring-blue-100 focus:bg-white transition-all outline-none ${ errors.password ? 'border-rose-400 bg-rose-50/20' : 'border-transparent' }`} required />
{errors.password && (

{errors.password[0] || errors.password}

)}
{/* Confirm Password input */}
handleInputChange('password_confirmation', e.target.value)} placeholder="••••••••" className={`w-full pl-12 pr-4 py-4 bg-slate-50 border rounded-2xl text-sm font-bold focus:ring-4 focus:ring-blue-100 focus:bg-white transition-all outline-none ${ errors.password_confirmation ? 'border-rose-400 bg-rose-50/20' : 'border-transparent' }`} required />
{errors.password_confirmation && (

{errors.password_confirmation[0] || errors.password_confirmation}

)}
{/* Password Rules Checklist */}

Password Complexity Checklist

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