issues fixed on tenants
This commit is contained in:
@@ -240,6 +240,9 @@ const AllTenants = () => {
|
||||
event.preventDefault();
|
||||
if (!selectedTenant) return;
|
||||
|
||||
// Capture the ID to use in the async context
|
||||
const tenantId = selectedTenant.id;
|
||||
|
||||
setEditError("");
|
||||
setIsSaving(true);
|
||||
|
||||
@@ -251,15 +254,22 @@ const AllTenants = () => {
|
||||
is_active: editForm.is_active,
|
||||
};
|
||||
|
||||
const updatedTenant = await tenantsApi.update(selectedTenant.id, payload);
|
||||
const updatedTenant = await tenantsApi.update(tenantId, payload);
|
||||
|
||||
// Safeguard: Ensure we actually got a tenant back
|
||||
if (!updatedTenant || !updatedTenant.id) {
|
||||
throw new Error("Invalid response from server");
|
||||
}
|
||||
|
||||
setTenants((prev) =>
|
||||
prev.map((tenant) =>
|
||||
tenant.id === updatedTenant.id ? updatedTenant : tenant
|
||||
tenant.id === tenantId ? updatedTenant : tenant
|
||||
)
|
||||
);
|
||||
setIsEditOpen(false);
|
||||
setSelectedTenant(null);
|
||||
} catch (error) {
|
||||
console.error("Update failed:", error);
|
||||
const message =
|
||||
error instanceof Error ? error.message : "Unable to update tenant.";
|
||||
setEditError(message);
|
||||
@@ -271,17 +281,21 @@ const AllTenants = () => {
|
||||
const handleDelete = async () => {
|
||||
if (!selectedTenant) return;
|
||||
|
||||
// Capture the ID securely
|
||||
const tenantId = selectedTenant.id;
|
||||
|
||||
setDeleteError("");
|
||||
setIsDeleting(true);
|
||||
|
||||
try {
|
||||
await tenantsApi.remove(selectedTenant.id);
|
||||
await tenantsApi.remove(tenantId);
|
||||
setTenants((prev) =>
|
||||
prev.filter((tenant) => tenant.id !== selectedTenant.id)
|
||||
prev.filter((tenant) => tenant.id !== tenantId)
|
||||
);
|
||||
setIsDeleteOpen(false);
|
||||
setSelectedTenant(null);
|
||||
} catch (error) {
|
||||
console.error("Delete failed:", error);
|
||||
const message =
|
||||
error instanceof Error ? error.message : "Unable to delete tenant.";
|
||||
setDeleteError(message);
|
||||
|
||||
Reference in New Issue
Block a user