import { useQuery, useQueryClient } from "@tanstack/react-query"; import { Building2, Save } from "lucide-react"; import { useState } from "react"; import { Button } from "../../components/ui/button"; import { toast } from "../../components/ui/use-toast"; import { fetchMyTenants } from "../../lib/devApi"; import { t } from "../../lib/i18n"; export default function ProfileTenantSwitcher() { const queryClient = useQueryClient(); const { data: tenants, isLoading } = useQuery({ queryKey: ["myTenants"], queryFn: fetchMyTenants, }); const [selectedTenantId, setSelectedTenantId] = useState(() => { return window.localStorage.getItem("dev_tenant_id") || ""; }); const handleSave = () => { window.localStorage.setItem("dev_tenant_id", selectedTenantId); // Invalidate queries to refresh data with new tenant context queryClient.invalidateQueries({ predicate: (query) => query.queryKey[0] !== "userMe" && query.queryKey[0] !== "myTenants", }); toast(t("ui.dev.tenant.switch_success", "테넌트 전환 완료"), "success"); }; if (isLoading || !tenants || tenants.length === 0) { return null; } // If there's only one tenant, the user doesn't need to switch. // Still show it as read-only or hidden. Let's just show it as disabled. const isSingleTenant = tenants.length <= 1; return (

{t("ui.dev.tenant.workspace", "작업 테넌트 (컨텍스트)")}

{t( "ui.dev.tenant.workspace_desc", "현재 작업 중인 테넌트를 선택하고 저장하여 API 요청 컨텍스트를 변경합니다.", )}

{isSingleTenant && (

{t( "ui.dev.tenant.single_notice", "단일 테넌트에 소속되어 전환할 필요가 없습니다.", )}

)}
); }