"use client"; import { useState, useEffect } from "react"; import { Button } from "@/components/ui/button"; import { DataTable } from "@/components/common/data-table"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Dialog, DialogContent, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Organization } from "@/types/admin"; import { adminApi } from "@/lib/api/admin"; import { ColumnDef } from "@tanstack/react-table"; import { Loader2, Plus } from "lucide-react"; export default function OrganizationsPage() { const [organizations, setOrganizations] = useState([]); const [loading, setLoading] = useState(true); const [dialogOpen, setDialogOpen] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false); const [formData, setFormData] = useState({ org_code: "", org_name: "", org_name_th: "", description: "", }); const fetchOrgs = async () => { setLoading(true); try { const data = await adminApi.getOrganizations(); setOrganizations(data); } catch (error) { console.error("Failed to fetch organizations", error); } finally { setLoading(false); } }; useEffect(() => { fetchOrgs(); }, []); const columns: ColumnDef[] = [ { accessorKey: "org_code", header: "Code" }, { accessorKey: "org_name", header: "Name (EN)" }, { accessorKey: "org_name_th", header: "Name (TH)" }, { accessorKey: "description", header: "Description" }, ]; const handleSubmit = async () => { setIsSubmitting(true); try { await adminApi.createOrganization(formData); setDialogOpen(false); setFormData({ org_code: "", org_name: "", org_name_th: "", description: "", }); fetchOrgs(); } catch (error) { console.error(error); alert("Failed to create organization"); } finally { setIsSubmitting(false); } }; return (

Organizations

Manage project organizations

{loading ? (
) : ( )} Add Organization
setFormData({ ...formData, org_code: e.target.value }) } placeholder="e.g., PAT" />
setFormData({ ...formData, org_name: e.target.value }) } />
setFormData({ ...formData, org_name_th: e.target.value }) } />
setFormData({ ...formData, description: e.target.value }) } />
); }