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 = () => (
Establish a robust password to ensure protection of your domestic hiring workspace.
Step 3 of 3: Configure Portal Access Key