Fix build: add AdminProfileModal.tsx
Build and Deploy (Gitea) / build-and-deploy (push) Successful in 59s
Details
Build and Deploy (Gitea) / build-and-deploy (push) Successful in 59s
Details
This commit is contained in:
parent
8dde8bf9e3
commit
4f5ac1f363
|
|
@ -0,0 +1,288 @@
|
||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import { X, Save, User, Phone, MapPin, Calendar, CreditCard, Building2, CheckCircle2, AlertCircle, Loader2 } from 'lucide-react';
|
||||||
|
|
||||||
|
interface AdminProfileModalProps {
|
||||||
|
isOpen: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
token: string | null;
|
||||||
|
onUpdated?: (data: any) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function AdminProfileModal({ isOpen, onClose, token, onUpdated }: AdminProfileModalProps) {
|
||||||
|
const [form, setForm] = useState({
|
||||||
|
name: '',
|
||||||
|
whatsapp: '',
|
||||||
|
birthDate: '',
|
||||||
|
cpf: '',
|
||||||
|
cep: '',
|
||||||
|
address: '',
|
||||||
|
number: '',
|
||||||
|
complement: '',
|
||||||
|
neighborhood: '',
|
||||||
|
city: '',
|
||||||
|
state: '',
|
||||||
|
});
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [isSaving, setIsSaving] = useState(false);
|
||||||
|
const [status, setStatus] = useState<{ type: 'success' | 'error'; msg: string } | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isOpen && token) {
|
||||||
|
fetchProfile();
|
||||||
|
}
|
||||||
|
}, [isOpen]);
|
||||||
|
|
||||||
|
const fetchProfile = async () => {
|
||||||
|
setIsLoading(true);
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/auth/me', {
|
||||||
|
headers: { 'Authorization': `Bearer ${token}` }
|
||||||
|
});
|
||||||
|
if (res.ok) {
|
||||||
|
const data = await res.json();
|
||||||
|
setForm({
|
||||||
|
name: data.name || '',
|
||||||
|
whatsapp: data.whatsapp || '',
|
||||||
|
birthDate: data.birthDate ? data.birthDate.substring(0, 10) : '',
|
||||||
|
cpf: data.cpf || '',
|
||||||
|
cep: data.cep || '',
|
||||||
|
address: data.address || '',
|
||||||
|
number: data.number || '',
|
||||||
|
complement: data.complement || '',
|
||||||
|
neighborhood: data.neighborhood || '',
|
||||||
|
city: data.city || '',
|
||||||
|
state: data.state || '',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Erro ao carregar perfil:', e);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSave = async () => {
|
||||||
|
setIsSaving(true);
|
||||||
|
setStatus(null);
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/users/profile', {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(form)
|
||||||
|
});
|
||||||
|
const data = await res.json();
|
||||||
|
if (res.ok) {
|
||||||
|
setStatus({ type: 'success', msg: 'Dados salvos com sucesso! O seu WhatsApp já será usado para os testes de envio.' });
|
||||||
|
if (onUpdated) onUpdated(data.user);
|
||||||
|
} else {
|
||||||
|
setStatus({ type: 'error', msg: data.error || 'Erro ao salvar dados.' });
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
setStatus({ type: 'error', msg: 'Erro interno ao salvar.' });
|
||||||
|
} finally {
|
||||||
|
setIsSaving(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const set = (field: string) => (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>) =>
|
||||||
|
setForm(f => ({ ...f, [field]: e.target.value }));
|
||||||
|
|
||||||
|
if (!isOpen) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/70 backdrop-blur-sm animate-fade-in">
|
||||||
|
<div className="relative w-full max-w-2xl bg-zinc-900 border border-white/10 rounded-2xl shadow-2xl flex flex-col max-h-[90vh]">
|
||||||
|
{/* Header */}
|
||||||
|
<div className="flex items-center justify-between px-6 py-4 border-b border-white/10 flex-shrink-0">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<div className="w-9 h-9 rounded-full bg-[#E50914] flex items-center justify-center">
|
||||||
|
<User className="w-5 h-5 text-white" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h2 className="text-base font-bold text-white">Meu Perfil — Administrador</h2>
|
||||||
|
<p className="text-[10px] text-zinc-500">Esses dados são usados para testes de envio de WhatsApp</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button onClick={onClose} className="w-8 h-8 flex items-center justify-center rounded-full text-zinc-400 hover:text-white hover:bg-white/10 transition-colors">
|
||||||
|
<X className="w-4 h-4" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Body */}
|
||||||
|
<div className="overflow-y-auto p-6 space-y-6 flex-1">
|
||||||
|
{isLoading ? (
|
||||||
|
<div className="flex justify-center items-center py-12">
|
||||||
|
<Loader2 className="w-8 h-8 text-[#E50914] animate-spin" />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
{/* Dados Pessoais */}
|
||||||
|
<div>
|
||||||
|
<p className="text-[10px] font-bold text-zinc-400 uppercase tracking-wider mb-3 flex items-center gap-2">
|
||||||
|
<User className="w-3.5 h-3.5" />
|
||||||
|
Dados Pessoais
|
||||||
|
</p>
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
<div className="md:col-span-2">
|
||||||
|
<label className="block text-[11px] text-zinc-400 mb-1 font-medium">Nome Completo</label>
|
||||||
|
<input
|
||||||
|
value={form.name}
|
||||||
|
onChange={set('name')}
|
||||||
|
className="w-full bg-black/40 border border-white/10 rounded-lg px-3 py-2.5 text-white text-sm focus:outline-none focus:border-[#E50914]/50"
|
||||||
|
placeholder="Seu nome completo"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="block text-[11px] text-zinc-400 mb-1 font-medium flex items-center gap-1">
|
||||||
|
<CreditCard className="w-3 h-3" /> CPF
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
value={form.cpf}
|
||||||
|
onChange={set('cpf')}
|
||||||
|
className="w-full bg-black/40 border border-white/10 rounded-lg px-3 py-2.5 text-white text-sm focus:outline-none focus:border-[#E50914]/50"
|
||||||
|
placeholder="000.000.000-00"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="block text-[11px] text-zinc-400 mb-1 font-medium flex items-center gap-1">
|
||||||
|
<Calendar className="w-3 h-3" /> Data de Nascimento
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="date"
|
||||||
|
value={form.birthDate}
|
||||||
|
onChange={set('birthDate')}
|
||||||
|
className="w-full bg-black/40 border border-white/10 rounded-lg px-3 py-2.5 text-white text-sm focus:outline-none focus:border-[#E50914]/50"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Contato */}
|
||||||
|
<div>
|
||||||
|
<p className="text-[10px] font-bold text-zinc-400 uppercase tracking-wider mb-3 flex items-center gap-2">
|
||||||
|
<Phone className="w-3.5 h-3.5" />
|
||||||
|
Contato
|
||||||
|
</p>
|
||||||
|
<div>
|
||||||
|
<label className="block text-[11px] text-zinc-400 mb-1 font-medium">
|
||||||
|
WhatsApp <span className="text-amber-400 font-bold">(⚠ Obrigatório para Testar Envios)</span>
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
value={form.whatsapp}
|
||||||
|
onChange={set('whatsapp')}
|
||||||
|
className="w-full bg-black/40 border border-amber-500/30 rounded-lg px-3 py-2.5 text-white text-sm focus:outline-none focus:border-amber-500/60"
|
||||||
|
placeholder="(85) 99999-9999 — sem código do país"
|
||||||
|
/>
|
||||||
|
<p className="text-[10px] text-zinc-500 mt-1">Quando clicar em "Testar Envio" em qualquer modelo, a mensagem chegará neste número.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Endereço */}
|
||||||
|
<div>
|
||||||
|
<p className="text-[10px] font-bold text-zinc-400 uppercase tracking-wider mb-3 flex items-center gap-2">
|
||||||
|
<MapPin className="w-3.5 h-3.5" />
|
||||||
|
Endereço
|
||||||
|
</p>
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||||
|
<div>
|
||||||
|
<label className="block text-[11px] text-zinc-400 mb-1 font-medium">CEP</label>
|
||||||
|
<input
|
||||||
|
value={form.cep}
|
||||||
|
onChange={set('cep')}
|
||||||
|
className="w-full bg-black/40 border border-white/10 rounded-lg px-3 py-2.5 text-white text-sm focus:outline-none focus:border-[#E50914]/50"
|
||||||
|
placeholder="00000-000"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="md:col-span-2">
|
||||||
|
<label className="block text-[11px] text-zinc-400 mb-1 font-medium">Logradouro (Rua, Av...)</label>
|
||||||
|
<input
|
||||||
|
value={form.address}
|
||||||
|
onChange={set('address')}
|
||||||
|
className="w-full bg-black/40 border border-white/10 rounded-lg px-3 py-2.5 text-white text-sm focus:outline-none focus:border-[#E50914]/50"
|
||||||
|
placeholder="Rua das Flores"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="block text-[11px] text-zinc-400 mb-1 font-medium">Número</label>
|
||||||
|
<input
|
||||||
|
value={form.number}
|
||||||
|
onChange={set('number')}
|
||||||
|
className="w-full bg-black/40 border border-white/10 rounded-lg px-3 py-2.5 text-white text-sm focus:outline-none focus:border-[#E50914]/50"
|
||||||
|
placeholder="123"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="block text-[11px] text-zinc-400 mb-1 font-medium">Complemento</label>
|
||||||
|
<input
|
||||||
|
value={form.complement}
|
||||||
|
onChange={set('complement')}
|
||||||
|
className="w-full bg-black/40 border border-white/10 rounded-lg px-3 py-2.5 text-white text-sm focus:outline-none focus:border-[#E50914]/50"
|
||||||
|
placeholder="Apto 12, Bloco B..."
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="block text-[11px] text-zinc-400 mb-1 font-medium">Bairro</label>
|
||||||
|
<input
|
||||||
|
value={form.neighborhood}
|
||||||
|
onChange={set('neighborhood')}
|
||||||
|
className="w-full bg-black/40 border border-white/10 rounded-lg px-3 py-2.5 text-white text-sm focus:outline-none focus:border-[#E50914]/50"
|
||||||
|
placeholder="Centro"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="md:col-span-2">
|
||||||
|
<label className="block text-[11px] text-zinc-400 mb-1 font-medium">Cidade</label>
|
||||||
|
<input
|
||||||
|
value={form.city}
|
||||||
|
onChange={set('city')}
|
||||||
|
className="w-full bg-black/40 border border-white/10 rounded-lg px-3 py-2.5 text-white text-sm focus:outline-none focus:border-[#E50914]/50"
|
||||||
|
placeholder="Fortaleza"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="block text-[11px] text-zinc-400 mb-1 font-medium">Estado (UF)</label>
|
||||||
|
<select
|
||||||
|
value={form.state}
|
||||||
|
onChange={set('state')}
|
||||||
|
className="w-full bg-black/40 border border-white/10 rounded-lg px-3 py-2.5 text-white text-sm focus:outline-none focus:border-[#E50914]/50"
|
||||||
|
>
|
||||||
|
<option value="">Selecione</option>
|
||||||
|
{['AC','AL','AP','AM','BA','CE','DF','ES','GO','MA','MT','MS','MG','PA','PB','PR','PE','PI','RJ','RN','RS','RO','RR','SC','SP','SE','TO'].map(uf => (
|
||||||
|
<option key={uf} value={uf}>{uf}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Status feedback */}
|
||||||
|
{status && (
|
||||||
|
<div className={`flex items-start gap-3 p-3 rounded-lg border ${status.type === 'success' ? 'bg-emerald-500/10 border-emerald-500/30 text-emerald-300' : 'bg-red-500/10 border-red-500/30 text-red-300'}`}>
|
||||||
|
{status.type === 'success' ? <CheckCircle2 className="w-5 h-5 flex-shrink-0 mt-0.5" /> : <AlertCircle className="w-5 h-5 flex-shrink-0 mt-0.5" />}
|
||||||
|
<p className="text-sm">{status.msg}</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Footer */}
|
||||||
|
<div className="flex justify-end gap-3 px-6 py-4 border-t border-white/10 flex-shrink-0 bg-zinc-900 rounded-b-2xl">
|
||||||
|
<button onClick={onClose} className="px-4 py-2 text-sm text-zinc-400 hover:text-white transition-colors">
|
||||||
|
Fechar
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={handleSave}
|
||||||
|
disabled={isSaving || isLoading}
|
||||||
|
className="bg-[#E50914] hover:bg-red-700 text-white px-6 py-2 rounded-lg font-bold text-sm transition-colors disabled:opacity-50 flex items-center gap-2"
|
||||||
|
>
|
||||||
|
{isSaving ? <Loader2 className="w-4 h-4 animate-spin" /> : <Save className="w-4 h-4" />}
|
||||||
|
<span>{isSaving ? 'Salvando...' : 'Salvar Dados'}</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue