import React, { useState } from 'react'; import { Button } from '../components/Button'; import { Input } from '../components/Input'; import { InstitutionForm } from '../components/InstitutionForm'; import { useAuth } from '../contexts/AuthContext'; import { useData } from '../contexts/DataContext'; interface RegisterProps { onNavigate: (page: string) => void; } export const Register: React.FC = ({ onNavigate }) => { const { register } = useAuth(); const { addInstitution } = useData(); const [formData, setFormData] = useState({ name: '', email: '', phone: '', password: '', confirmPassword: '', wantsToAddInstitution: false }); const [agreedToTerms, setAgreedToTerms] = useState(false); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(''); const [isPending, setIsPending] = useState(false); const [showInstitutionForm, setShowInstitutionForm] = useState(false); const [tempUserId] = useState(`user-${Date.now()}`); const [registeredInstitutionName, setRegisteredInstitutionName] = useState(); const handleChange = (field: string, value: string | boolean) => { setFormData(prev => ({ ...prev, [field]: value })); setError(''); }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setIsLoading(true); setError(''); // Validação do checkbox de termos if (!agreedToTerms) { setError('Você precisa concordar com os termos de uso para continuar'); setIsLoading(false); return; } // Validações if (formData.password !== formData.confirmPassword) { setError('As senhas não coincidem'); setIsLoading(false); return; } if (formData.password.length < 6) { setError('A senha deve ter no mínimo 6 caracteres'); setIsLoading(false); return; } // If user wants to add institution, show form if (formData.wantsToAddInstitution) { setIsLoading(false); setShowInstitutionForm(true); return; } try { await register({ nome: formData.name, email: formData.email, senha: formData.password, telefone: formData.phone }); setIsLoading(false); setIsPending(true); } catch (err: any) { setIsLoading(false); setError(err.message || 'Erro ao realizar cadastro'); } }; const handleInstitutionSubmit = async (institutionData: any) => { // Logic for adding institution remains (mock or need API for it too?), // but user registration must be real. // Assuming institution addition is still mock for now in DataContext. const newInstitution = { ...institutionData, id: `inst-${Date.now()}`, ownerId: tempUserId }; addInstitution(newInstitution); setRegisteredInstitutionName(newInstitution.name); setShowInstitutionForm(false); // Complete registration via API setIsLoading(true); try { await register({ nome: formData.name, email: formData.email, senha: formData.password, telefone: formData.phone // Note: The backend register endpoint currently doesn't accept institution data directly. // We'd need to create the institution separately after logging in, but the user won't be able to login yet (pending). // Or update backend to accept it. // For now, we perform the user registration. }); setIsLoading(false); setIsPending(true); } catch (err: any) { setIsLoading(false); setError(err.message || 'Erro ao realizar cadastro'); } }; // Show institution form modal if (showInstitutionForm) { return (
{ // Apenas fecha o modal e volta para o formulário setShowInstitutionForm(false); // Desmarca a opção de cadastrar universidade setFormData(prev => ({ ...prev, wantsToAddInstitution: false })); }} onSubmit={handleInstitutionSubmit} userId={tempUserId} />
); } if (isPending) { return (

Cadastro Pendente de Aprovação

Seu cadastro foi realizado com sucesso e está aguardando aprovação da empresa.

Você receberá um e-mail assim que seu cadastro for aprovado e poderá acessar o sistema.

Atenção: Enquanto seu cadastro não for aprovado, você não terá acesso ao sistema.

); } return (
{/* Logo dentro do card */}
Photum Formaturas
Comece agora

Crie sua conta

Já tem uma conta?{' '}

handleChange('name', e.target.value)} /> handleChange('email', e.target.value)} /> handleChange('phone', e.target.value)} mask="phone" /> handleChange('password', e.target.value)} /> handleChange('confirmPassword', e.target.value)} error={error && (error.includes('senha') || error.includes('coincidem')) ? error : undefined} />
setAgreedToTerms(e.target.checked)} className="mt-0.5 sm:mt-1 h-4 w-4 flex-shrink-0 border-gray-300 rounded focus:ring-2" style={{ accentColor: '#B9CF33' }} />
{error && error.includes('termos') && ( {error} )}
setFormData(prev => ({ ...prev, wantsToAddInstitution: e.target.checked }))} className="mt-0.5 sm:mt-1 h-4 w-4 flex-shrink-0 border-gray-300 rounded focus:ring-2" style={{ accentColor: '#B9CF33' }} />
); };