fix: add confirmation dialog before tenant context switch
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
import { useNavigate } from 'react-router';
|
import { useNavigate } from 'react-router';
|
||||||
import {
|
import {
|
||||||
|
AlertDialog,
|
||||||
Badge,
|
Badge,
|
||||||
Card,
|
Card,
|
||||||
DataTable,
|
DataTable,
|
||||||
@@ -37,6 +39,7 @@ export function AdminTenantsPage() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { data: tenants, isLoading, isError } = useAllTenants();
|
const { data: tenants, isLoading, isError } = useAllTenants();
|
||||||
const { setCurrentOrg } = useOrgStore();
|
const { setCurrentOrg } = useOrgStore();
|
||||||
|
const [switchTarget, setSwitchTarget] = useState<TenantResponse | null>(null);
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
@@ -58,15 +61,18 @@ export function AdminTenantsPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleRowClick = (tenant: TenantResponse) => {
|
const handleRowClick = (tenant: TenantResponse) => {
|
||||||
// Find the matching org from the store and switch context
|
setSwitchTarget(tenant);
|
||||||
|
};
|
||||||
|
|
||||||
|
const confirmSwitch = () => {
|
||||||
|
if (!switchTarget) return;
|
||||||
const orgs = useOrgStore.getState().organizations;
|
const orgs = useOrgStore.getState().organizations;
|
||||||
const match = orgs.find(
|
const match = orgs.find((o) => o.name === switchTarget.name || o.slug === switchTarget.slug);
|
||||||
(o) => o.name === tenant.name || o.slug === tenant.slug,
|
|
||||||
);
|
|
||||||
if (match) {
|
if (match) {
|
||||||
setCurrentOrg(match.id);
|
setCurrentOrg(match.id);
|
||||||
navigate('/');
|
navigate('/');
|
||||||
}
|
}
|
||||||
|
setSwitchTarget(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -83,6 +89,16 @@ export function AdminTenantsPage() {
|
|||||||
<DataTable columns={columns} data={tenants} onRowClick={handleRowClick} />
|
<DataTable columns={columns} data={tenants} onRowClick={handleRowClick} />
|
||||||
)}
|
)}
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
<AlertDialog
|
||||||
|
open={!!switchTarget}
|
||||||
|
onClose={() => setSwitchTarget(null)}
|
||||||
|
onConfirm={confirmSwitch}
|
||||||
|
title="Switch tenant?"
|
||||||
|
description={`Switch to tenant "${switchTarget?.name}"? Your dashboard context will change.`}
|
||||||
|
confirmLabel="Switch"
|
||||||
|
variant="warning"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user