0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

chore(console): add value for tenants api swr to reduce requests

This commit is contained in:
Darcy Ye 2023-06-20 16:07:19 +08:00
parent da6f9eef5c
commit 133c50a3a4
No known key found for this signature in database
GPG key ID: B46F4C07EDEFC610
2 changed files with 14 additions and 4 deletions

View file

@ -123,7 +123,7 @@ function TenantSelector() {
onClose={async (tenant?: TenantInfo) => {
if (tenant) {
toast.success(t('tenants.tenant_created', { name: tenant.name }));
void mutate();
void mutate([tenant, ...tenants]);
window.location.assign(new URL(`/${tenant.id}`, window.location.origin).toString());
}
setShowCreateTenantModal(false);

View file

@ -69,13 +69,23 @@ function TenantBasicSettings() {
const saveData = async (data: { name?: string; tag?: TenantTag }) => {
try {
const { name, tag } = await api.patch(`/api/tenants/:tenantId`, {
const updatedTenant = await api.patch(`/api/tenants/:tenantId`, {
params: { tenantId: currentTenantId },
body: data,
});
const { name, tag } = updatedTenant;
reset({ profile: { name, tag } });
void mutate();
toast.success(t('tenant_settings.profile.tenant_info_saved'));
const currentTenantIndex = tenants?.findIndex(({ id }) => id === currentTenantId);
if (currentTenantIndex !== undefined && currentTenantIndex !== -1) {
void mutate([
...(tenants?.slice(0, currentTenantIndex) ?? []),
updatedTenant,
...(tenants?.slice(currentTenantIndex + 1) ?? []),
]);
return;
}
void mutate([updatedTenant]);
} catch (error: unknown) {
setError(
error instanceof Error
@ -109,7 +119,7 @@ function TenantBasicSettings() {
try {
await api.delete(`/api/tenants/:tenantId`, { params: { tenantId: currentTenantId } });
setIsDeletionModalOpen(false);
void mutate();
void mutate((tenants ?? []).filter(({ id }) => id !== currentTenantId));
} catch (error: unknown) {
setError(
error instanceof Error