Countries
Manage visa destinations
"use client"; import { useState, useEffect } from "react"; import { useRouter } from "next/navigation"; import { useAuth } from "../../hooks/useAuth"; import { useCountries } from "../../hooks/useCountries"; import Sidebar from "../../components/Sidebar"; import Header from "../../components/Header"; import CountryCard from "../../components/CountryCard"; import { countryAPI } from "../../lib/api"; import { toast } from "react-toastify"; import { Plus, X, Globe } from "lucide-react"; export default function CountriesPage() { const router = useRouter(); const { user, loading, isAdmin } = useAuth(); const { countries, refetch } = useCountries(); const [showModal, setShowModal] = useState(false); const [form, setForm] = useState({ name: "", code: "", flag_emoji: "", vfs_url: "", processing_time: "", visa_types: "", requirements: "" }); useEffect(() => { if (!loading && !user) router.push("/login"); }, [user, loading, router]); const handleCreate = async (e: React.FormEvent) => { e.preventDefault(); try { const visa_types = form.visa_types.split(",").map((s) => s.trim()).filter(Boolean); const requirements = form.requirements.split("\n").map((s) => s.trim()).filter(Boolean); await countryAPI.create({ ...form, visa_types, requirements }); toast.success("Country created"); setShowModal(false); setForm({ name: "", code: "", flag_emoji: "", vfs_url: "", processing_time: "", visa_types: "", requirements: "" }); refetch(); } catch (error: any) { toast.error(error.response?.data?.message || "Failed to create country"); } }; const handleDelete = async (id: string) => { if (!confirm("Delete this country?")) return; try { await countryAPI.delete(id); toast.success("Country deleted"); refetch(); } catch (error: any) { toast.error(error.response?.data?.message || "Failed to delete"); } }; if (loading || !user) return null; return (
Manage visa destinations