diff --git a/src/App.tsx b/src/App.tsx index 8df253a..4655b0a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,3 +1,4 @@ + import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom'; import { Suspense, lazy } from 'react'; import { Toaster } from "@/components/ui/sonner"; @@ -18,6 +19,7 @@ const GruposWhatsApp = lazy(() => import('./pages/GruposWhatsApp')); const NotFound = lazy(() => import('./pages/NotFound')); const CartoesCredito = lazy(() => import('./pages/CartoesCredito')); const Configuracoes = lazy(() => import('./pages/Configuracoes')); +const AdminFAQ = lazy(() => import('./pages/AdminFAQ')); function App() { const isLoggedIn = authStore((state) => state.isLoggedIn); @@ -68,6 +70,7 @@ function App() { Carregando...}>} /> Carregando...}>} /> Carregando...}>} /> + Carregando...}>} /> Carregando...}> diff --git a/src/components/help/ContactForm.tsx b/src/components/help/ContactForm.tsx new file mode 100644 index 0000000..fb86288 --- /dev/null +++ b/src/components/help/ContactForm.tsx @@ -0,0 +1,234 @@ + +import { useState } from 'react'; +import { ArrowLeft, Upload, X } from 'lucide-react'; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Textarea } from '@/components/ui/textarea'; +import { Label } from '@/components/ui/label'; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from '@/components/ui/select'; +import { useToast } from '@/hooks/use-toast'; +import { supabase } from '@/integrations/supabase/client'; + +interface ContactFormProps { + onBack: () => void; +} + +const ContactForm = ({ onBack }: ContactFormProps) => { + const [formData, setFormData] = useState({ + assunto: '', + motivo: '', + mensagem: '', + anexo: null as File | null + }); + const [loading, setLoading] = useState(false); + const { toast } = useToast(); + + const motivosContato = [ + 'Dúvida sobre funcionalidade', + 'Problema técnico', + 'Sugestão de melhoria', + 'Reclamação', + 'Elogio', + 'Outros' + ]; + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + + if (!formData.assunto || !formData.motivo || !formData.mensagem) { + toast({ + title: "Erro", + description: "Por favor, preencha todos os campos obrigatórios.", + variant: "destructive" + }); + return; + } + + setLoading(true); + + try { + let anexoUrl = null; + + // Upload do anexo se existe + if (formData.anexo) { + const fileExt = formData.anexo.name.split('.').pop(); + const fileName = `${Date.now()}.${fileExt}`; + + const { data: uploadData, error: uploadError } = await supabase.storage + .from('anexos-contato') + .upload(fileName, formData.anexo); + + if (uploadError) throw uploadError; + + const { data: { publicUrl } } = supabase.storage + .from('anexos-contato') + .getPublicUrl(fileName); + + anexoUrl = publicUrl; + } + + // Salvar contato no banco + const { error } = await supabase + .from('contatos') + .insert({ + assunto: formData.assunto, + motivo: formData.motivo, + mensagem: formData.mensagem, + anexo_url: anexoUrl, + user_id: (await supabase.auth.getUser()).data.user?.id, + status: 'pendente' + }); + + if (error) throw error; + + toast({ + title: "Mensagem enviada!", + description: "Você vai receber a resposta no e-mail que cadastrou aqui. Obrigado!", + }); + + // Reset form + setFormData({ + assunto: '', + motivo: '', + mensagem: '', + anexo: null + }); + + onBack(); + + } catch (error) { + console.error('Erro ao enviar contato:', error); + toast({ + title: "Erro", + description: "Não foi possível enviar sua mensagem. Tente novamente.", + variant: "destructive" + }); + } finally { + setLoading(false); + } + }; + + const handleFileChange = (e: React.ChangeEvent) => { + const file = e.target.files?.[0]; + if (file) { + // Validar tamanho (max 5MB) + if (file.size > 5 * 1024 * 1024) { + toast({ + title: "Arquivo muito grande", + description: "O arquivo deve ter no máximo 5MB.", + variant: "destructive" + }); + return; + } + setFormData({ ...formData, anexo: file }); + } + }; + + const removeFile = () => { + setFormData({ ...formData, anexo: null }); + }; + + return ( +
+
+ +
+

+ Você vai receber a resposta no e-mail que cadastrou aqui +

+
+
+ +
+
+ + setFormData({ ...formData, assunto: e.target.value })} + required + /> +
+ +
+ + +
+ +
+ +