import { useMutation, useQuery } from "@tanstack/react-query"; import type { AxiosError } from "axios"; import { ArrowLeft, Save, Trash2 } from "lucide-react"; import { useEffect, useMemo, useState } from "react"; import { Link, useNavigate, useParams } from "react-router-dom"; import { Badge } from "../../components/ui/badge"; import { Button } from "../../components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "../../components/ui/card"; import { Input } from "../../components/ui/input"; import { Label } from "../../components/ui/label"; import { Textarea } from "../../components/ui/textarea"; import { deleteTenant, fetchTenant, updateTenant } from "../../lib/adminApi"; function TenantDetailPage() { const { id } = useParams(); const navigate = useNavigate(); const tenantId = useMemo(() => id ?? "", [id]); const tenantQuery = useQuery({ queryKey: ["tenant", tenantId], queryFn: () => fetchTenant(tenantId), enabled: tenantId !== "", }); const [name, setName] = useState(""); const [slug, setSlug] = useState(""); const [description, setDescription] = useState(""); const [status, setStatus] = useState("active"); useEffect(() => { if (!tenantQuery.data) { return; } setName(tenantQuery.data.name); setSlug(tenantQuery.data.slug); setDescription(tenantQuery.data.description ?? ""); setStatus(tenantQuery.data.status); }, [tenantQuery.data]); const updateMutation = useMutation({ mutationFn: () => updateTenant(tenantId, { name, slug, description: description || undefined, status, }), onSuccess: () => { navigate("/tenants"); }, }); const deleteMutation = useMutation({ mutationFn: () => deleteTenant(tenantId), onSuccess: () => { navigate("/tenants"); }, }); const errorMsg = (updateMutation.error as AxiosError<{ error?: string }>) ?.response?.data?.error; const loadError = (tenantQuery.error as AxiosError<{ error?: string }>) ?.response?.data?.error; const handleDelete = () => { if (!window.confirm("이 테넌트를 삭제할까요?")) { return; } deleteMutation.mutate(); }; return (
테넌트 정보를 수정하거나 삭제할 수 있습니다.