import React, { useState } from 'react'; import { Head, Link, router } from '@inertiajs/react'; import axios from 'axios'; import { toast } from 'sonner'; import { Loader2, ShieldAlert, ShieldCheck, UploadCloud, FileText, Users, DollarSign, MessageSquare, ArrowLeft } from 'lucide-react'; export default function UploadEmiratesId({ email }) { const [frontFile, setFrontFile] = useState(null); const [backFile, setBackFile] = useState(null); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const handleFrontFileChange = (e) => { const selectedFile = e.target.files[0]; if (selectedFile) { if (selectedFile.size > 10240 * 1024) { setError('The document must not exceed 10MB.'); toast.error('The document must not exceed 10MB.'); return; } setFrontFile(selectedFile); setError(null); } }; const handleBackFileChange = (e) => { const selectedFile = e.target.files[0]; if (selectedFile) { if (selectedFile.size > 10240 * 1024) { setError('The document must not exceed 10MB.'); toast.error('The document must not exceed 10MB.'); return; } setBackFile(selectedFile); setError(null); } }; const handleSubmit = async (e) => { e.preventDefault(); if (!frontFile || !backFile) { setError('Please upload both the front and back side of your Emirates ID.'); toast.error('Please upload both sides of your Emirates ID.'); return; } setLoading(true); setError(null); const formData = new FormData(); formData.append('emirates_id_front', frontFile); formData.append('emirates_id_back', backFile); try { await axios.post('/employer/upload-emirates-id', formData, { headers: { 'Content-Type': 'multipart/form-data' } }); toast.success('Emirates ID scanned successfully. Data extracted and document deleted.'); router.visit('/employer/register-payment'); } catch (err) { if (err.response && err.response.data && err.response.data.errors) { const errors = err.response.data.errors; const firstError = Object.values(errors).flat()[0]; const errorMsg = firstError || 'Validation failed.'; setError(errorMsg); toast.error(errorMsg); } else { toast.error('Scan extraction failed. Please try again.'); } } finally { setLoading(false); } }; const renderStepIndicator = () => (
Unlock direct access to top domestic candidates with a Migrant premium subscription. Find, interview, and hire directly without middlemen.
Upload your identity document for quick OCR scanning
We do not store your physical Emirates ID document. Your card is temporarily scanned only to securely extract the ID number and expiry date via automated OCR, and the file is permanently deleted immediately after extraction.