feat: admin tickets, dashboard i18n, user edit fix and location picker bugfix

This commit is contained in:
Tiago Yamamoto 2025-12-26 16:42:19 -03:00
parent 87aa558a61
commit 8eeecf76d7
13 changed files with 1021 additions and 113 deletions

View file

@ -0,0 +1,231 @@
"use client"
import { useState, useEffect } from "react"
import { useParams, useRouter } from "next/navigation"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
import { Input } from "@/components/ui/input"
import { ScrollArea } from "@/components/ui/scroll-area"
import { Badge } from "@/components/ui/badge"
import { Ticket, TicketMessage, ticketsApi } from "@/lib/api"
import { toast } from "sonner"
import { Send, ArrowLeft, Trash2 } from "lucide-react"
import { formatDistanceToNow } from "date-fns"
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog"
export default function AdminTicketDetailsPage() {
const params = useParams()
const router = useRouter()
const ticketId = params.id as string
const [ticket, setTicket] = useState<Ticket | null>(null)
const [messages, setMessages] = useState<TicketMessage[]>([])
const [loading, setLoading] = useState(true)
const [inputText, setInputText] = useState("")
const [deleteOpen, setDeleteOpen] = useState(false)
const fetchTicket = async () => {
try {
const data = await ticketsApi.get(ticketId)
setTicket(data.ticket)
setMessages(data.messages)
setLoading(false)
} catch (error) {
console.error("Failed to load ticket", error)
toast.error("Failed to load ticket")
setLoading(false)
}
}
useEffect(() => {
if (ticketId) {
fetchTicket()
}
}, [ticketId])
const handleSendMessage = async () => {
if (!inputText.trim()) return
try {
const newMsg = await ticketsApi.sendMessage(ticketId, inputText)
setMessages([...messages, newMsg])
setInputText("")
} catch (error) {
console.error("Failed to send message", error)
toast.error("Failed to send message")
}
}
const handleStatusChange = async (status: string) => {
try {
await ticketsApi.update(ticketId, { status })
setTicket(prev => prev ? { ...prev, status: status as any } : null)
toast.success("Status updated")
} catch (error) {
toast.error("Failed to update status")
}
}
const handlePriorityChange = async (priority: string) => {
try {
await ticketsApi.update(ticketId, { priority })
setTicket(prev => prev ? { ...prev, priority: priority as any } : null)
toast.success("Priority updated")
} catch (error) {
toast.error("Failed to update priority")
}
}
const handleDelete = async () => {
try {
await ticketsApi.delete(ticketId)
toast.success("Ticket deleted")
router.push("/dashboard/tickets")
} catch (error) {
toast.error("Failed to delete ticket")
}
}
if (loading) {
return <div className="p-8 text-center text-muted-foreground">Loading ticket details...</div>
}
if (!ticket) {
return <div className="p-8 text-center text-destructive">Ticket not found</div>
}
return (
<div className="space-y-6">
{/* Header */}
<div className="flex items-center justify-between">
<div className="flex items-center gap-4">
<Button variant="outline" size="icon" onClick={() => router.back()}>
<ArrowLeft className="h-4 w-4" />
</Button>
<div>
<h1 className="text-2xl font-bold flex items-center gap-2">
Ticket #{ticket.id.substring(0, 8)}
<Badge variant={ticket.status === 'open' ? 'default' : 'outline'}>{ticket.status}</Badge>
</h1>
<h2 className="text-lg text-muted-foreground">{ticket.subject}</h2>
</div>
</div>
<Button variant="destructive" onClick={() => setDeleteOpen(true)}>
<Trash2 className="h-4 w-4 mr-2" />
Delete Ticket
</Button>
</div>
<div className="grid grid-cols-3 gap-6">
{/* Main Chat Area */}
<Card className="col-span-2 h-[600px] flex flex-col">
<CardHeader className="border-b">
<CardTitle>Conversation</CardTitle>
</CardHeader>
<ScrollArea className="flex-1 p-4">
<div className="space-y-4">
{messages.map((msg) => {
const isUser = msg.userId.toString() === ticket.userId.toString() // Assuming simple string match
return (
<div key={msg.id} className={`flex ${isUser ? 'justify-start' : 'justify-end'}`}>
<div className={`p-3 rounded-lg max-w-[80%] ${isUser ? 'bg-muted' : 'bg-primary text-primary-foreground'}`}>
<p className="text-sm">{msg.message}</p>
<span className={`text-xs mt-1 block ${isUser ? 'text-muted-foreground' : 'text-primary-foreground/80'}`}>
{isUser ? 'User' : 'Admin'} {formatDistanceToNow(new Date(msg.createdAt))} ago
</span>
</div>
</div>
)
})}
</div>
</ScrollArea>
<div className="p-4 border-t flex gap-2">
<Input
value={inputText}
onChange={(e) => setInputText(e.target.value)}
placeholder="Type a reply..."
onKeyDown={(e) => {
if (e.key === 'Enter') handleSendMessage()
}}
/>
<Button onClick={handleSendMessage}>
<Send className="h-4 w-4" />
</Button>
</div>
</Card>
{/* Sidebar / Meta */}
<Card className="h-fit">
<CardHeader>
<CardTitle>Admin Controls</CardTitle>
</CardHeader>
<CardContent className="space-y-6">
<div>
<span className="text-sm font-medium text-muted-foreground mb-2 block">Status</span>
<Select value={ticket.status} onValueChange={handleStatusChange}>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="open">Open</SelectItem>
<SelectItem value="in_progress">In Progress</SelectItem>
<SelectItem value="closed">Closed</SelectItem>
</SelectContent>
</Select>
</div>
<div>
<span className="text-sm font-medium text-muted-foreground mb-2 block">Priority</span>
<Select value={ticket.priority} onValueChange={handlePriorityChange}>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="low">Low</SelectItem>
<SelectItem value="medium">Medium</SelectItem>
<SelectItem value="high">High</SelectItem>
</SelectContent>
</Select>
</div>
<div>
<span className="text-sm font-medium text-muted-foreground">User ID</span>
<p className="font-mono text-xs mt-1 break-all bg-muted p-2 rounded">{ticket.userId}</p>
</div>
<div>
<span className="text-sm font-medium text-muted-foreground">Created</span>
<p className="mt-1">{new Date(ticket.createdAt).toLocaleString()}</p>
</div>
</CardContent>
</Card>
</div>
<Dialog open={deleteOpen} onOpenChange={setDeleteOpen}>
<DialogContent>
<DialogHeader>
<DialogTitle>Delete Ticket</DialogTitle>
<DialogDescription>
Are you sure? This will delete the ticket and all messages permanently.
</DialogDescription>
</DialogHeader>
<DialogFooter>
<Button variant="outline" onClick={() => setDeleteOpen(false)}>Cancel</Button>
<Button variant="destructive" onClick={handleDelete}>Delete</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
)
}

View file

@ -0,0 +1,173 @@
"use client"
import { useState, useEffect } from "react"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table"
import { Badge } from "@/components/ui/badge"
import { Ticket, ticketsApi } from "@/lib/api"
import { toast } from "sonner"
import Link from "next/link"
import { MessageSquare, Trash2, Eye } from "lucide-react"
import { format } from "date-fns"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog"
export default function AdminTicketsPage() {
const [tickets, setTickets] = useState<Ticket[]>([])
const [loading, setLoading] = useState(true)
const [deleteId, setDeleteId] = useState<string | null>(null)
const fetchTickets = async () => {
try {
setLoading(true)
const data = await ticketsApi.listAll()
setTickets(data)
} catch (error) {
console.error("Failed to fetch tickets", error)
toast.error("Failed to fetch tickets")
} finally {
setLoading(false)
}
}
useEffect(() => {
fetchTickets()
}, [])
const handleDelete = async () => {
if (!deleteId) return
try {
await ticketsApi.delete(deleteId)
toast.success("Ticket deleted")
setDeleteId(null)
fetchTickets()
} catch (error) {
console.error("Failed to delete ticket", error)
toast.error("Failed to delete ticket")
}
}
const getStatusBadge = (status: string) => {
switch (status) {
case "open": return <Badge variant="default" className="bg-green-500">Open</Badge>
case "in_progress": return <Badge variant="secondary" className="bg-yellow-500 text-white">In Progress</Badge>
case "closed": return <Badge variant="outline">Closed</Badge>
default: return <Badge variant="outline">{status}</Badge>
}
}
const getPriorityBadge = (priority: string) => {
switch (priority) {
case "high": return <Badge variant="destructive">High</Badge>
case "medium": return <Badge variant="secondary">Medium</Badge>
case "low": return <Badge variant="outline">Low</Badge>
default: return <Badge variant="outline">{priority}</Badge>
}
}
return (
<div className="space-y-6">
<div className="flex justify-between items-center">
<div>
<h1 className="text-3xl font-bold tracking-tight">Support Tickets (Admin)</h1>
<p className="text-muted-foreground">Manage all user support tickets.</p>
</div>
</div>
<Card>
<CardHeader>
<CardTitle>All Tickets</CardTitle>
<CardDescription>A list of all support tickets from users.</CardDescription>
</CardHeader>
<CardContent>
<Table>
<TableHeader>
<TableRow>
<TableHead>ID</TableHead>
<TableHead>Subject</TableHead>
<TableHead>User ID</TableHead>
<TableHead>Status</TableHead>
<TableHead>Priority</TableHead>
<TableHead>Created</TableHead>
<TableHead className="text-right">Actions</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{loading ? (
<TableRow>
<TableCell colSpan={7} className="text-center py-4">Loading...</TableCell>
</TableRow>
) : tickets.length === 0 ? (
<TableRow>
<TableCell colSpan={7} className="text-center py-4">No tickets found</TableCell>
</TableRow>
) : (
tickets.map((ticket) => (
<TableRow key={ticket.id}>
<TableCell className="font-mono text-xs max-w-[80px] truncate" title={ticket.id}>
{ticket.id.substring(0, 8)}...
</TableCell>
<TableCell className="font-medium">{ticket.subject}</TableCell>
<TableCell className="text-xs text-muted-foreground font-mono" title={ticket.userId}>
{ticket.userId}
</TableCell>
<TableCell>{getStatusBadge(ticket.status)}</TableCell>
<TableCell>{getPriorityBadge(ticket.priority)}</TableCell>
<TableCell>{format(new Date(ticket.createdAt), "MMM d, yyyy")}</TableCell>
<TableCell className="text-right">
<div className="flex justify-end gap-2">
<Link href={`./tickets/${ticket.id}`}>
<Button variant="ghost" size="sm">
<Eye className="h-4 w-4 mr-2" />
View
</Button>
</Link>
<Button
variant="ghost"
size="sm"
onClick={() => setDeleteId(ticket.id)}
className="text-destructive hover:text-destructive"
>
<Trash2 className="h-4 w-4" />
</Button>
</div>
</TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
</CardContent>
</Card>
<Dialog open={!!deleteId} onOpenChange={(open) => !open && setDeleteId(null)}>
<DialogContent>
<DialogHeader>
<DialogTitle>Delete Ticket</DialogTitle>
<DialogDescription>
Are you sure you want to delete this ticket? This action cannot be undone.
</DialogDescription>
</DialogHeader>
<DialogFooter>
<Button variant="outline" onClick={() => setDeleteId(null)}>Cancel</Button>
<Button variant="destructive" onClick={handleDelete}>Delete</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
)
}

View file

@ -0,0 +1,110 @@
export const dashboardTranslations = {
pt: {
title: "Dashboard",
subtitle: "Visão geral do portal de vagas",
stats: {
activeJobs: "Vagas Ativas",
activeJobsDesc: "Total de vagas publicadas",
candidates: "Candidatos",
candidatesDesc: "Usuários registrados",
applications: "Candidaturas",
applicationsDesc: "Em andamento",
hiringRate: "Taxa de Contratação",
hiringRateDesc: "Candidaturas por vaga"
},
jobs: {
title: "Gerenciamento de Vagas",
add: "Nova Vaga",
table: {
title: "Título",
company: "Empresa",
status: "Status",
created: "Criado em",
actions: "Ações"
},
empty: "Nenhuma vaga encontrada."
},
candidates: {
title: "Gerenciamento de Candidatos",
table: {
name: "Nome",
email: "Email",
location: "Localização",
actions: "Ações"
},
empty: "Nenhum candidato encontrado."
}
},
en: {
title: "Dashboard",
subtitle: "Overview of the jobs portal",
stats: {
activeJobs: "Active Jobs",
activeJobsDesc: "Total posted jobs",
candidates: "Total Candidates",
candidatesDesc: "Registered users",
applications: "Active Applications",
applicationsDesc: "Current pipeline",
hiringRate: "Hiring Rate",
hiringRateDesc: "Applications per job"
},
jobs: {
title: "Job Management",
add: "Add Job",
table: {
title: "Title",
company: "Company",
status: "Status",
created: "Created At",
actions: "Actions"
},
empty: "No jobs found."
},
candidates: {
title: "Candidate Management",
table: {
name: "Name",
email: "Email",
location: "Location",
actions: "Actions"
},
empty: "No candidates found."
}
},
es: {
title: "Panel de Control",
subtitle: "Visión general del portal de empleos",
stats: {
activeJobs: "Empleos Activos",
activeJobsDesc: "Total publicados",
candidates: "Candidatos Total",
candidatesDesc: "Usuarios registrados",
applications: "Aplicaciones Activas",
applicationsDesc: "En proceso",
hiringRate: "Tasa de Contratación",
hiringRateDesc: "Aplicaciones por empleo"
},
jobs: {
title: "Gestión de Empleos",
add: "Nuevo Empleo",
table: {
title: "Título",
company: "Empresa",
status: "Estado",
created: "Creado en",
actions: "Acciones"
},
empty: "No se encontraron empleos."
},
candidates: {
title: "Gestión de Candidatos",
table: {
name: "Nombre",
email: "Correo",
location: "Ubicación",
actions: "Acciones"
},
empty: "No se encontraron candidatos."
}
}
}

View file

@ -418,14 +418,25 @@ export default function AdminUsersPage() {
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={() => setIsEditDialogOpen(false)}>
{viewing ? "Close" : "Cancel"}
</Button>
{!viewing && (
<Button onClick={handleUpdate} disabled={updating}>
{updating && <Loader2 className="h-4 w-4 mr-2 animate-spin" />}
Save Changes
</Button>
{viewing ? (
<>
<Button variant="outline" onClick={() => setIsEditDialogOpen(false)}>
Close
</Button>
<Button onClick={() => setViewing(false)}>
Edit
</Button>
</>
) : (
<>
<Button variant="outline" onClick={() => setIsEditDialogOpen(false)}>
Cancel
</Button>
<Button onClick={handleUpdate} disabled={updating}>
{updating && <Loader2 className="h-4 w-4 mr-2 animate-spin" />}
Save Changes
</Button>
</>
)}
</DialogFooter>
</DialogContent>

View file

@ -2,6 +2,7 @@
import { useState } from "react";
import { useRouter } from "next/navigation";
import { translations, Language } from "./translations";
import { toast } from "sonner";
import { Navbar } from "@/components/navbar";
import { Footer } from "@/components/footer";
@ -47,18 +48,28 @@ const getCurrencySymbol = (code: string): string => {
return symbols[code] || code;
};
// Salary period label helper
const getSalaryPeriodLabel = (type: string): string => {
const labels: Record<string, string> = {
'hourly': '/hora', 'daily': '/dia', 'weekly': '/semana',
'monthly': '/mês', 'yearly': '/ano'
};
return labels[type] || '';
};
export default function PostJobPage() {
const router = useRouter();
const [step, setStep] = useState<1 | 2>(1);
// Language State
const [lang, setLang] = useState<Language>('pt');
const t = translations[lang];
// Helper inside to use t
const getSalaryPeriodLabel = (type: string): string => {
const labels: Record<string, string> = {
'hourly': t.options.period.hourly,
'daily': t.options.period.daily,
'weekly': t.options.period.weekly,
'monthly': t.options.period.monthly,
'yearly': t.options.period.yearly
};
return labels[type] || '';
};
const [loading, setLoading] = useState(false);
// Company/User data
@ -208,11 +219,25 @@ export default function PostJobPage() {
<main className="flex-1 py-12">
<div className="container max-w-2xl mx-auto px-4">
<div className="text-center mb-8">
<h1 className="text-3xl font-bold mb-2">Postar uma Vaga</h1>
<p className="text-muted-foreground">
Cadastre sua empresa e publique sua vaga em poucos minutos
</p>
<div className="relative mb-8">
<div className="absolute right-0 top-0">
<Select value={lang} onValueChange={(v) => setLang(v as Language)}>
<SelectTrigger className="w-[140px]">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="pt">🇧🇷 Português</SelectItem>
<SelectItem value="en">🇺🇸 English</SelectItem>
<SelectItem value="es">🇪🇸 Español</SelectItem>
</SelectContent>
</Select>
</div>
<div className="text-center pt-2">
<h1 className="text-3xl font-bold mb-2">{t.title}</h1>
<p className="text-muted-foreground">
{t.subtitle}
</p>
</div>
</div>
{/* Progress Steps */}
@ -226,7 +251,7 @@ export default function PostJobPage() {
{s}
</div>
<span className="hidden sm:inline text-sm">
{s === 1 ? "Dados" : "Confirmar"}
{s === 1 ? t.steps.data : t.steps.confirm}
</span>
</div>
))}
@ -235,12 +260,12 @@ export default function PostJobPage() {
<Card>
<CardHeader>
<CardTitle>
{step === 1 && "Empresa & Vaga"}
{step === 2 && "Confirmar e Publicar"}
{step === 1 && t.cardTitle.step1}
{step === 2 && t.cardTitle.step2}
</CardTitle>
<CardDescription>
{step === 1 && "Informe os dados da empresa e da vaga"}
{step === 2 && "Revise as informações antes de publicar"}
{step === 1 && t.cardDesc.step1}
{step === 2 && t.cardDesc.step2}
</CardDescription>
</CardHeader>
<CardContent>
@ -248,19 +273,19 @@ export default function PostJobPage() {
{step === 1 && (
<div className="space-y-4">
<div>
<Label>Nome da Empresa *</Label>
<Label>{t.company.name}</Label>
<div className="relative">
<Building2 className="absolute left-3 top-3 h-4 w-4 text-muted-foreground" />
<Input
value={company.name}
onChange={(e) => setCompany({ ...company, name: e.target.value })}
placeholder="Minha Empresa Ltda"
placeholder={t.company.namePlaceholder}
className="pl-10"
/>
</div>
</div>
<div>
<Label>Email *</Label>
<Label>{t.company.email}</Label>
<div className="relative">
<Mail className="absolute left-3 top-3 h-4 w-4 text-muted-foreground" />
<Input
@ -275,7 +300,7 @@ export default function PostJobPage() {
{/* Password Field */}
<div>
<Label>Senha *</Label>
<Label>{t.company.password}</Label>
<div className="relative">
<Lock className="absolute left-3 top-3 h-4 w-4 text-muted-foreground" />
<Input
@ -297,7 +322,7 @@ export default function PostJobPage() {
{/* Confirm Password Field */}
<div>
<Label>Confirmar Senha *</Label>
<Label>{t.company.confirmPassword}</Label>
<div className="relative">
<Lock className="absolute left-3 top-3 h-4 w-4 text-muted-foreground" />
<Input
@ -319,11 +344,11 @@ export default function PostJobPage() {
{/* Phone Field with DDI */}
<div>
<Label>Telefone</Label>
<div className="flex gap-2">
<div className="w-[140px]">
<Label>{t.company.phone}</Label>
<div className="flex border rounded-md focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2">
<div className="w-[140px] border-r">
<Select value={company.ddi} onValueChange={(val) => setCompany({ ...company, ddi: val })}>
<SelectTrigger className="pl-9 relative">
<SelectTrigger className="pl-9 relative border-0 shadow-none focus:ring-0 rounded-r-none h-10">
<Globe className="absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground" />
<SelectValue placeholder="DDI" />
</SelectTrigger>
@ -346,18 +371,18 @@ export default function PostJobPage() {
value={formatPhoneForDisplay(company.phone)}
onChange={(e) => setCompany({ ...company, phone: e.target.value })}
placeholder="11 99999-9999"
className="pl-10"
className="pl-10 border-0 shadow-none focus-visible:ring-0 rounded-l-none h-10"
/>
</div>
</div>
<p className="text-xs text-muted-foreground mt-1 ml-1">
Selecione o código do país e digite o número com DDD.
{t.company.phoneHelp}
</p>
</div>
{/* Website */}
<div>
<Label>Site da Empresa</Label>
<Label>{t.company.website}</Label>
<div className="relative">
<Globe className="absolute left-3 top-3 h-4 w-4 text-muted-foreground" />
<Input
@ -373,13 +398,13 @@ export default function PostJobPage() {
{/* Employee Count & Founded Year */}
<div className="grid grid-cols-2 gap-4">
<div>
<Label> de Funcionários</Label>
<Label>{t.company.size}</Label>
<select
value={company.employeeCount}
onChange={(e) => setCompany({ ...company, employeeCount: e.target.value })}
className="w-full px-3 py-2 border rounded-lg bg-background"
>
<option value="">Selecione</option>
<option value="">{t.company.sizePlaceholder}</option>
<option value="1-10">1-10</option>
<option value="11-50">11-50</option>
<option value="51-200">51-200</option>
@ -389,7 +414,7 @@ export default function PostJobPage() {
</select>
</div>
<div>
<Label>Ano de Fundação</Label>
<Label>{t.company.founded}</Label>
<Input
type="number"
value={company.foundedYear}
@ -403,7 +428,7 @@ export default function PostJobPage() {
{/* About Company */}
<div>
<Label>Sobre a Empresa</Label>
<Label>{t.company.description}</Label>
<RichTextEditor
value={company.description}
onChange={(val) => setCompany({ ...company, description: val })}
@ -415,24 +440,24 @@ export default function PostJobPage() {
{/* Separator */}
<div className="border-t pt-6 mt-6">
<h3 className="font-semibold text-lg mb-4 flex items-center gap-2">
<Briefcase className="h-5 w-5" /> Dados da Vaga
<Briefcase className="h-5 w-5" /> {t.job.title}
</h3>
</div>
<div>
<Label>Título da Vaga *</Label>
<Label>{t.job.jobTitle}</Label>
<div className="relative">
<Briefcase className="absolute left-3 top-3 h-4 w-4 text-muted-foreground" />
<Input
value={job.title}
onChange={(e) => setJob({ ...job, title: e.target.value })}
placeholder="Desenvolvedor Full Stack"
placeholder={t.job.jobTitlePlaceholder}
className="pl-10"
/>
</div>
</div>
<div>
<Label>Descrição da Vaga *</Label>
<Label>{t.job.description}</Label>
<RichTextEditor
value={job.description}
onChange={(val) => setJob({ ...job, description: val })}
@ -452,7 +477,7 @@ export default function PostJobPage() {
{/* Salary Section */}
<div className="space-y-3">
<div className="flex items-center justify-between">
<Label>Salário</Label>
<Label>{t.job.salary}</Label>
<label className="flex items-center gap-2 text-sm cursor-pointer">
<input
type="checkbox"
@ -460,7 +485,7 @@ export default function PostJobPage() {
onChange={(e) => setJob({ ...job, salaryNegotiable: e.target.checked })}
className="rounded"
/>
<span className="text-muted-foreground">Candidato envia proposta</span>
<span className="text-muted-foreground">{t.job.salaryNegotiable}</span>
</label>
</div>
@ -469,7 +494,7 @@ export default function PostJobPage() {
{/* Currency and Period Row */}
<div className="grid grid-cols-2 gap-2">
<div>
<Label className="text-xs text-muted-foreground">Moeda</Label>
<Label className="text-xs text-muted-foreground">{t.job.currency}</Label>
<select
value={job.currency}
onChange={(e) => setJob({ ...job, currency: e.target.value })}
@ -488,17 +513,17 @@ export default function PostJobPage() {
</select>
</div>
<div>
<Label className="text-xs text-muted-foreground">Período</Label>
<Label className="text-xs text-muted-foreground">{t.job.period}</Label>
<select
value={job.salaryType}
onChange={(e) => setJob({ ...job, salaryType: e.target.value })}
className="w-full px-3 py-2 border rounded-lg bg-background text-sm"
>
<option value="hourly">por hora</option>
<option value="daily">por dia</option>
<option value="weekly">por semana</option>
<option value="monthly">por mês</option>
<option value="yearly">por ano</option>
<option value="hourly">{t.options.period.hourly}</option>
<option value="daily">{t.options.period.daily}</option>
<option value="weekly">{t.options.period.weekly}</option>
<option value="monthly">{t.options.period.monthly}</option>
<option value="yearly">{t.options.period.yearly}</option>
</select>
</div>
</div>
@ -542,48 +567,48 @@ export default function PostJobPage() {
</div>
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<Label>Tipo de Contrato</Label>
<Label>{t.job.contractType}</Label>
<select
value={job.employmentType}
onChange={(e) => setJob({ ...job, employmentType: e.target.value })}
className="w-full px-3 py-2 border rounded-lg bg-background"
>
<option value="">Qualquer</option>
<option value="permanent">Permanente</option>
<option value="contract">Contrato (PJ)</option>
<option value="training">Estágio/Trainee</option>
<option value="temporary">Temporário</option>
<option value="voluntary">Voluntário</option>
<option value="">{t.options.any}</option>
<option value="permanent">{t.options.contract.permanent}</option>
<option value="contract">{t.options.contract.contract}</option>
<option value="training">{t.options.contract.training}</option>
<option value="temporary">{t.options.contract.temporary}</option>
<option value="voluntary">{t.options.contract.voluntary}</option>
</select>
</div>
<div>
<Label>Jornada de Trabalho</Label>
<Label>{t.job.workingHours}</Label>
<select
value={job.workingHours}
onChange={(e) => setJob({ ...job, workingHours: e.target.value })}
className="w-full px-3 py-2 border rounded-lg bg-background"
>
<option value="">Qualquer</option>
<option value="full-time">Tempo Integral</option>
<option value="part-time">Meio Período</option>
<option value="">{t.options.any}</option>
<option value="full-time">{t.options.hours.fullTime}</option>
<option value="part-time">{t.options.hours.partTime}</option>
</select>
</div>
<div>
<Label>Modelo de Trabalho</Label>
<Label>{t.job.workMode}</Label>
<select
value={job.workMode}
onChange={(e) => setJob({ ...job, workMode: e.target.value })}
className="w-full px-3 py-2 border rounded-lg"
>
<option value="remote">Remoto</option>
<option value="hybrid">Híbrido</option>
<option value="onsite">Presencial</option>
<option value="remote">{t.options.mode.remote}</option>
<option value="hybrid">{t.options.mode.hybrid}</option>
<option value="onsite">{t.options.mode.onsite}</option>
</select>
</div>
</div>
<Button onClick={() => setStep(2)} className="w-full">
Próximo: Confirmar
{t.buttons.next}
</Button>
</div>
)}
@ -593,33 +618,39 @@ export default function PostJobPage() {
<div className="space-y-6">
<div className="bg-muted/50 rounded-lg p-4">
<h3 className="font-semibold mb-2 flex items-center gap-2">
<Building2 className="h-4 w-4" /> Empresa
<Building2 className="h-4 w-4" /> {t.common.company}
</h3>
<p><strong>Nome:</strong> {company.name}</p>
<p><strong>Email:</strong> {company.email}</p>
{company.phone && <p><strong>Telefone:</strong> {company.ddi} {company.phone}</p>}
<p><strong>{t.common.name}:</strong> {company.name}</p>
<p><strong>{t.common.email}:</strong> {company.email}</p>
{company.phone && <p><strong>{t.common.phone}:</strong> {company.ddi} {company.phone}</p>}
</div>
<div className="bg-muted/50 rounded-lg p-4">
<h3 className="font-semibold mb-2 flex items-center gap-2">
<Briefcase className="h-4 w-4" /> Vaga
<Briefcase className="h-4 w-4" /> {t.common.job}
</h3>
<p><strong>Título:</strong> {job.title}</p>
<p><strong>Localização:</strong> {job.location || "Não informado"}</p>
<p><strong>Salário:</strong> {
<p><strong>{t.common.title}:</strong> {job.title}</p>
<p><strong>{t.common.location}:</strong> {job.location || "Não informado"}</p>
<p><strong>{t.common.salary}:</strong> {
job.salaryNegotiable
? "Candidato envia proposta"
? t.job.salaryNegotiable
: salaryMode === 'fixed'
? (job.salaryFixed ? `${getCurrencySymbol(job.currency)} ${job.salaryFixed} ${getSalaryPeriodLabel(job.salaryType)}` : "A combinar")
: (job.salaryMin && job.salaryMax ? `${getCurrencySymbol(job.currency)} ${job.salaryMin} - ${job.salaryMax} ${getSalaryPeriodLabel(job.salaryType)}` : "A combinar")
? (job.salaryFixed ? `${getCurrencySymbol(job.currency)} ${job.salaryFixed} ${getSalaryPeriodLabel(job.salaryType)}` : t.job.salaryNegotiable)
: (job.salaryMin && job.salaryMax ? `${getCurrencySymbol(job.currency)} ${job.salaryMin} - ${job.salaryMax} ${getSalaryPeriodLabel(job.salaryType)}` : t.job.salaryNegotiable)
}</p>
<p><strong>Tipo:</strong> {job.employmentType || "Qualquer"} / {job.workingHours === 'full-time' ? 'Integral' : job.workingHours === 'part-time' ? 'Meio Período' : 'Qualquer'} / {job.workMode}</p>
<p><strong>{t.common.type}:</strong> {
(job.employmentType ? (t.options.contract[job.employmentType as keyof typeof t.options.contract] || job.employmentType) : t.options.any)
} / {
job.workingHours === 'full-time' ? t.options.hours.fullTime : job.workingHours === 'part-time' ? t.options.hours.partTime : t.options.any
} / {
job.workMode === 'remote' ? t.options.mode.remote : job.workMode === 'hybrid' ? t.options.mode.hybrid : t.options.mode.onsite
}</p>
</div>
<div className="flex gap-3">
<Button variant="outline" onClick={() => setStep(1)} className="flex-1">
Voltar
{t.buttons.back}
</Button>
<Button onClick={handleSubmit} disabled={loading} className="flex-1">
{loading ? "Publicando..." : "Publicar Vaga"}
{loading ? t.buttons.publishing : t.buttons.publish}
</Button>
</div>
</div>

View file

@ -0,0 +1,274 @@
export const translations = {
pt: {
title: "Postar uma Vaga",
subtitle: "Cadastre sua empresa e publique sua vaga em poucos minutos",
steps: {
data: "Dados",
confirm: "Confirmar"
},
cardTitle: {
step1: "Empresa & Vaga",
step2: "Confirmar e Publicar"
},
cardDesc: {
step1: "Informe os dados da empresa e da vaga",
step2: "Revise as informações antes de publicar"
},
common: {
company: "Empresa",
job: "Vaga",
name: "Nome",
email: "Email",
phone: "Telefone",
title: "Título",
location: "Localização",
salary: "Salário",
type: "Tipo"
},
company: {
name: "Nome da Empresa *",
namePlaceholder: "Minha Empresa Ltda",
email: "Email *",
emailPlaceholder: "contato@empresa.com",
password: "Senha *",
confirmPassword: "Confirmar Senha *",
phone: "Telefone",
phoneHelp: "Selecione o código do país e digite o número com DDD.",
website: "Site da Empresa",
websitePlaceholder: "https://minhaempresa.com",
size: "Tamanho da Empresa",
sizePlaceholder: "Selecione o tamanho",
founded: "Ano de Fundação",
description: "Sobre a Empresa"
},
job: {
title: "Dados da Vaga",
jobTitle: "Título da Vaga *",
jobTitlePlaceholder: "ex: Desenvolvedor Frontend Senior",
location: "Localização",
locationPlaceholder: "ex: São Paulo, SP (ou Remoto)",
salary: "Salário",
salaryNegotiable: "A combinar",
currency: "Moeda",
period: "Período",
contractType: "Tipo de Contrato",
workMode: "Modelo de Trabalho",
workingHours: "Jornada de Trabalho",
description: "Descrição da Vaga"
},
options: {
any: "Qualquer",
period: {
hourly: "por hora",
daily: "por dia",
weekly: "por semana",
monthly: "por mês",
yearly: "por ano"
},
contract: {
permanent: "Permanente",
contract: "Contrato (PJ)",
training: "Estágio/Trainee",
temporary: "Temporário",
voluntary: "Voluntário"
},
hours: {
fullTime: "Tempo Integral",
partTime: "Meio Período"
},
mode: {
remote: "Remoto",
hybrid: "Híbrido",
onsite: "Presencial"
}
},
buttons: {
back: "Voltar",
next: "Próximo: Confirmar",
publish: "Publicar Vaga",
publishing: "Publicando..."
}
},
en: {
title: "Post a Job",
subtitle: "Register your company and publish your job in minutes",
steps: {
data: "Details",
confirm: "Confirm"
},
cardTitle: {
step1: "Company & Job",
step2: "Confirm & Publish"
},
cardDesc: {
step1: "Enter company and job details",
step2: "Review information before publishing"
},
common: {
company: "Company",
job: "Job",
name: "Name",
email: "Email",
phone: "Phone",
title: "Title",
location: "Location",
salary: "Salary",
type: "Type"
},
company: {
name: "Company Name *",
namePlaceholder: "My Company Ltd",
email: "Email *",
emailPlaceholder: "contact@company.com",
password: "Password *",
confirmPassword: "Confirm Password *",
phone: "Phone",
phoneHelp: "Select country code and enter number.",
website: "Company Website",
websitePlaceholder: "https://mycompany.com",
size: "Company Size",
sizePlaceholder: "Select size",
founded: "Founded Year",
description: "About the Company"
},
job: {
title: "Job Details",
jobTitle: "Job Title *",
jobTitlePlaceholder: "e.g. Senior Frontend Developer",
location: "Location",
locationPlaceholder: "e.g. New York, NY (or Remote)",
salary: "Salary",
salaryNegotiable: "Negotiable",
currency: "Currency",
period: "Period",
contractType: "Contract Type",
workMode: "Work Mode",
workingHours: "Working Hours",
description: "Job Description"
},
options: {
any: "Any",
period: {
hourly: "/hour",
daily: "/day",
weekly: "/week",
monthly: "/month",
yearly: "/year"
},
contract: {
permanent: "Permanent",
contract: "Contract",
training: "Internship/Trainee",
temporary: "Temporary",
voluntary: "Voluntary"
},
hours: {
fullTime: "Full-time",
partTime: "Part-time"
},
mode: {
remote: "Remote",
hybrid: "Hybrid",
onsite: "On-site"
}
},
buttons: {
back: "Back",
next: "Next: Confirm",
publish: "Publish Job",
publishing: "Publishing..."
}
},
es: {
title: "Publicar un Empleo",
subtitle: "Registre su empresa y publique su vacante en minutos",
steps: {
data: "Datos",
confirm: "Confirmar"
},
cardTitle: {
step1: "Empresa y Empleo",
step2: "Confirmar y Publicar"
},
cardDesc: {
step1: "Ingrese los datos de la empresa y del empleo",
step2: "Revise la información antes de publicar"
},
common: {
company: "Empresa",
job: "Empleo",
name: "Nombre",
email: "Correo",
phone: "Teléfono",
title: "Título",
location: "Ubicación",
salary: "Salario",
type: "Tipo"
},
company: {
name: "Nombre de la Empresa *",
namePlaceholder: "Mi Empresa Ltda",
email: "Correo Electrónico *",
emailPlaceholder: "contacto@empresa.com",
password: "Contraseña *",
confirmPassword: "Confirmar Contraseña *",
phone: "Teléfono",
phoneHelp: "Seleccione el código de país e ingrese el número.",
website: "Sitio Web",
websitePlaceholder: "https://miempresa.com",
size: "Tamaño de la Empresa",
sizePlaceholder: "Seleccione tamaño",
founded: "Año de Fundación",
description: "Sobre la Empresa"
},
job: {
title: "Datos del Empleo",
jobTitle: "Título del Puesto *",
jobTitlePlaceholder: "ej: Desarrollador Frontend Senior",
location: "Ubicación",
locationPlaceholder: "ej: Ciudad de México (o Remoto)",
salary: "Salario",
salaryNegotiable: "A convenir",
currency: "Moneda",
period: "Periodo",
contractType: "Tipo de Contrato",
workMode: "Modalidad",
workingHours: "Jornada Laboral",
description: "Descripción del Puesto"
},
options: {
any: "Cualquiera",
period: {
hourly: "por hora",
daily: "por día",
weekly: "por semana",
monthly: "por mes",
yearly: "por año"
},
contract: {
permanent: "Permanente",
contract: "Contrato",
training: "Pasantía",
temporary: "Temporal",
voluntary: "Voluntario"
},
hours: {
fullTime: "Tiempo Completo",
partTime: "Medio Tiempo"
},
mode: {
remote: "Remoto",
hybrid: "Híbrido",
onsite: "Presencial"
}
},
buttons: {
back: "Volver",
next: "Siguiente: Confirmar",
publish: "Publicar Empleo",
publishing: "Publicando..."
}
}
}
export type Language = 'pt' | 'en' | 'es'

View file

@ -23,10 +23,14 @@ import { Briefcase, Users, TrendingUp, FileText, Plus, MoreHorizontal, Loader2 }
import { motion } from "framer-motion"
import { adminJobsApi, adminCandidatesApi, type AdminJob, type AdminCandidate, type AdminCandidateStats } from "@/lib/api"
import { toast } from "sonner"
import { useLanguageStore } from "@/lib/store/language-store"
import { dashboardTranslations } from "@/app/dashboard/translations"
export function AdminDashboardContent() {
const [isDialogOpen, setIsDialogOpen] = useState(false)
const [isLoading, setIsLoading] = useState(true)
const { language } = useLanguageStore()
const t = dashboardTranslations[language]
const [stats, setStats] = useState({
activeJobs: 0,
@ -100,8 +104,8 @@ export function AdminDashboardContent() {
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.5 }}
>
<h1 className="text-3xl font-bold mb-2">Dashboard</h1>
<p className="text-muted-foreground">Overview of the jobs portal</p>
<h1 className="text-3xl font-bold mb-2">{t.title}</h1>
<p className="text-muted-foreground">{t.subtitle}</p>
</motion.div>
{/* Stats */}
@ -112,28 +116,28 @@ export function AdminDashboardContent() {
className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6"
>
<StatsCard
title="Active jobs"
title={t.stats.activeJobs}
value={stats.activeJobs}
icon={Briefcase}
description="Total posted jobs"
description={t.stats.activeJobsDesc}
/>
<StatsCard
title="Total candidates"
title={t.stats.candidates}
value={stats.totalCandidates}
icon={Users}
description="Registered users"
description={t.stats.candidatesDesc}
/>
<StatsCard
title="Active applications"
title={t.stats.applications}
value={stats.newApplications}
icon={FileText}
description="Current pipeline"
description={t.stats.applicationsDesc}
/>
<StatsCard
title="Hiring rate"
title={t.stats.hiringRate}
value={`${stats.conversionRate.toFixed(1)}%`}
icon={TrendingUp}
description="Applications per job"
description={t.stats.hiringRateDesc}
/>
</motion.div>
@ -145,12 +149,12 @@ export function AdminDashboardContent() {
>
<Card>
<CardHeader className="flex flex-row items-center justify-between">
<CardTitle>Job management</CardTitle>
<CardTitle>{t.jobs.title}</CardTitle>
<Dialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
<DialogTrigger asChild>
<Button>
<Plus className="mr-2 h-4 w-4" />
Add job
{t.jobs.add}
</Button>
</DialogTrigger>
<DialogContent className="max-w-2xl">
@ -195,17 +199,17 @@ export function AdminDashboardContent() {
<Table>
<TableHeader>
<TableRow>
<TableHead>Title</TableHead>
<TableHead>Company</TableHead>
<TableHead>Status</TableHead>
<TableHead>Created At</TableHead>
<TableHead className="text-right">Actions</TableHead>
<TableHead>{t.jobs.table.title}</TableHead>
<TableHead>{t.jobs.table.company}</TableHead>
<TableHead>{t.jobs.table.status}</TableHead>
<TableHead>{t.jobs.table.created}</TableHead>
<TableHead className="text-right">{t.jobs.table.actions}</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{recentJobs.length === 0 ? (
<TableRow>
<TableCell colSpan={5} className="text-center text-muted-foreground">No jobs found.</TableCell>
<TableCell colSpan={5} className="text-center text-muted-foreground">{t.jobs.empty}</TableCell>
</TableRow>
) : (
recentJobs.map((job) => (
@ -238,16 +242,16 @@ export function AdminDashboardContent() {
>
<Card>
<CardHeader>
<CardTitle>Candidate management</CardTitle>
<CardTitle>{t.candidates.title}</CardTitle>
</CardHeader>
<CardContent>
<Table>
<TableHeader>
<TableRow>
<TableHead>Name</TableHead>
<TableHead>Email</TableHead>
<TableHead>Location</TableHead>
<TableHead className="text-right">Actions</TableHead>
<TableHead>{t.candidates.table.name}</TableHead>
<TableHead>{t.candidates.table.email}</TableHead>
<TableHead>{t.candidates.table.location}</TableHead>
<TableHead className="text-right">{t.candidates.table.actions}</TableHead>
</TableRow>
</TableHeader>
<TableBody>

View file

@ -16,6 +16,7 @@ import {
import { LogOut, User } from "lucide-react";
import { logout, getCurrentUser } from "@/lib/auth";
import { NotificationsDropdown } from "@/components/notifications-dropdown";
import { LanguageSelector } from "@/components/language-selector";
export function DashboardHeader() {
const router = useRouter();
@ -49,6 +50,7 @@ export function DashboardHeader() {
<div className="hidden md:block"></div>
<div className="flex items-center gap-4">
<LanguageSelector />
<NotificationsDropdown />
<DropdownMenu>

View file

@ -0,0 +1,29 @@
"use client"
import { useLanguageStore, Language } from "@/lib/store/language-store"
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select"
import { Globe } from "lucide-react"
export function LanguageSelector() {
const { language, setLanguage } = useLanguageStore()
return (
<Select value={language} onValueChange={(v) => setLanguage(v as Language)}>
<SelectTrigger className="w-[140px] border-0 shadow-none bg-transparent focus:ring-0">
<Globe className="mr-2 h-4 w-4 text-muted-foreground" />
<SelectValue placeholder="Language" />
</SelectTrigger>
<SelectContent align="end">
<SelectItem value="pt">🇧🇷 Português</SelectItem>
<SelectItem value="en">🇺🇸 English</SelectItem>
<SelectItem value="es">🇪🇸 Español</SelectItem>
</SelectContent>
</Select>
)
}

View file

@ -47,7 +47,7 @@ export function LocationPicker({ value, onChange }: LocationPickerProps) {
const timeout = setTimeout(() => {
setLoading(true);
locationsApi.search(query, selectedCountry)
.then(setResults)
.then(res => setResults(res || []))
.catch(err => {
console.error("Search failed", err);
setResults([]);
@ -123,7 +123,7 @@ export function LocationPicker({ value, onChange }: LocationPickerProps) {
</div>
{/* Results Dropdown */}
{showResults && results.length > 0 && (
{showResults && results?.length > 0 && (
<div className="absolute z-10 w-full mt-1 bg-background border rounded-md shadow-lg max-h-60 overflow-auto">
{results.map((item) => (
<button

View file

@ -4,7 +4,7 @@ import Link from "next/link"
import Image from "next/image"
import { usePathname } from "next/navigation"
import { cn } from "@/lib/utils"
import { LayoutDashboard, Briefcase, Users, MessageSquare, Building2, FileText, HelpCircle } from "lucide-react"
import { LayoutDashboard, Briefcase, Users, MessageSquare, Building2, FileText, HelpCircle, Ticket } from "lucide-react"
import { getCurrentUser, isAdminUser } from "@/lib/auth"
const adminItems = [
@ -43,6 +43,11 @@ const adminItems = [
href: "/dashboard/messages",
icon: MessageSquare,
},
{
title: "Tickets",
href: "/dashboard/tickets",
icon: Ticket,
},
]
const companyItems = [

View file

@ -503,6 +503,21 @@ export const ticketsApi = {
body: JSON.stringify({ message }),
});
},
// Admin methods
listAll: () => {
return apiRequest<Ticket[]>("/api/v1/support/tickets/all");
},
update: (id: string, data: { status?: string; priority?: string }) => {
return apiRequest<Ticket>(`/api/v1/support/tickets/${id}`, {
method: "PATCH",
body: JSON.stringify(data),
});
},
delete: (id: string) => {
return apiRequest<void>(`/api/v1/support/tickets/${id}`, {
method: "DELETE",
});
},
};
// --- Profile ---
@ -795,7 +810,9 @@ export const locationsApi = {
listCountries: () => apiRequest<Country[]>("/api/v1/locations/countries"),
listStates: (countryId: number | string) => apiRequest<State[]>(`/api/v1/locations/countries/${countryId}/states`),
listCities: (stateId: number | string) => apiRequest<City[]>(`/api/v1/locations/states/${stateId}/cities`),
search: (query: string, countryId: number | string) =>
apiRequest<LocationSearchResult[]>(`/api/v1/locations/search?q=${encodeURIComponent(query)}&country_id=${countryId}`),
search: async (query: string, countryId: number | string) => {
const res = await apiRequest<LocationSearchResult[]>(`/api/v1/locations/search?q=${encodeURIComponent(query)}&country_id=${countryId}`);
return res || [];
},
};

View file

@ -0,0 +1,21 @@
import { create } from 'zustand'
import { persist } from 'zustand/middleware'
export type Language = 'pt' | 'en' | 'es'
interface LanguageState {
language: Language
setLanguage: (language: Language) => void
}
export const useLanguageStore = create<LanguageState>()(
persist(
(set) => ({
language: 'pt',
setLanguage: (language) => set({ language }),
}),
{
name: 'language-storage',
}
)
)