import React, { useState } from "react"; import Modal from "../../components/common/Modal"; import { useAuthModal, useSelectTenant, useTenants } from "../../hooks/useAuth"; import { useProfile } from "../../hooks/useProfile"; import { useQueryClient } from "@tanstack/react-query"; import AuthRepository from "../../repositories/AuthRepository"; import Loader from "../../components/common/Loader"; const SwitchTenant = () => { const queryClient = useQueryClient(); const { profile } = useProfile(); const [pendingTenant, setPendingTenant] = useState(null); const { isOpen, onClose, onOpen } = useAuthModal(); const { data, isLoading, isError, error } = useTenants(); const { mutate: chooseTenant, isPending } = useSelectTenant(() => { onClose(); queryClient.clear(); // 2. Force fetch profile fresh for the new tenant queryClient.fetchQuery({ queryKey: ["profile"], queryFn: () => AuthRepository.profile(), }); }); const currentTenant = localStorage.getItem("ctnt"); const handleTenantselection = (tenantId) => { setPendingTenant(tenantId); localStorage.setItem("ctnt", tenantId); chooseTenant(tenantId); }; const contentBody = (
Switch Workplace
{tenant?.name}
Industry:
{tenant?.industry?.name || "Not Available"}
{tenant?.description}
)}